-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from godatadriven/add-first-test
Adding first test to dbt-bouncer
- Loading branch information
Showing
10 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Dict, List | ||
|
||
import pytest | ||
|
||
|
||
class FixturePlugin(object): | ||
def __init__(self): | ||
self.models_ = None | ||
self.sources_ = None | ||
self.tests_ = None | ||
|
||
@pytest.fixture(scope="session") | ||
def models(self): | ||
return self.models_ | ||
|
||
@pytest.fixture(scope="session") | ||
def sources(self): | ||
return self.sources_ | ||
|
||
@pytest.fixture(scope="session") | ||
def tests(self): | ||
return self.tests_ | ||
|
||
|
||
def runner( | ||
models: List[Dict[str, str]], | ||
sources: List[Dict[str, str]], | ||
tests: List[Dict[str, str]], | ||
) -> None: | ||
""" | ||
Run pytest using fixtures from artifacts. | ||
""" | ||
|
||
# Create a fixture plugin that can be used to inject the manifest into the tests | ||
fixtures = FixturePlugin() | ||
for att in ["models", "sources", "tests"]: | ||
setattr(fixtures, att + "_", locals()[att]) | ||
|
||
# Run the tests, if one fails then pytest will raise an exception | ||
pytest.main(["dbt_bouncer/tests"], plugins=[fixtures]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def populated_model_description(models): | ||
""" | ||
Models must have a populated description. | ||
""" | ||
|
||
for model in models: | ||
assert ( | ||
len(model["description"].strip()) > 4 | ||
), f"{model['unique_id']} does not have a populated description." | ||
|
||
|
||
def test_populated_model_description(models): | ||
populated_model_description(models=models) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
select 1 as id |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from contextlib import nullcontext as does_not_raise | ||
|
||
import pytest | ||
|
||
from dbt_bouncer.tests.test_models import populated_model_description | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"models,expectation", | ||
[ | ||
( | ||
[ | ||
{ | ||
"description": "Description that is more than 4 characters.", | ||
"unique_id": "model.package_name.model_1", | ||
} | ||
], | ||
does_not_raise(), | ||
), | ||
( | ||
[ | ||
{ | ||
"description": """A | ||
multiline | ||
description | ||
""", | ||
"unique_id": "model.package_name.model_2", | ||
} | ||
], | ||
does_not_raise(), | ||
), | ||
( | ||
[ | ||
{ | ||
"description": "", | ||
"unique_id": "model.package_name.model_3", | ||
} | ||
], | ||
pytest.raises(AssertionError), | ||
), | ||
( | ||
[ | ||
{ | ||
"description": " ", | ||
"unique_id": "model.package_name.model_4", | ||
} | ||
], | ||
pytest.raises(AssertionError), | ||
), | ||
( | ||
[ | ||
{ | ||
"description": """ | ||
""", | ||
"unique_id": "model.package_name.model_5", | ||
} | ||
], | ||
pytest.raises(AssertionError), | ||
), | ||
( | ||
[ | ||
{ | ||
"description": "-", | ||
"unique_id": "model.package_name.model_6", | ||
} | ||
], | ||
pytest.raises(AssertionError), | ||
), | ||
( | ||
[ | ||
{ | ||
"description": "null", | ||
"unique_id": "model.package_name.model_7", | ||
} | ||
], | ||
pytest.raises(AssertionError), | ||
), | ||
], | ||
) | ||
def test_populated_model_description(models, expectation): | ||
with expectation: | ||
populated_model_description(models=models) |