From 07ae3c57aef0c09769866afa07bf0482cc5fa7b0 Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Thu, 21 Sep 2023 17:40:10 -0400 Subject: [PATCH] update to use centralized relation type tests --- .../adapter/test_persist_test_results.py | 5 ++ .../test_persist_test_results.py | 20 ------- .../functional/persist_test_results/utils.py | 55 ------------------- 3 files changed, 5 insertions(+), 75 deletions(-) create mode 100644 tests/functional/adapter/test_persist_test_results.py delete mode 100644 tests/functional/persist_test_results/test_persist_test_results.py delete mode 100644 tests/functional/persist_test_results/utils.py diff --git a/tests/functional/adapter/test_persist_test_results.py b/tests/functional/adapter/test_persist_test_results.py new file mode 100644 index 000000000..75bfb5acc --- /dev/null +++ b/tests/functional/adapter/test_persist_test_results.py @@ -0,0 +1,5 @@ +from dbt.tests.adapter.persist_test_results.basic import PersistTestResults + + +class TestPersistTestResults(PersistTestResults): + pass diff --git a/tests/functional/persist_test_results/test_persist_test_results.py b/tests/functional/persist_test_results/test_persist_test_results.py deleted file mode 100644 index 82b9d5b1c..000000000 --- a/tests/functional/persist_test_results/test_persist_test_results.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import Dict, Set, Tuple - -from dbt.tests.adapter.persist_test_results.basic import PersistTestResults - -from tests.functional.persist_test_results.utils import ( - delete_record, - get_relation_summary_in_schema, - insert_record, -) - - -class TestPersistTestResults(PersistTestResults): - def get_audit_relation_summary(self, project) -> Set[Tuple]: - return get_relation_summary_in_schema(project, self.audit_schema) - - def insert_record(self, project, record: Dict[str, str]): - insert_record(project, project.test_schema, self.model_table, record) - - def delete_record(self, project, record: Dict[str, str]): - delete_record(project, project.test_schema, self.model_table, record) diff --git a/tests/functional/persist_test_results/utils.py b/tests/functional/persist_test_results/utils.py deleted file mode 100644 index cbacafc61..000000000 --- a/tests/functional/persist_test_results/utils.py +++ /dev/null @@ -1,55 +0,0 @@ -from typing import Dict, Set, Tuple - - -def get_relation_summary_in_schema(project, schema: str) -> Set[Tuple]: - """ - Returns a summary like this: - { - ("my_table", "table", 0), - ("my_view", "view", 1), - } - """ - sql = """ - We can't get the relation type in tests right now because it requires a multi-statement sql execution. - This needs to be solved prior to automating these tests. This will also resolve the same issue for DT tests. - """ - relation_types = project.run_sql(sql, fetch="all") - - results = set() - for relation_name, relation_type in relation_types: - row_count_sql = f"select count(*) from {schema}.{relation_name}" - row_count = project.run_sql(row_count_sql, fetch="one")[0] - summary = (relation_name, relation_type, row_count) - results.add(summary) - - return results - - -def insert_record(project, schema: str, table_name: str, record: Dict[str, str]): - # postgres only supports schema names of 63 characters - # a schema with a longer name still gets created, but the name gets truncated - schema_name = schema[:63] - field_names, field_values = [], [] - for field_name, field_value in record.items(): - field_names.append(field_name) - field_values.append(f"'{field_value}'") - field_name_clause = ", ".join(field_names) - field_value_clause = ", ".join(field_values) - - sql = f""" - insert into {schema_name}.{table_name} ({field_name_clause}) - values ({field_value_clause}) - """ - project.run_sql(sql) - - -def delete_record(project, schema: str, table_name: str, record: Dict[str, str]): - schema_name = schema[:63] - where_clause = " and ".join( - [f"{field_name} = '{field_value}'" for field_name, field_value in record.items()] - ) - sql = f""" - delete from {schema_name}.{table_name} - where {where_clause} - """ - project.run_sql(sql)