From 55611b17c70ca20406585fa9ab6bb0d356033278 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Fri, 12 Jan 2024 12:37:09 -0600 Subject: [PATCH] Add seed to test of external node unit test, and indirectly have the 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. --- .../functional/unit_testing/test_unit_testing.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/functional/unit_testing/test_unit_testing.py b/tests/functional/unit_testing/test_unit_testing.py index fac13477229..3af63fa0eca 100644 --- a/tests/functional/unit_testing/test_unit_testing.py +++ b/tests/functional/unit_testing/test_unit_testing.py @@ -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 { @@ -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