Skip to content

Commit

Permalink
create empty group when nothing selected
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-connors-3 committed Jun 28, 2023
1 parent 4195dda commit 8460d39
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
5 changes: 0 additions & 5 deletions dbt_meshify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ def create_group(
"""
from dbt_meshify.utilities.grouper import ResourceGrouper

if not (select or exclude or selector):
raise Exception(
"Groups must be a subset of the resources in your project. Please provide a select, exclude, or selector argument to filter the resources in the project."
)

path = Path(project_path).expanduser().resolve()
project = DbtProject.from_directory(path)

Expand Down
9 changes: 6 additions & 3 deletions dbt_meshify/utilities/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ def _generate_resource_group(
resource_type=NodeType.Group,
)

nodes = self.project.select_resources(
select=select, exclude=exclude, selector=selector, output_key="unique_id"
)
if not (select or exclude or selector):
nodes = set()
else:
nodes = self.project.select_resources(
select=select, exclude=exclude, selector=selector, output_key="unique_id"
)

# Check if any of the selected nodes are already in a group of a different name. If so, raise an exception.
nodes = set(filter(lambda x: not x.startswith("source"), nodes))
Expand Down
49 changes: 23 additions & 26 deletions tests/integration/test_create_group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@


@pytest.mark.parametrize(
"model_yml,start_group_yml,end_group_yml",
"model_yml,select,start_group_yml,end_group_yml",
[
(model_yml_shared_model, group_yml_empty_file, expected_group_yml_no_group),
(model_yml_shared_model, group_yml_existing_groups, expected_group_yml_existing_groups),
(model_yml_shared_model, group_yml_group_predefined, expected_group_yml_no_group),
(
model_yml_shared_model,
"shared_model",
group_yml_empty_file,
expected_group_yml_no_group,
),
(
model_yml_shared_model,
"shared_model",
group_yml_existing_groups,
expected_group_yml_existing_groups,
),
(
model_yml_shared_model,
"shared_model",
group_yml_group_predefined,
expected_group_yml_no_group,
),
(model_yml_shared_model, "", group_yml_empty_file, expected_group_yml_no_group),
],
ids=["1", "2", "3"],
ids=["1", "2", "3", "4"],
)
def test_create_group_command(model_yml, start_group_yml, end_group_yml):
def test_create_group_command(model_yml, select, start_group_yml, end_group_yml):
group_yml_file = proj_path / "models" / "_groups.yml"
model_yml_file = proj_path / "models" / "_models.yml"

Expand All @@ -48,7 +64,7 @@ def test_create_group_command(model_yml, start_group_yml, end_group_yml):
[
"test_group",
"--select",
"shared_model",
select,
"--project-path",
proj_path_string,
"--owner-name",
Expand All @@ -68,25 +84,6 @@ def test_create_group_command(model_yml, start_group_yml, end_group_yml):
assert actual == yaml.safe_load(end_group_yml)


def test_group_command_no_selection_syntax():
"""Test that the command fails if no selection syntax is provided"""
runner = CliRunner()
result = runner.invoke(
create_group,
[
"test_group",
"--project-path",
proj_path_string,
"--owner-name",
"Shaina Fake",
"--owner-email",
"[email protected]",
],
)

assert result.exit_code == 1


@pytest.mark.parametrize(
"name,email,end_group_yml",
[
Expand Down

0 comments on commit 8460d39

Please sign in to comment.