Skip to content

Commit

Permalink
[Test] Add unit test for dbt adapter support_tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Huang <[email protected]>
  • Loading branch information
kentwelcome committed Dec 11, 2024
1 parent 39683c1 commit c2fad5b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,4 +28,3 @@ install-frontend-requires:

dev: install-frontend-requires
@cd js && pnpm dev

40 changes: 40 additions & 0 deletions tests/adapter/dbt_adapter/test_dbt_adapter.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c2fad5b

Please sign in to comment.