"""Integration test for Projections flow.""" from boto.s3.connection import Bucket from boto.s3.connection import S3Connection from flows import datastore from flows.projections import config as flow_config from integration_tests.flows.projections import config as test_config from integration_tests.flows.projections import helpers from integration_tests.flows.projections import queries def test_flow_execution(): """Test Projections workflow execution.""" # preparing test data for test flow execution helpers.prepare_data() # execute test flow helpers.execute_flow() # check database state db_checks = [queries.assert_queries['logs_count'], queries.assert_queries['revenue_data']] for check in db_checks: value = datastore.execute(check['sql']).rowcount assert value == check['check_value'], check['error_message'] # check S3 state source_bucket = Bucket(S3Connection(), test_config.test_bucket_name) archive_bucket = Bucket(S3Connection(), test_config.test_bucket_name) assert source_bucket.get_key( test_config.source_file_data['s3_path']) is None, ( "File wasn't deleted from source path") assert archive_bucket.get_key( flow_config.S3_ARCHIVE_PATH.format( projections=flow_config.REGULAR_PROJECTION, filename=test_config.source_file_name)) is not None, ( "File wasn't copied to the archive path") helpers.clean_database() print('Integration test was successfully passed')