From c2fad5b46d150f34100bc4c98a66ef9b2174aad9 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Wed, 11 Dec 2024 18:31:54 +0800 Subject: [PATCH] [Test] Add unit test for dbt adapter support_tasks Signed-off-by: Kent Huang --- Makefile | 5 +-- tests/adapter/dbt_adapter/test_dbt_adapter.py | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests/adapter/dbt_adapter/test_dbt_adapter.py diff --git a/Makefile b/Makefile index 07facd39..f8525cf9 100644 --- a/Makefile +++ b/Makefile @@ -16,10 +16,10 @@ flake8: @echo "Passed" test: install-dev - @python3 -m pytest tests + @python3 -m pytest --cov=recce --cov-report html tests test-tox: install-dev - @tox + @tox install-frontend-requires: # Install pnpm if not installed @@ -28,4 +28,3 @@ install-frontend-requires: dev: install-frontend-requires @cd js && pnpm dev - \ No newline at end of file diff --git a/tests/adapter/dbt_adapter/test_dbt_adapter.py b/tests/adapter/dbt_adapter/test_dbt_adapter.py new file mode 100644 index 00000000..3481d0d4 --- /dev/null +++ b/tests/adapter/dbt_adapter/test_dbt_adapter.py @@ -0,0 +1,40 @@ +from recce.adapter.dbt_adapter import DbtAdapter, dbt_supported_registry +from recce.models import RunType + + +def test_dbt_adapter_support_tasks(dbt_test_helper): + adapter: DbtAdapter = dbt_test_helper.context.adapter + + # Test dbt package name + supported_dbt_packages = set([package.package_name for package in adapter.manifest.macros.values()]) + assert 'audit_helper' in supported_dbt_packages + assert 'dbt_profiler' in supported_dbt_packages + + # Test dbt task support + support_tasks = adapter.support_tasks() + + for task_type in dbt_supported_registry: + task = task_type.value + assert task in support_tasks + assert support_tasks[task] is True + + +def test_dbt_adapter_support_tasks_without_required_dbt_package(dbt_test_helper): + adapter: DbtAdapter = dbt_test_helper.context.adapter + # Mock the macros in manifest to simulate no required dbt package installed + adapter.manifest.macros = {} + + support_tasks = adapter.support_tasks() + + for task_type in dbt_supported_registry: + task = task_type.value + assert task in support_tasks + if task == RunType.PROFILE_DIFF.value: + assert support_tasks[task] is False + elif task == RunType.VALUE_DIFF.value: + assert support_tasks[task] is False + elif task == RunType.VALUE_DIFF_DETAIL.value: + assert support_tasks[task] is False + + # Check the query_diff_with_primary_key is not supported + assert support_tasks["query_diff_with_primary_key"] is False