Skip to content

Commit

Permalink
Initial code to use dbt.tests.adapter in Redshift (dbt-labs#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Mar 29, 2022
1 parent bbe1ff5 commit 7e51634
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## dbt-redshift 1.1.0 (TBD)

### Under the hood
- Use dbt.tests.adapter.basic in test suite ([#78](https://github.com/dbt-labs/dbt-redshift/issues/78), [#81](https://github.com/dbt-labs/dbt-redshift/pull/81))

## dbt-redshift 1.1.0b1 (March 23, 2022)

### Fixes
Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# install latest changes in dbt-core + dbt-postgres
# TODO: how to switch from HEAD to x.y.latest branches after minor releases?
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter
git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-postgres&subdirectory=plugins/postgres

bumpversion
Expand All @@ -18,4 +19,4 @@ pytest-xdist
pytz
tox>=3.13
twine
wheel
wheel
10 changes: 10 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[pytest]
filterwarnings =
ignore:.*'soft_unicode' has been renamed to 'soft_str'*:DeprecationWarning
ignore:unclosed file .*:ResourceWarning
env_files =
test.env
testpaths =
tests/unit
tests/integration
tests/functional
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import os

# Import the fuctional fixtures as a plugin
# Note: fixtures with session scope need to be local

pytest_plugins = ["dbt.tests.fixtures.project"]

# The profile dictionary, used to write out profiles.yml
@pytest.fixture(scope="class")
def dbt_profile_target():
return {
'type': 'redshift',
'threads': 1,
'host': os.getenv('REDSHIFT_TEST_HOST'),
'port': int(os.getenv('REDSHIFT_TEST_PORT')),
'user': os.getenv('REDSHIFT_TEST_USER'),
'pass': os.getenv('REDSHIFT_TEST_PASS'),
'dbname': os.getenv('REDSHIFT_TEST_DBNAME'),
}


79 changes: 79 additions & 0 deletions tests/functional/adapter/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import pytest

from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import (
BaseSingularTestsEphemeral,
)
from dbt.tests.adapter.basic.test_empty import BaseEmpty
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
from dbt.tests.adapter.basic.test_incremental import BaseIncremental
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp

from dbt.tests.adapter.basic.files import seeds_base_csv, seeds_added_csv, seeds_newcolumns_csv

# set the datatype of the name column in the 'added' seed so it
# can hold the '_update' that's added
schema_seed_added_yml = """
version: 2
seeds:
- name: added
config:
column_types:
name: varchar(64)
"""


class TestSimpleMaterializationsRedshift(BaseSimpleMaterializations):
pass


class TestSingularTestsRedshift(BaseSingularTests):
pass


class TestSingularTestsEphemeralRedshift(BaseSingularTestsEphemeral):
pass


class TestEmptyRedshift(BaseEmpty):
pass


class TestEphemeralRedshift(BaseEphemeral):
pass


class TestIncrementalRedshift(BaseIncremental):
pass


class TestGenericTestsRedshift(BaseGenericTests):
pass


class TestSnapshotCheckColsRedshift(BaseSnapshotCheckCols):
# Redshift defines the 'name' column such that it's not big enough
# to hold the '_update' added in the test.
@pytest.fixture(scope="class")
def models(self):
return {
"base.csv": seeds_base_csv,
"added.csv": seeds_added_csv,
"seeds.yml": schema_seed_added_yml,
}


class TestSnapshotTimestampRedshift(BaseSnapshotTimestamp):
# Redshift defines the 'name' column such that it's not big enough
# to hold the '_update' added in the test.
@pytest.fixture(scope="class")
def models(self):
return {
"base.csv": seeds_base_csv,
"added.csv": seeds_added_csv,
"newcolumns.csv": seeds_newcolumns_csv,
"seeds.yml": schema_seed_added_yml,
}
8 changes: 1 addition & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ skip_install = true
passenv = DBT_* REDSHIFT_TEST_* PYTEST_ADDOPTS
commands =
redshift: {envpython} -m pytest {posargs} -m profile_redshift tests/integration
redshift: {envpython} -m pytest {posargs} tests/functional
deps =
-rdev_requirements.txt
-e.

[pytest]
env_files =
test.env
testpaths =
tests/unit
tests/integration

0 comments on commit 7e51634

Please sign in to comment.