"""Integration test for YouTube Weekly workflow.""" from garcon_contrib.dynamo_feed_status import garcon_feed_status from integration_tests.python_integration_tests import helpers as test_helpers from integration_tests.python_integration_tests import workflow_runner from integration_tests.python_integration_tests.youtube_weekly import config def test_reset_flow_status_in_the_dynamodb(): """Delete feed status to prevent the shortcut. We're deleting the status from the dev DynamoDB table, so it's safe. """ garcon_feed_status.delete_status(config.feed_name, '2016-10-17') def test_truncate_tables(): """Truncate destination tables in the integration_tests db schema.""" test_helpers.truncate_tables(config.tables.values()) def test_put_sample_files_on_s3(): """Put sample files on S3.""" test_helpers.put_sample_files_on_s3( config.feed_name, config.s3_paths['downloads_bucket']) def test_put_seed_tables(): """Put seed files on S3.""" test_helpers.seed_snowflake_tables( config.feed_name, config.s3_paths['seed_bucket']) def test_run_youtube_weekly_workflow(): """Run the youtube_weekly workflow on the sample data.""" execution_status = workflow_runner.run_workflow( config.workflow_type, config.workflow_category) # Assert if flow was completed without errors assert execution_status == 'COMPLETED' def test_check_status_in_dynamodb(): """Check feed status after the successful workflow execution.""" assert garcon_feed_status.get_overall_status( config.feed_name, '2016-10-17') == 'INGESTED' def test_staging_raw_table(): """Test if raw table was properly filled up. We assume that we have duplicate video_id-custom_id pairs in the mapping table (videos with the multiple audio tracks), so in the staging_raw_youtube we have more rows than in the source raw CSV files (30000 + 30000), but not much more. We can use magic number here because of frozen data set and frozen tables (dim_track, ioda_track_mapping, etc.) """ number_of_rows = test_helpers.get_number_of_rows_in_table( config.tables['staging_raw_table'], download_date='2018-11-07') assert number_of_rows == 7 def test_fact_analytics_table(): """Test if fact_analytics table was properly filled up.""" number_of_rows = test_helpers.get_number_of_rows_in_table( config.tables['fact_analytics'], feedid=config.feedid, reportdate='2019-08-05') assert number_of_rows == 6 def test_fact_analytics_error_table(): """Test if fact_analytics_error table was properly filled up.""" number_of_rows = test_helpers.get_number_of_rows_in_table( config.tables['fact_analytics_error']) assert number_of_rows == 1 def test_s3_archive(): """Test if all the sample source files were archived on the S3.""" number_of_files_in_archive = test_helpers.get_number_of_files( config.s3_paths['archive_bucket']) assert number_of_files_in_archive == 4 def test_remove_test_files_from_s3(): """Delete sample files and directories from S3.""" for s3_path in config.s3_paths.values(): test_helpers.remove_test_files_from_s3( s3_path, config.expected_bucket_owner )