Skip to content

Commit

Permalink
Add seed to test of external node unit test, and indirectly have the …
Browse files Browse the repository at this point in the history
…external node point to it

Previously I was getting an error about the columns for the external model
not being fetchable from the database via the macro `get_columns_in_relation`.
By creating a seed for the tests, which creates a table in postgres, we can then
tell the external model that it's database schema and identifier (the relation)
is that table from the seed without make the seed an actual dependency of the
external model in the dag.
  • Loading branch information
QMalcolm committed Jan 16, 2024
1 parent 55b2606 commit 55611b1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/functional/unit_testing/test_unit_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,25 @@ def test_nonexistent_seed(self, project):
- {user_id: 4, is_valid_email_address: false}
"""

external_node_seed_csv = """user_id,email,emtail_top_level_domain
1,"example@example.com","example.com"
"""


class TestUnitTestExternalNode:
@pytest.fixture(scope="class")
def external_model_node(self):
def external_model_node(self, unique_schema):
return ModelNodeArgs(
name="external_model",
package_name="external_package",
identifier="test_identifier",
schema="test_schema",
identifier="external_node_seed",
schema=unique_schema,
)

@pytest.fixture(scope="class")
def seeds(self):
return {"external_node_seed.csv": external_node_seed_csv}

@pytest.fixture(scope="class")
def models(self):
return {
Expand All @@ -297,5 +305,6 @@ def test_unit_test_ext_nodes(
external_nodes.add_model(external_model_node)
get_plugin_manager.return_value.get_nodes.return_value = external_nodes

run_dbt(["seed"], expect_pass=True)
results = run_dbt(["test", "--select", "valid_emails"], expect_pass=True)
assert len(results) == 1

0 comments on commit 55611b1

Please sign in to comment.