Skip to content

Commit

Permalink
Test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ilias1111 committed Nov 28, 2024
1 parent 2df1887 commit b2989b1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
17 changes: 14 additions & 3 deletions integration_tests/.scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ for db in ${DATABASES[@]}; do

eval "dbt run --target $db --vars '{snowplow__enable_youtube: false, snowplow__enable_whatwg_media: false, snowplow__enable_whatwg_video: false, snowplow__enable_media_player_v1: false}'" || exit 1;



echo "Snowplow media player integration tests: Execute models - run 1/6"

eval "dbt run --target $db --full-refresh --vars '{snowplow__allow_refresh: true}'" || exit 1;
Expand All @@ -69,6 +67,19 @@ for db in ${DATABASES[@]}; do

eval "dbt test --target $db" || exit 1;

echo "Snowplow media player integration tests: Testing ad views passthrough - mixed configuration"
eval "dbt run --target $db --full-refresh --vars '{
snowplow__allow_refresh: true,
snowplow__enable_media_ad: true,
snowplow__backfill_limit_days: 999,
snowplow__ad_views_passthroughs: [
\"v_collector\",
{\"sql\": \"v_tracker || app_id\", \"alias\": \"tracker_app_id\", \"agg\": \"max\"}
]
}'" || exit 1;

eval "dbt test --target $db --select test_type:singular tag:ad_views_passthrough" || exit 1;

echo "Snowplow media player integration tests: All tests passed"

done
done
45 changes: 45 additions & 0 deletions integration_tests/tests/assert_media_ad_views_passthrough.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- tests/assert_media_ad_views_passthrough.sql
with base_data as (
select * from {{ ref('snowplow_media_player_base_events_this_run') }}
where media_ad__ad_id is not null
and media_identifier is not null
),

expected as (
select
{{ dbt_utils.generate_surrogate_key(['platform', 'media_identifier', 'media_ad__ad_id']) }} as media_ad_id,
-- simple passthrough
v_collector,
-- max aggregation
max(v_tracker || app_id) as tracker_app_id
from base_data
group by 1, 2
),

actual as (
select
media_ad_id,
v_collector,
tracker_app_id
from {{ ref('snowplow_media_player_media_ad_views_this_run') }}
),

comparison as (
select
coalesce(e.media_ad_id, a.media_ad_id) as media_ad_id,
case
when e.v_collector != a.v_collector then 1
when e.tracker_app_id != a.tracker_app_id then 1
when e.media_ad_id is null then 1
when a.media_ad_id is null then 1
else 0
end as has_mismatch
from expected e
full outer join actual a using (media_ad_id)
)

select
'Data mismatch found' as test_name,
sum(has_mismatch) as failures
from comparison
having sum(has_mismatch) > 0
20 changes: 20 additions & 0 deletions integration_tests/tests/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

models:
- name: snowplow_media_player_media_ad_views_this_run
tests:
- assert_media_ad_views_passthrough
columns:
- name: media_ad_id
tests:
- not_null
- unique
- name: v_collector
tests:
- not_null
- name: tracker_app_id
tests:
- not_null

config:
tags: ['this_run']
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ select
{%- for col in passthrough_names %}
, p.{{col}}
{%- endfor -%}
{%- for agg_col in agg_columns %}
, p.{{agg_col['alias']}}
{%- endfor -%}

{%- endif %}

from prep as p

0 comments on commit b2989b1

Please sign in to comment.