Skip to content

Commit

Permalink
Update validate sql test classes to new nomenclature (#8076)
Browse files Browse the repository at this point in the history
The original implementation of validate_sql was called dry_run,
but in the rename the test classes and much of their associated
documentation still retained the old naming.

This is mainly cosmetic, but since these test classes will be
imported into adapter repositories we should fix this now before
the wrong name proliferates.
  • Loading branch information
tlento authored Jul 12, 2023
1 parent 4ffd633 commit b78d23f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230711-234737.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Update DryRunMethod test classes ValidateSqlMethod naming
time: 2023-07-11T23:47:37.9525-04:00
custom:
Author: tlento
Issue: "7839"
20 changes: 10 additions & 10 deletions tests/adapter/dbt/tests/adapter/utils/test_validate_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
from dbt.exceptions import DbtRuntimeError, InvalidConnectionError


class BaseDryRunMethod:
"""Tests the behavior of the dry run method for the relevant adapters.
class BaseValidateSqlMethod:
"""Tests the behavior of the validate_sql method for the relevant adapters.
The valid and invalid SQL should work with most engines by default, but
both inputs can be overridden as needed for a given engine to get the correct
behavior.
The base method is meant to throw the appropriate custom exception when dry_run
The base method is meant to throw the appropriate custom exception when validate_sql
fails.
"""

@pytest.fixture(scope="class")
def valid_sql(self) -> str:
"""Returns a valid statement for issuing as a dry run query.
"""Returns a valid statement for issuing as a validate_sql query.
Ideally this would be checkable for non-execution. For example, we could use a
CREATE TABLE statement with an assertion that no table was created. However,
Expand All @@ -33,7 +33,7 @@ def valid_sql(self) -> str:

@pytest.fixture(scope="class")
def invalid_sql(self) -> str:
"""Returns an invalid statement for issuing a bad dry run query."""
"""Returns an invalid statement for issuing a bad validate_sql query."""

return "Let's run some invalid SQL and see if we get an error!"

Expand All @@ -45,18 +45,18 @@ def expected_exception(self) -> Type[Exception]:
base exception for adapters to throw."""
return DbtRuntimeError

def test_valid_dry_run(self, adapter: BaseAdapter, valid_sql: str) -> None:
"""Executes a dry run query on valid SQL. No news is good news."""
def test_validate_sql_success(self, adapter: BaseAdapter, valid_sql: str) -> None:
"""Executes validate_sql on valid SQL. No news is good news."""
with adapter.connection_named("test_valid_sql_validation"):
adapter.validate_sql(valid_sql)

def test_invalid_dry_run(
def test_validate_sql_failure(
self,
adapter: BaseAdapter,
invalid_sql: str,
expected_exception: Type[Exception],
) -> None:
"""Executes a dry run query on invalid SQL, expecting the exception."""
"""Executes validate_sql on invalid SQL, expecting the exception."""
with pytest.raises(expected_exception=expected_exception) as excinfo:
with adapter.connection_named("test_invalid_sql_validation"):
adapter.validate_sql(invalid_sql)
Expand All @@ -71,5 +71,5 @@ def test_invalid_dry_run(
) from excinfo.value


class TestDryRunMethod(BaseDryRunMethod):
class TestValidateSqlMethod(BaseValidateSqlMethod):
pass

0 comments on commit b78d23f

Please sign in to comment.