Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Raise a DbtMeshifyError if a project path is provided that does not contain a dbt_project.yml file #163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions dbt_meshify/dbt_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
ModelNode,
ParsedNode,
Resource,
SnapshotNode,
SourceDefinition,
)
from dbt.contracts.project import Project
Expand All @@ -26,6 +25,7 @@
from loguru import logger

from dbt_meshify.dbt import Dbt
from dbt_meshify.exceptions import FatalMeshifyException


class BaseDbtProject:
Expand Down Expand Up @@ -257,7 +257,15 @@ class DbtProject(BaseDbtProject, PathedProject):
@staticmethod
def _load_project(path) -> Project:
"""Load a dbt Project configuration"""
project_dict = yaml.load(open(os.path.join(path, "dbt_project.yml")), Loader=yaml.Loader)
try:
project_dict = yaml.load(
open(os.path.join(path, "dbt_project.yml")), Loader=yaml.Loader
)
except FileNotFoundError:
raise FatalMeshifyException(
f"The provided directory ({path}) does not contain a dbt project."
)

return Project.from_dict(project_dict)

@classmethod
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_connect_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,19 @@ def test_connect_source_hack_existing_dependency(self, producer_project):

# assert that the dependencies.yml was created with a pointer to the upstream project
assert "src_proj_a" in dependency_path.read_text()

def test_connect_raises_exception_invalid_paths(self, producer_project):
"""Verify that proving an invalid project path raises the correct error."""
runner = CliRunner()
result = runner.invoke(
cli,
[
"connect",
"--project-paths",
"totally_bogus_path",
copy_source_consumer_project_path,
],
)

assert result.exit_code != 0
assert "does not contain a dbt project" in result.stdout
19 changes: 19 additions & 0 deletions tests/integration/test_contract_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,22 @@ def test_add_contract_read_catalog(start_yml, end_yml, read_catalog, caplog, pro
assert "Generating catalog with dbt docs generate..." in caplog.text

assert actual == yaml.safe_load(end_yml)


def test_command_raises_exception_invalid_paths():
"""Verify that proving an invalid project path raises the correct error."""
runner = CliRunner()
result = runner.invoke(
cli,
[
"operation",
"add-contract",
"--select",
"shared_model",
"--project-path",
"tests",
],
)

assert result.exit_code != 0
assert "does not contain a dbt project" in result.stdout
23 changes: 23 additions & 0 deletions tests/integration/test_create_group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,26 @@ def test_group_owner_properties(name, email, end_group_yml, project):
del end_group_content["groups"][0]["owner"]["email"]

assert actual == end_group_content


def test_command_raises_exception_invalid_paths():
"""Verify that proving an invalid project path raises the correct error."""
runner = CliRunner()
result = runner.invoke(
cli,
[
"operation",
"create-group",
"test_group",
"--owner-name",
"Johnny Spells",
"--select",
"shared_model",
"other_model",
"--project-path",
"tests",
],
)

assert result.exit_code != 0
assert "does not contain a dbt project" in result.stdout
21 changes: 21 additions & 0 deletions tests/integration/test_group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,24 @@ def test_group_command(select, expected_public_contracted_models):
]
assert public_contracted_models == expected_public_contracted_models
teardown_test_project(dest_path_string)


def test_command_raises_exception_invalid_paths():
"""Verify that proving an invalid project path raises the correct error."""
runner = CliRunner()
result = runner.invoke(
cli,
[
"group",
"test_group",
"--owner-name",
"Teenage Mutant Jinja Turtles",
"--select",
"foo",
"--project-path",
"tests",
],
)

assert result.exit_code != 0
assert "does not contain a dbt project" in result.stdout
19 changes: 19 additions & 0 deletions tests/integration/test_split_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,22 @@ def test_split_downstream_multiple_boundary_parents(self):
assert x_proj_ref_5 in child_sql

teardown_test_project(dest_project_path)


def test_command_raises_exception_invalid_paths():
"""Verify that proving an invalid project path raises the correct error."""
runner = CliRunner()
result = runner.invoke(
cli,
[
"split",
"my_new_project",
"--project-path",
"tests",
"--select",
"orders+",
],
)

assert result.exit_code != 0
assert "does not contain a dbt project" in result.stdout
20 changes: 19 additions & 1 deletion tests/integration/test_version_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,22 @@ def test_add_version_to_invalid_yml(start_yml, start_files, project):
]
result = runner.invoke(cli, base_command, catch_exceptions=True)
assert result.exit_code == 1
# reset the read path to the default in the logic


def test_command_raises_exception_invalid_paths():
"""Verify that proving an invalid project path raises the correct error."""
runner = CliRunner()
result = runner.invoke(
cli,
[
"operation",
"add-version",
"--select",
"shared_model",
"--project-path",
"tests",
],
)

assert result.exit_code != 0
assert "does not contain a dbt project" in result.stdout