Skip to content

Commit

Permalink
Merge pull request #82 from dbt-labs/multi-option-support-for-select
Browse files Browse the repository at this point in the history
Multi option support for select
  • Loading branch information
dave-connors-3 authored Jun 27, 2023
2 parents 295f09a + 0ea333f commit b9e55f1
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
12 changes: 11 additions & 1 deletion dbt_meshify/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools

import click
from dbt.cli.options import MultiOption

# define common parameters
project_path = click.option(
Expand All @@ -13,6 +14,9 @@
exclude = click.option(
"--exclude",
"-e",
cls=MultiOption,
multiple=True,
type=tuple,
default=None,
help="The dbt selection syntax specifying the resources to exclude in the operation",
)
Expand All @@ -26,14 +30,20 @@
select = click.option(
"--select",
"-s",
cls=MultiOption,
multiple=True,
type=tuple,
default=None,
help="The dbt selection syntax specifying the resources to include in the operation",
)

selector = click.option(
"--selector",
cls=MultiOption,
multiple=True,
type=tuple,
default=None,
help="The name of the YML selector specifying the resources to include in the operation",
help="The name(s) of the YML selector specifying the resources to include in the operation",
)

owner_name = click.option(
Expand Down
71 changes: 70 additions & 1 deletion tests/integration/test_create_group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from click.testing import CliRunner

from dbt_meshify.main import create_group
from tests.unit.test_add_group_and_access_to_model_yml import model_yml_shared_model
from tests.unit.test_add_group_and_access_to_model_yml import (
expected_model_yml_multiple_models_multi_select,
model_yml_multiple_models,
model_yml_shared_model,
)
from tests.unit.test_add_group_to_yml import (
expected_group_yml_existing_groups,
expected_group_yml_no_group,
Expand Down Expand Up @@ -68,6 +72,71 @@ def test_create_group_command(model_yml, start_group_yml, end_group_yml):
assert actual == yaml.safe_load(end_group_yml)


@pytest.mark.parametrize(
"start_model_yml, end_model_yml, start_group_yml, end_group_yml",
[
(
model_yml_multiple_models,
expected_model_yml_multiple_models_multi_select,
group_yml_empty_file,
expected_group_yml_no_group,
),
],
ids=["1"],
)
def test_create_group_command_multi_select(
start_model_yml, end_model_yml, start_group_yml, end_group_yml
):
group_yml_file = proj_path / "models" / "_groups.yml"
model_yml_file = proj_path / "models" / "_models.yml"
other_model_file = proj_path / "models" / "other_model.sql"

group_yml_file.parent.mkdir(parents=True, exist_ok=True)
model_yml_file.parent.mkdir(parents=True, exist_ok=True)
other_model_file.parent.mkdir(parents=True, exist_ok=True)

start_yml_content = yaml.safe_load(start_model_yml)
with open(model_yml_file, "w") as f:
yaml.safe_dump(start_yml_content, f, sort_keys=False)

start_group_yml_content = yaml.safe_load(start_group_yml)
with open(group_yml_file, "w") as f:
yaml.safe_dump(start_group_yml_content, f, sort_keys=False)

with open(other_model_file, "w") as f:
f.write("select 1 as test")

runner = CliRunner()
result = runner.invoke(
create_group,
[
"test_group",
"--select",
"shared_model",
"other_model",
"--project-path",
proj_path_string,
"--owner-name",
"Shaina Fake",
"--owner-email",
"[email protected]",
],
)

with open(group_yml_file, "r") as f:
actual_group_yml = yaml.safe_load(f)
with open(model_yml_file, "r") as f:
actual_model_yml = yaml.safe_load(f)

group_yml_file.unlink()
model_yml_file.unlink()
other_model_file.unlink()

assert result.exit_code == 0
assert actual_group_yml == yaml.safe_load(end_group_yml)
assert actual_model_yml == yaml.safe_load(end_model_yml)


@pytest.mark.parametrize(
"name,email,end_group_yml",
[
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_add_group_and_access_to_model_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
- name: other_other_model
"""

expected_model_yml_multiple_models_multi_select = """
models:
- name: shared_model
access: public
group: test_group
- name: other_model
access: public
group: test_group
- name: other_other_model
"""


class TestAddGroupToModelYML:
@pytest.fixture
Expand Down

0 comments on commit b9e55f1

Please sign in to comment.