From 86d0764a885a6072a2d58724523c69e11b28413f Mon Sep 17 00:00:00 2001 From: Grace Goheen Date: Mon, 26 Jun 2023 12:34:02 -0700 Subject: [PATCH 1/3] add new unit test for yaml tests --- tests/fixtures.py | 26 ++++++++++++++++++++++++++ tests/unit/test_add_contract_to_yml.py | 10 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/tests/fixtures.py b/tests/fixtures.py index 887ca6d..ff48cbb 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -63,6 +63,17 @@ description: "this is the id column" """ +model_yml_one_col_one_test = """ +models: + - name: shared_model + description: "this is a test model" + columns: + - name: id + description: "this is the id column" + tests: + - unique +""" + model_yml_all_col = """ models: - name: shared_model @@ -102,6 +113,21 @@ data_type: varchar """ +expected_contract_yml_one_col_one_test = """ +models: + - name: shared_model + config: + contract: + enforced: true + description: "this is a test model" + columns: + - name: id + description: "this is the id column" + data_type: integer + tests: + - unique +""" + expected_contract_yml_all_col = """ models: - name: shared_model diff --git a/tests/unit/test_add_contract_to_yml.py b/tests/unit/test_add_contract_to_yml.py index 0a9efe5..ca2d13e 100644 --- a/tests/unit/test_add_contract_to_yml.py +++ b/tests/unit/test_add_contract_to_yml.py @@ -6,10 +6,12 @@ expected_contract_yml_no_entry, expected_contract_yml_one_col, expected_contract_yml_other_model, + expected_contract_yml_one_col_one_test, model_yml_all_col, model_yml_no_col_no_version, model_yml_one_col, model_yml_other_model, + model_yml_one_col_one_test, shared_model_catalog_entry, ) from . import read_yml @@ -36,6 +38,14 @@ def test_add_contract_to_yml_one_col(self): ) assert yml_dict == read_yml(expected_contract_yml_one_col) + def test_add_contract_to_yml_one_col_one_test(self): + yml_dict = meshify.add_model_contract_to_yml( + models_yml=read_yml(model_yml_one_col_one_test), + model_catalog=catalog_entry, + model_name=model_name, + ) + assert yml_dict == read_yml(expected_contract_yml_one_col_one_test) + def test_add_contract_to_yml_all_col(self): yml_dict = meshify.add_model_contract_to_yml( models_yml=read_yml(model_yml_all_col), From 3372b49105429f060ce15572f06663a053ec6af6 Mon Sep 17 00:00:00 2001 From: Grace Goheen Date: Mon, 26 Jun 2023 12:48:03 -0700 Subject: [PATCH 2/3] fixed unit test --- tests/fixtures.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/fixtures.py b/tests/fixtures.py index ff48cbb..dd4122d 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -126,6 +126,8 @@ data_type: integer tests: - unique + - name: colleague + data_type: varchar """ expected_contract_yml_all_col = """ From aa2bd19fda034cf48a54efdfe49d2c44358ef930 Mon Sep 17 00:00:00 2001 From: Grace Goheen Date: Mon, 26 Jun 2023 13:05:36 -0700 Subject: [PATCH 3/3] fixed case issue --- dbt_meshify/storage/yaml_editors.py | 4 ++-- tests/fixtures.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dbt_meshify/storage/yaml_editors.py b/dbt_meshify/storage/yaml_editors.py index bf3b32f..bedb7f5 100644 --- a/dbt_meshify/storage/yaml_editors.py +++ b/dbt_meshify/storage/yaml_editors.py @@ -98,9 +98,9 @@ def add_model_contract_to_yml( # isolate the columns from the existing model entry yml_cols: List[Dict] = model_yml.get("columns", []) catalog_cols = model_catalog.columns or {} if model_catalog else {} + catalog_cols = {k.lower(): v for k, v in catalog_cols.items()} - # add the data type to the yml entry for columns that are in yml - # import pdb; pdb.set_trace() + # add the data type to the yml entry for columns that are in yml yml_cols = [ {**yml_col, "data_type": catalog_cols[yml_col["name"]].type.lower()} for yml_col in yml_cols diff --git a/tests/fixtures.py b/tests/fixtures.py index dd4122d..f90d9f4 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -25,7 +25,7 @@ "owner": None, }, "columns": { - "id": {"type": "INTEGER", "index": 1, "name": "id", "comment": None}, + "ID": {"type": "INTEGER", "index": 1, "name": "id", "comment": None}, "colleague": {"type": "VARCHAR", "index": 2, "name": "colleague", "comment": None}, }, "stats": {