Skip to content

Commit

Permalink
Add test ensuring partial parsing handles metrics generated from meas…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
QMalcolm committed Aug 4, 2023
1 parent 0ae1416 commit 5e951dc
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion tests/functional/semantic_models/test_semantic_model_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
expr: user_id
- name: id
type: primary
metrics:
- name: simple_metric
label: Simple Metric
type: simple
type_params:
measure: sum_of_things
"""

schema_without_semantic_model_yml = """models:
Expand Down Expand Up @@ -120,7 +127,7 @@ def test_semantic_model_parsing(self, project):
)
assert len(semantic_model.measures) == 5
# manifest should have one metric (that was created from a measure)
assert len(manifest.metrics) == 1
assert len(manifest.metrics) == 2
metric = manifest.metrics["metric.test.txn_revenue"]
assert metric.name == "txn_revenue"

Expand Down Expand Up @@ -184,3 +191,43 @@ def test_semantic_model_deleted_partial_parsing(self, project):

# Finally, verify that the manifest reflects the deletion
assert "semantic_model.test.revenue" not in result.result.semantic_models

def test_semantic_model_flipping_create_metric_partial_parsing(self, project):
generated_metric = "metric.test.txn_revenue"
# First, use the default schema.yml to define our semantic model, and
# run the dbt parse command
write_file(schema_yml, project.project_root, "models", "schema.yml")
runner = dbtRunner()
result = runner.invoke(["parse"])
assert result.success

# Verify the metric created by `create_metric: true` exists
metric = result.result.metrics[generated_metric]
assert metric.name == "txn_revenue"

# --- Next, modify the default schema.yml to have no `create_metric: true` ---
no_create_metric_schema_yml = schema_yml.replace(
"create_metric: true", "create_metric: false"
)
write_file(no_create_metric_schema_yml, project.project_root, "models", "schema.yml")

# Now, run the dbt parse command again.
result = runner.invoke(["parse"])
assert result.success

# Verify the metric originally created by `create_metric: true` was removed
assert result.result.metrics.get(generated_metric) is None

# --- Now bring it back ---
create_metric_schema_yml = schema_yml.replace(
"create_metric: false", "create_metric: true"
)
write_file(create_metric_schema_yml, project.project_root, "models", "schema.yml")

# Now, run the dbt parse command again.
result = runner.invoke(["parse"])
assert result.success

# Verify the metric originally created by `create_metric: true` was removed
metric = result.result.metrics[generated_metric]
assert metric.name == "txn_revenue"

0 comments on commit 5e951dc

Please sign in to comment.