Skip to content

Commit

Permalink
checks: Node not used in any links
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Oct 18, 2022
1 parent fd201b8 commit a5ad6c0
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 8 deletions.
28 changes: 28 additions & 0 deletions libcoveofds/lib/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,39 @@ def skip_if_any_related_resources(self) -> bool:
return False


class IsNodeUsedInLinkAdditionalCheckForNetwork(AdditionalCheckForNetwork):
def __init__(self, lib_cove_bods_config, schema_object):
super().__init__(lib_cove_bods_config, schema_object)
self._node_ids_used_in_links = []

def check_link_first_pass(self, link: dict):
start = link.get("start")
if start and start not in self._node_ids_used_in_links:
self._node_ids_used_in_links.append(start)
end = link.get("end")
if end and end not in self._node_ids_used_in_links:
self._node_ids_used_in_links.append(end)

def check_node_second_pass(self, node: dict):
id = node.get("id")
if id and id not in self._node_ids_used_in_links:
self._additional_check_results.append(
{
"type": "node_not_used_in_any_links",
"node_id": node.get("id"),
}
)

def skip_if_any_related_resources(self) -> bool:
return True


ADDITIONAL_CHECK_CLASSES_FOR_NETWORK = [
LinksMustHaveValidNodesAdditionalCheckForNetwork,
NodesLocationAndLinksRouteAdditionalCheckForNetwork,
PhaseReferenceAdditionalCheckForNetwork,
NodeInternationalConnectionCountryAdditionalCheckForNetwork,
IsNodeUsedInLinkAdditionalCheckForNetwork,
]


Expand Down
4 changes: 0 additions & 4 deletions tests/fixtures/0_1_0_alpha/end_node_not_found_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
{
"id": "1",
"name": "Accra"
},
{
"id": "2",
"name": "Kumasi"
}
],
"links": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
]
]
}
},
{
"id": "2",
"name": "Kumasi"
}
],
"links": [
{
"id": "1",
"name": "Accra to Kumasi",
"start": "1",
"end": "2"
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/0_1_0_alpha/node_location_type_incorrect_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
5.625
]
}
},
{
"id": "2",
"name": "Kumasi"
}
],
"links": [
{
"id": "1",
"name": "Accra to Kumasi",
"start": "1",
"end": "2"
}
]
}
Expand Down
27 changes: 27 additions & 0 deletions tests/fixtures/0_1_0_alpha/node_not_used_in_any_links_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"networks": [
{
"id": "a096d627-72e1-4f9b-b129-951b1737bff4",
"name": "Ghana Fibre Network",
"nodes": [
{
"id": "1"
},
{
"id": "2"
},
{
"id": "3"
}
],
"links": [
{
"id": "1",
"name": "Accra to Kumasi",
"start": "1",
"end": "2"
}
]
}
]
}
4 changes: 0 additions & 4 deletions tests/fixtures/0_1_0_alpha/start_node_not_found_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
"id": "a096d627-72e1-4f9b-b129-951b1737bff4",
"name": "Ghana Fibre Network",
"nodes": [
{
"id": "1",
"name": "Accra"
},
{
"id": "2",
"name": "Kumasi"
Expand Down
25 changes: 25 additions & 0 deletions tests/test_api_0_1_0_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,28 @@ def test_node_international_connections_country_not_set_1():
"node_id": "1",
"type": "node_international_connections_country_not_set",
}


def test_node_not_used_in_any_links_1():
cove_temp_folder = tempfile.mkdtemp(
prefix="lib-cove-ofds-tests-", dir=tempfile.gettempdir()
)
json_filename = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"fixtures",
"0_1_0_alpha",
"node_not_used_in_any_links_1.json",
)

results = ofds_json_output(cove_temp_folder, json_filename)

assert results["schema_version"] == "0.1.0-alpha"

assert results["validation_errors_count"] == 0

assert results["additional_checks_count"] == 1
assert results["additional_checks"][0] == {
"network_id": "a096d627-72e1-4f9b-b129-951b1737bff4",
"node_id": "3",
"type": "node_not_used_in_any_links",
}

0 comments on commit a5ad6c0

Please sign in to comment.