Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Sep 13, 2023
1 parent 8994626 commit 14cd913
Showing 1 changed file with 77 additions and 4 deletions.
81 changes: 77 additions & 4 deletions tests/functional/access/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@
group: analytics
- name: another_model
description: "yet another model"
- name: ref_my_model
description: "a model that refs my_model"
group: marts
- name: ref_my_model
description: "a model that refs my_model"
group: analytics
Expand All @@ -116,6 +113,26 @@
group: analytics
"""

v6_schema_yml = """
models:
- name: my_model
description: "my model"
config:
access: private
group: analytics
- name: another_model
description: "yet another model"
- name: ref_my_model
description: "a model that refs my_model"
config:
group: analytics
- name: people_model
description: "some people"
config:
access: public
group: analytics
"""

people_model_sql = """
select 1 as id, 'Drew' as first_name, 'Banin' as last_name, 'yellow' as favorite_color, true as loves_dbt, 5 as tenure, current_timestamp as created_at
union all
Expand Down Expand Up @@ -313,10 +330,23 @@ def test_access_attribute(self, project):
# Should succeed
manifest = run_dbt(["parse"])
assert len(manifest.nodes) == 5
manifest = get_manifest(project.project_root)
metric_id = "metric.test.number_of_people"
assert manifest.metrics[metric_id].group == "analytics"

# Use access and group in config
write_file(v5_schema_yml, project.project_root, "models", "schema.yml")
manifest = run_dbt(["parse"])
# ['model.test.another_model', 'model.test.my_model', 'model.test.ref_my_model', 'model.test.people_model', 'model.test.metricflow_time_spine']
assert len(manifest.nodes) == 5
assert manifest.nodes["model.test.my_model"].access == AccessType.Private
assert manifest.nodes["model.test.my_model"].group == "analytics"
assert manifest.nodes["model.test.ref_my_model"].access == AccessType.Protected
assert manifest.nodes["model.test.ref_my_model"].group == "analytics"
assert manifest.nodes["model.test.people_model"].access == AccessType.Public
assert manifest.nodes["model.test.people_model"].group == "analytics"
assert manifest.nodes["model.test.another_model"].access == AccessType.Protected
assert manifest.nodes["model.test.another_model"].group is None


class TestUnrestrictedPackageAccess:
@pytest.fixture(scope="class", autouse=True)
Expand Down Expand Up @@ -398,3 +428,46 @@ def test_restricted_private_ref(self, project):

with pytest.raises(DbtReferenceError):
run_dbt(["parse"])


dbt_project_yml = """
models:
test:
subdir_one:
+group: analytics
+access: private
subdir_two:
+group: marts
+access: public
"""


class TestAccessDbtProjectConfig:
@pytest.fixture(scope="class")
def models(self):
return {
"model_one.sql": my_model_sql,
"subdir_one": {
"model_two.sql": my_model_sql,
},
"subdir_two": {
"model_three.sql": my_model_sql,
},
}

@pytest.fixture(scope="class")
def project_config_update(self):
return dbt_project_yml

def test_dbt_project_access_config(self, project):
write_file(groups_yml, project.project_root, "models", "groups.yml")
manifest = run_dbt(["parse"])
model_one = manifest.nodes["model.test.model_one"]
model_two = manifest.nodes["model.test.model_two"]
model_three = manifest.nodes["model.test.model_three"]
assert model_one.group is None
assert model_one.access == AccessType.Protected
assert model_two.group == "analytics"
assert model_two.access == AccessType.Private
assert model_three.group == "marts"
assert model_three.access == AccessType.Public

0 comments on commit 14cd913

Please sign in to comment.