Skip to content

Commit

Permalink
feat(api): find_related_nodes_by_id returns input when type is not su…
Browse files Browse the repository at this point in the history
…pported (#104)
  • Loading branch information
datnguye committed Apr 5, 2024
1 parent b587c35 commit 2a51024
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions dbterd/adapters/algos/test_relationship.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import List, Tuple, Union

import click

from dbterd.adapters.algos import base
from dbterd.adapters.filter import is_selected_table
from dbterd.adapters.meta import Ref, Table
Expand Down Expand Up @@ -121,14 +119,15 @@ def find_related_nodes_by_id(
Returns:
List[str]: Manifest nodes' unique ID
"""
if type is not None:
raise click.BadParameter("Not supported manifest type")
found_nodes = [node_unique_id]
if type == "metadata":
return found_nodes # not supported yet, returned input only

rule = base.get_algo_rule(**kwargs)
test_nodes = base.get_test_nodes_by_rule_name(
manifest=manifest, rule_name=rule.get("name").lower()
)
found_nodes = [node_unique_id]

for test_node in test_nodes:
nodes = manifest.nodes[test_node].depends_on.nodes or []
if node_unique_id in nodes:
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/adapters/algos/test_test_relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,10 @@ def test_get_relationships_from_metadata_error(self, data, kwargs):
with pytest.raises(click.BadParameter):
base_algo.get_relationships_from_metadata(data=data, **kwargs)

def test_find_related_nodes_by_id_error(self):
with pytest.raises(click.BadParameter):
test_relationship.find_related_nodes_by_id(
manifest="irrelevant", type="metadata", node_unique_id="irrelevant"
)
def test_find_related_nodes_by_id_not_supported_type(self):
assert ["model.p.abc"] == test_relationship.find_related_nodes_by_id(
manifest="irrelevant", type="metadata", node_unique_id="model.p.abc"
)

def test_find_related_nodes_by_id(self):
assert sorted(["model.dbt_resto.table1", "model.dbt_resto.table2"]) == sorted(
Expand Down

0 comments on commit 2a51024

Please sign in to comment.