Skip to content

Commit

Permalink
Additional unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
peterallenwebb committed Oct 24, 2023
1 parent 53ae181 commit 1c3128f
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions tests/unit/test_postgres_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dataclasses

import agate
import decimal
import unittest
Expand Down Expand Up @@ -326,32 +328,43 @@ def test_set_zero_keepalive(self, psycopg2):
@mock.patch.object(PostgresAdapter, "execute_macro")
@mock.patch.object(PostgresAdapter, "_get_catalog_relations")
def test_get_catalog_various_schemas(self, mock_get_relations, mock_execute):
column_names = ["table_database", "table_schema", "table_name"]
rows = [
("dbt", "foo", "bar"),
("dbt", "FOO", "baz"),
("dbt", None, "bar"),
("dbt", "quux", "bar"),
("dbt", "skip", "bar"),
]
mock_execute.return_value = agate.Table(rows=rows, column_names=column_names)
self.catalog_test(mock_get_relations, mock_execute, False)

@mock.patch.object(PostgresAdapter, "execute_macro")
@mock.patch.object(PostgresAdapter, "_get_catalog_relations")
def test_get_filtered_catalog(self, mock_get_relations, mock_execute):
self.catalog_test(mock_get_relations, mock_execute, True)

mock_get_relations.return_value = [
def catalog_test(self, mock_get_relations, mock_execute, filtered=False):
column_names = ["table_database", "table_schema", "table_name"]
relations = [
BaseRelation(path=Path(database="dbt", schema="foo", identifier="bar")),
BaseRelation(path=Path(database="dbt", schema="FOO", identifier="baz")),
BaseRelation(path=Path(database="dbt", schema=None, identifier="bar")),
BaseRelation(path=Path(database="dbt", schema="quux", identifier="bar")),
BaseRelation(path=Path(database="dbt", schema="skip", identifier="bar")),
]
rows = list(map(lambda x: dataclasses.astuple(x.path), relations))
mock_execute.return_value = agate.Table(rows=rows, column_names=column_names)

mock_get_relations.return_value = relations

mock_manifest = mock.MagicMock()
mock_manifest.get_used_schemas.return_value = {("dbt", "foo"), ("dbt", "quux")}

catalog, exceptions = self.adapter.get_catalog(mock_manifest)
self.assertEqual(
set(map(tuple, catalog)),
{("dbt", "foo", "bar"), ("dbt", "FOO", "baz"), ("dbt", "quux", "bar")},
)
if filtered:
catalog, exceptions = self.adapter.get_filtered_catalog(
mock_manifest, set([relations[0], relations[3]])
)
else:
catalog, exceptions = self.adapter.get_catalog(mock_manifest)

tupled_catalog = set(map(tuple, catalog))
if filtered:
self.assertEqual(tupled_catalog, {rows[0], rows[3]})
else:
self.assertEqual(tupled_catalog, {rows[0], rows[1], rows[3]})

self.assertEqual(exceptions, [])


Expand Down

0 comments on commit 1c3128f

Please sign in to comment.