-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rule to check if there is designated owner for physical models
* add rule to enforce the assignment of owner on physical models #6 * modify all manifest input to properly assign source node definitions in the expected place in manifest.json physical models are: - sources - views - tables - incrementals
- Loading branch information
Showing
7 changed files
with
199 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Models should all be enabled. | ||
Copyright (C) 2020, Auto Trader UK | ||
Created 15. Dec 2020 15:51 | ||
""" | ||
from typing import List, Tuple, Optional | ||
|
||
from olivertwist.manifest import Manifest, Node | ||
from olivertwist.ruleengine.rule import rule | ||
from olivertwist.rules.utils import partition | ||
|
||
|
||
@rule(id="no-owner-on-physical-models", name="No owner on physical models") | ||
def no_owner_on_physical_models(manifest: Manifest) -> Tuple[List[Node], List[Node]]: | ||
passes, failures = partition( | ||
lambda x: x.is_db_relation and __is_none_or_blank(x.owner), | ||
manifest.nodes() | ||
) | ||
return list(passes), list(failures) | ||
|
||
|
||
def __is_none_or_blank(owner: Optional[str]): | ||
return owner is None or owner.strip(" ") == "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import pytest | ||
|
||
from olivertwist.manifest import Manifest | ||
from olivertwist.rules.no_owner_on_physical_models import no_owner_on_physical_models | ||
|
||
|
||
@pytest.fixture | ||
def manifest() -> Manifest: | ||
return Manifest( | ||
{ | ||
"nodes": { | ||
"physical_node_1": { | ||
"unique_id": "physical_node_1", | ||
"resource_type": "model", | ||
"config": {"materialized": "view"}, | ||
"meta": {"owner": "Joe"} | ||
}, | ||
"physical_node_2": { | ||
"unique_id": "physical_node_2", | ||
"resource_type": "model", | ||
"config": {"materialized": "table"}, | ||
"meta": {"owner": "Joe"} | ||
}, | ||
"physical_node_3": { | ||
"unique_id": "physical_node_3", | ||
"resource_type": "model", | ||
"config": {"materialized": "incremental"}, | ||
"meta": {"owner": "Joe"} | ||
}, | ||
"ephemeral_node_1": { | ||
"unique_id": "ephemeral_node_1", | ||
"resource_type": "model", | ||
"config": {"materialized": "ephemeral"}, | ||
"meta": {"owner": "Joe"} | ||
}, | ||
"ephemeral_node_2": { | ||
"unique_id": "ephemeral_node_2", | ||
"resource_type": "model", | ||
"config": {"materialized": "ephemeral"}, | ||
"meta": {} | ||
}, | ||
"no_owner_physical_node_1": { | ||
"unique_id": "no_owner_physical_node_1", | ||
"resource_type": "model", | ||
"config": {"materialized": "incremental"}, | ||
"meta": {} | ||
}, | ||
"no_owner_physical_node_2": { | ||
"unique_id": "no_owner_physical_node_2", | ||
"resource_type": "model", | ||
"config": {"materialized": "incremental"}, | ||
"meta": {"owner": ""} | ||
}, | ||
"no_owner_physical_node_3": { | ||
"unique_id": "no_owner_physical_node_3", | ||
"resource_type": "model", | ||
"config": {"materialized": "incremental"}, | ||
"meta": {"owner": " "} | ||
}, | ||
}, | ||
"child_map": { | ||
"physical_node_1": [], | ||
"physical_node_2": [], | ||
"physical_node_3": [], | ||
"ephemeral_node_1": [], | ||
"ephemeral_node_2": [], | ||
"no_owner_physical_node_1": [], | ||
"no_owner_physical_node_2": [], | ||
"no_owner_physical_node_3": [], | ||
"source_1": [], | ||
"no_owner_source_1": [], | ||
"no_owner_source_2": [], | ||
"no_owner_source_3": [], | ||
}, | ||
"disabled": [], | ||
"sources": { | ||
"source_1": { | ||
"unique_id": "source_1", | ||
"resource_type": "source", | ||
"meta": {"owner": "Joe"} | ||
}, | ||
"no_owner_source_1": { | ||
"unique_id": "no_owner_source_1", | ||
"resource_type": "source", | ||
"meta": {"owner": " "} | ||
}, | ||
"no_owner_source_2": { | ||
"unique_id": "no_owner_source_2", | ||
"resource_type": "source", | ||
"meta": {"owner": ""} | ||
}, | ||
"no_owner_source_3": { | ||
"unique_id": "no_owner_source_3", | ||
"resource_type": "source", | ||
"meta": {} | ||
}, | ||
|
||
}, | ||
|
||
} | ||
) | ||
|
||
|
||
def test_no_owner_on_physical_models(manifest): | ||
passes, failures = no_owner_on_physical_models(manifest) | ||
|
||
pass_ids = [p.id for p in passes] | ||
failure_ids = [f.id for f in failures] | ||
|
||
assert pass_ids == [ | ||
"physical_node_1", | ||
"physical_node_2", | ||
"physical_node_3", | ||
"ephemeral_node_1", | ||
"ephemeral_node_2", | ||
"source_1" | ||
] | ||
assert failure_ids == [ | ||
"no_owner_physical_node_1", | ||
"no_owner_physical_node_2", | ||
"no_owner_physical_node_3", | ||
"no_owner_source_1", | ||
"no_owner_source_2", | ||
"no_owner_source_3", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters