def test_facebook_age_gender_daily_report_actions__ok(pg_cursor): # Preparing DB ads_account_query = ''' INSERT INTO public.ads_account (account_id, account_name, master_account_id, account_currency, provider_name, parent_rep_owner_id, parent_rep_owner_name, updated_at, dsp, created_at) VALUES ('facebook_9038993320', NULL, '3562746171', 'USD', 'Gupta Media', NULL, 'Determine according to artist / campaign name', '2021-01-05 18:48:07.400000', 'facebook', '2021-02-08 17:45:20.596098'); ''' pg_cursor.execute(ads_account_query) pg_cursor.connection.commit() ads_campaign_query = ''' INSERT INTO public.ads_campaign (campaign_id, campaign_name, objective, account_id, start_date, end_date, updated_at, created_at, dsp) VALUES ('facebook_11621004435', 'CNCO - Tan Enamorados (Official Music Video) - TVD - RT - ES', 'Video Views', 'facebook_9038993320', '2020-11-13', '2020-12-03', '2021-01-11 18:10:39.176000', '2021-02-09 06:04:49.215593', 'facebook'); ''' pg_cursor.execute(ads_campaign_query) pg_cursor.connection.commit() ads_ad_set_query = ''' INSERT INTO public.ads_ad_set (ad_set_id, ad_set_name, campaign_id, account_id, updated_at, created_at, dsp) VALUES ('facebook_115670522280', 'TVD (Long-Term Views)', 'facebook_11621004435', 'facebook_9038993320', '2021-01-11 15:04:50.656000', '2021-02-09 09:43:05.649303', 'facebook'); ''' pg_cursor.execute(ads_ad_set_query) pg_cursor.connection.commit() insert_to_staging_query = ''' INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '25-34', 'unknown', null, null, null, '2020-11-16 14:54:31.532000', '2021-02-09 21:20:51.778000'); INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '55-64', 'unknown', null, null, null, '2020-11-16 18:59:54.703000', '2021-02-09 21:20:51.778000'); INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-08-22', null, '35-44', 'unknown', null, null, null, '2020-11-16 13:37:02.934000', '2021-02-09 21:20:51.778000'); ''' pg_cursor.execute(insert_to_staging_query) pg_cursor.connection.commit() uow_query = ''' INSERT INTO uow_meta.unit_of_work (uow_id, project, fact, dimensions, status, version, first_fact_id, last_fact_id, created_at, updated_at) VALUES (28620, 'decibel', '', '{ads_ad_set}', 'IMPORT_IN_PROGRESS', 'v1', 0, 0, '2021-01-11 12:23:53.000000', '2021-01-12 17:39:53.215338'); ''' pg_cursor.execute(uow_query) pg_cursor.connection.commit() # Before data transfer pg_cursor.execute('SELECT COUNT(*) FROM staging.facebook_age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (3,) pg_cursor.execute('SELECT COUNT(*) FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (0,) # Triggering data transfer pg_cursor.execute('UPDATE uow_meta.unit_of_work SET status = \'IMPORT_COMPLETED\' WHERE uow_id = 28620;') pg_cursor.connection.commit() # After data transfer pg_cursor.execute('SELECT COUNT(*) FROM staging.facebook_age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (3,) pg_cursor.execute('SELECT COUNT(*) FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (0,) def test_facebook_age_gender_daily_report_actions__ads_ad_set_missed(pg_cursor): # Preparing DB ads_account_query = ''' INSERT INTO public.ads_account (account_id, account_name, master_account_id, account_currency, provider_name, parent_rep_owner_id, parent_rep_owner_name, updated_at, dsp, created_at) VALUES ('facebook_9038993320', NULL, '3562746171', 'USD', 'Gupta Media', NULL, 'Determine according to artist / campaign name', '2021-01-05 18:48:07.400000', 'facebook', '2021-02-08 17:45:20.596098'); ''' pg_cursor.execute(ads_account_query) pg_cursor.connection.commit() ads_campaign_query = ''' INSERT INTO public.ads_campaign (campaign_id, campaign_name, objective, account_id, start_date, end_date, updated_at, created_at, dsp) VALUES ('facebook_11621004435', 'CNCO - Tan Enamorados (Official Music Video) - TVD - RT - ES', 'Video Views', 'facebook_9038993320', '2020-11-13', '2020-12-03', '2021-01-11 18:10:39.176000', '2021-02-09 06:04:49.215593', 'facebook'); ''' pg_cursor.execute(ads_campaign_query) pg_cursor.connection.commit() insert_to_staging_query = ''' INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '25-34', 'unknown', null, null, null, '2020-11-16 14:54:31.532000', '2021-02-09 21:20:51.778000'); INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '55-64', 'unknown', null, null, null, '2020-11-16 18:59:54.703000', '2021-02-09 21:20:51.778000'); INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-08-22', null, '35-44', 'unknown', null, null, null, '2020-11-16 13:37:02.934000', '2021-02-09 21:20:51.778000'); ''' pg_cursor.execute(insert_to_staging_query) pg_cursor.connection.commit() uow_query = ''' INSERT INTO uow_meta.unit_of_work (uow_id, project, fact, dimensions, status, version, first_fact_id, last_fact_id, created_at, updated_at) VALUES (28620, 'decibel', '', '{ads_ad_set}', 'IMPORT_IN_PROGRESS', 'v1', 0, 0, '2021-01-11 12:23:53.000000', '2021-01-12 17:39:53.215338'); ''' pg_cursor.execute(uow_query) pg_cursor.connection.commit() # Before data transfer pg_cursor.execute('SELECT COUNT(*) FROM staging.facebook_age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (3,) pg_cursor.execute('SELECT COUNT(*) FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (0,) # Triggering data transfer pg_cursor.execute('UPDATE uow_meta.unit_of_work SET status = \'IMPORT_COMPLETED\' WHERE uow_id = 28620;') pg_cursor.connection.commit() # After data transfer pg_cursor.execute('SELECT COUNT(*) FROM staging.facebook_age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (3,) pg_cursor.execute('SELECT COUNT(*) FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (0,) def test_facebook_age_gender_daily_report_actions__on_conflict_do_update(pg_cursor): # Preparing DB ads_account_query = ''' INSERT INTO public.ads_account (account_id, account_name, master_account_id, account_currency, provider_name, parent_rep_owner_id, parent_rep_owner_name, updated_at, dsp, created_at) VALUES ('facebook_9038993320', NULL, '3562746171', 'USD', 'Gupta Media', NULL, 'Determine according to artist / campaign name', '2021-01-05 18:48:07.400000', 'facebook', '2021-02-08 17:45:20.596098'); ''' pg_cursor.execute(ads_account_query) pg_cursor.connection.commit() ads_campaign_query = ''' INSERT INTO public.ads_campaign (campaign_id, campaign_name, objective, account_id, start_date, end_date, updated_at, created_at, dsp) VALUES ('facebook_11621004435', 'CNCO - Tan Enamorados (Official Music Video) - TVD - RT - ES', 'Video Views', 'facebook_9038993320', '2020-11-13', '2020-12-03', '2021-01-11 18:10:39.176000', '2021-02-09 06:04:49.215593', 'facebook'); ''' pg_cursor.execute(ads_campaign_query) pg_cursor.connection.commit() ads_ad_set_query = ''' INSERT INTO public.ads_ad_set (ad_set_id, ad_set_name, campaign_id, account_id, updated_at, created_at, dsp) VALUES ('facebook_115670522280', 'TVD (Long-Term Views)', 'facebook_11621004435', 'facebook_9038993320', '2021-01-11 15:04:50.656000', '2021-02-09 09:43:05.649303', 'facebook'); ''' pg_cursor.execute(ads_ad_set_query) pg_cursor.connection.commit() insert_to_staging_query = ''' INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', 123, '25-34', 'unknown', 'foo', null, 20.0, '2020-11-16 14:54:31.532000', '2021-02-09 21:20:51.778000'); ''' pg_cursor.execute(insert_to_staging_query) pg_cursor.connection.commit() insert_to_public_query = ''' INSERT INTO facebook.age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, updated_at, created_at) VALUES ('facebook_115670522280', '2020-10-16', 123, '25-34', 'unknown', 'foo', null, 10.0, '2021-02-09 21:20:51.778000', '2021-02-11 07:06:49.652836'); ''' pg_cursor.execute(insert_to_public_query) pg_cursor.connection.commit() uow_query = ''' INSERT INTO uow_meta.unit_of_work (uow_id, project, fact, dimensions, status, version, first_fact_id, last_fact_id, created_at, updated_at) VALUES (28620, 'decibel', '', '{ads_ad_set}', 'IMPORT_IN_PROGRESS', 'v1', 0, 0, '2021-01-11 12:23:53.000000', '2021-01-12 17:39:53.215338'); ''' pg_cursor.execute(uow_query) pg_cursor.connection.commit() # Before data transfer pg_cursor.execute('SELECT cost_per_action_type FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (10,) # Triggering data transfer pg_cursor.execute('UPDATE uow_meta.unit_of_work SET status = \'IMPORT_COMPLETED\' WHERE uow_id = 28620;') pg_cursor.connection.commit() # After data transfer pg_cursor.execute('SELECT cost_per_action_type FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (10,) def test_facebook_age_gender_daily_report_actions__duplicates(pg_cursor): # Preparing DB ads_account_query = ''' INSERT INTO public.ads_account (account_id, account_name, master_account_id, account_currency, provider_name, parent_rep_owner_id, parent_rep_owner_name, updated_at, dsp, created_at) VALUES ('facebook_9038993320', NULL, '3562746171', 'USD', 'Gupta Media', NULL, 'Determine according to artist / campaign name', '2021-01-05 18:48:07.400000', 'facebook', '2021-02-08 17:45:20.596098'); ''' pg_cursor.execute(ads_account_query) pg_cursor.connection.commit() ads_campaign_query = ''' INSERT INTO public.ads_campaign (campaign_id, campaign_name, objective, account_id, start_date, end_date, updated_at, created_at, dsp) VALUES ('facebook_11621004435', 'CNCO - Tan Enamorados (Official Music Video) - TVD - RT - ES', 'Video Views', 'facebook_9038993320', '2020-11-13', '2020-12-03', '2021-01-11 18:10:39.176000', '2021-02-09 06:04:49.215593', 'facebook'); ''' pg_cursor.execute(ads_campaign_query) pg_cursor.connection.commit() ads_ad_set_query = ''' INSERT INTO public.ads_ad_set (ad_set_id, ad_set_name, campaign_id, account_id, updated_at, created_at, dsp) VALUES ('facebook_115670522280', 'TVD (Long-Term Views)', 'facebook_11621004435', 'facebook_9038993320', '2021-01-11 15:04:50.656000', '2021-02-09 09:43:05.649303', 'facebook'); ''' pg_cursor.execute(ads_ad_set_query) pg_cursor.connection.commit() insert_to_staging_query = ''' INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '25-34', 'unknown', null, null, null, '2020-11-16 14:54:31.532000', '2021-02-09 21:20:51.778000'); INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '25-34', 'unknown', null, null, null, '2020-11-16 14:54:31.532000', '2021-02-09 21:20:51.778000'); INSERT INTO staging.facebook_age_gender_daily_report_actions (adset_id, date, index, age, gender, action_type, action_type_value, cost_per_action_type, _fivetran_synced, updated_at) VALUES (115670522280, '2020-10-16', null, '25-34', 'unknown', null, null, null, '2020-11-16 14:54:31.532000', '2021-02-09 21:20:51.778000'); ''' pg_cursor.execute(insert_to_staging_query) pg_cursor.connection.commit() uow_query = ''' INSERT INTO uow_meta.unit_of_work (uow_id, project, fact, dimensions, status, version, first_fact_id, last_fact_id, created_at, updated_at) VALUES (28620, 'decibel', '', '{ads_ad_set}', 'IMPORT_IN_PROGRESS', 'v1', 0, 0, '2021-01-11 12:23:53.000000', '2021-01-12 17:39:53.215338'); ''' pg_cursor.execute(uow_query) pg_cursor.connection.commit() # Before data transfer pg_cursor.execute('SELECT COUNT(*) FROM staging.facebook_age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (3,) pg_cursor.execute('SELECT COUNT(*) FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (0,) # Triggering data transfer pg_cursor.execute('UPDATE uow_meta.unit_of_work SET status = \'IMPORT_COMPLETED\' WHERE uow_id = 28620;') pg_cursor.connection.commit() # After data transfer pg_cursor.execute('SELECT COUNT(*) FROM staging.facebook_age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (3,) pg_cursor.execute('SELECT COUNT(*) FROM facebook.age_gender_daily_report_actions;') res = pg_cursor.fetchone() assert res == (0,)