forked from Velir/dbt-ga4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_stg_ga4__events.todo
43 lines (35 loc) · 1.94 KB
/
test_stg_ga4__events.todo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Test test currently fails because the event_key depends on the event_params nested field. Cannot mock that using CSV.
import pytest
from dbt.tests.util import read_file,check_relations_equal,run_dbt
# Define mocks via CSV (seeds) or SQL (models)
mock_base_ga4__events_csv = """user_id,event_name,event_timestamp,client_key,ga_session_id,stream_id,page_location,page_referrer,source,medium,campaign
user_id_1,pageview,12345,client_key_1,ga_session_id_1,stream_id_1,http://www.website.com/?foo=bar,http://www.cnn.com/,google,organic,(organic)
""".lstrip()
expected_csv = """user_id,event_name,event_timestamp,client_key,ga_session_id,stream_id,source,user_key,session_key,event_key,medium,campaign,original_page_location,original_page_referrer,page_location,page_referrer,page_hostname,page_query_string
user_id_1,pageview,12345,client_key_1,ga_session_id_1,stream_id_1,google,c/nWU/GWhlWiLU0S6R/rwg==,9fDgaCrbd4ieAj1QpcWDjw==,70B/o+ww2nOTa32ASF/ulw==,organic,(organic),http://www.website.com/?foo=bar,http://www.cnn.com/,http://www.website.com/?foo=bar,http://www.cnn.com/,website.com,foo=bar
"""
actual = read_file('../models/staging/stg_ga4__events.sql')
class TestStgEvents():
# everything that goes in the "seeds" directory (= CSV format)
@pytest.fixture(scope="class")
def seeds(self):
return {
"base_ga4__events.csv": mock_base_ga4__events_csv,
"expected.csv": expected_csv
}
# everything that goes in the "macros"
@pytest.fixture(scope="class")
def macros(self):
return {
"macros.sql": read_file('../macros/url_parsing.sql'),
}
# everything that goes in the "models" directory (= SQL)
@pytest.fixture(scope="class")
def models(self):
return {
"actual.sql": actual
}
def test_mock_run_and_check(self, project):
run_dbt(["build"])
breakpoint()
check_relations_equal(project.adapter, ["actual", "expected"])