Skip to content

Commit

Permalink
Remove dbt_valid_to_current test (will go in adapter zone) (#10854)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Oct 15, 2024
1 parent cd6bb9e commit 8f84716
Showing 1 changed file with 0 additions and 97 deletions.
97 changes: 0 additions & 97 deletions tests/functional/snapshots/test_snapshot_column_names.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import os

import pytest
Expand All @@ -8,7 +7,6 @@
get_manifest,
run_dbt,
run_dbt_and_capture,
run_sql_with_adapter,
update_config_file,
)

Expand Down Expand Up @@ -234,98 +232,3 @@ def test_snapshot_invalid_column_names(self, project):
assert len(results) == 1
assert "Compilation Error in snapshot snapshot_actual" in log_output
assert "Snapshot target is missing configured columns" in log_output


snapshots_valid_to_current_yml = """
snapshots:
- name: snapshot_actual
config:
strategy: timestamp
updated_at: updated_at
dbt_valid_to_current: "date('2099-12-31')"
snapshot_meta_column_names:
dbt_valid_to: test_valid_to
dbt_valid_from: test_valid_from
dbt_scd_id: test_scd_id
dbt_updated_at: test_updated_at
"""

update_with_current_sql = """
-- insert v2 of the 11 - 21 records
insert into {database}.{schema}.snapshot_expected (
id,
first_name,
last_name,
email,
gender,
ip_address,
updated_at,
test_valid_from,
test_valid_to,
test_updated_at,
test_scd_id
)
select
id,
first_name,
last_name,
email,
gender,
ip_address,
updated_at,
-- fields added by snapshotting
updated_at as test_valid_from,
date('2099-12-31') as test_valid_to,
updated_at as test_updated_at,
md5(id || '-' || first_name || '|' || updated_at::text) as test_scd_id
from {database}.{schema}.seed
where id >= 10 and id <= 20;
"""


class TestSnapshotDbtValidToCurrent:
@pytest.fixture(scope="class")
def snapshots(self):
return {"snapshot.sql": snapshot_actual_sql}

@pytest.fixture(scope="class")
def models(self):
return {
"snapshots.yml": snapshots_valid_to_current_yml,
"ref_snapshot.sql": ref_snapshot_sql,
}

def test_valid_to_current(self, project):
path = os.path.join(project.test_data_dir, "seed_dbt_valid_to.sql")
project.run_sql_file(path)
results = run_dbt(["snapshot"])
assert len(results) == 1

original_snapshot = run_sql_with_adapter(
project.adapter,
"select id, test_scd_id, test_valid_to from {database}.{schema}.snapshot_actual",
"all",
)
assert original_snapshot[0][2] == datetime.datetime(2099, 12, 31, 0, 0)
assert original_snapshot[9][2] == datetime.datetime(2099, 12, 31, 0, 0)

project.run_sql(invalidate_sql)
project.run_sql(update_with_current_sql)

results = run_dbt(["snapshot"])
assert len(results) == 1

updated_snapshot = run_sql_with_adapter(
project.adapter,
"select id, test_scd_id, test_valid_to from {database}.{schema}.snapshot_actual",
"all",
)
assert updated_snapshot[0][2] == datetime.datetime(2099, 12, 31, 0, 0)
# Original row that was updated now has a non-current (2099/12/31) date
assert updated_snapshot[9][2] == datetime.datetime(2016, 8, 20, 16, 44, 49)
# Updated row has a current date
assert updated_snapshot[20][2] == datetime.datetime(2099, 12, 31, 0, 0)

check_relations_equal(project.adapter, ["snapshot_actual", "snapshot_expected"])

0 comments on commit 8f84716

Please sign in to comment.