From a5aa263ab43c466578c71bf5a96720b1d0e344cb Mon Sep 17 00:00:00 2001 From: john681611 Date: Fri, 15 Sep 2023 11:48:58 +0100 Subject: [PATCH] Fix existing tests --- application/tests/db_test.py | 136 +++++++------- application/tests/gap_analysis_test.py | 241 ++++++++++++------------- 2 files changed, 180 insertions(+), 197 deletions(-) diff --git a/application/tests/db_test.py b/application/tests/db_test.py index 714b11423..0f2193b97 100644 --- a/application/tests/db_test.py +++ b/application/tests/db_test.py @@ -1139,9 +1139,12 @@ def test_get_root_cres(self): self.maxDiff = None self.assertEqual(root_cres, [cres[0], cres[1], cres[7]]) - def test_gap_analysis_disconnected(self): + @patch.object(db.NEO_DB, "gap_analysis") + def test_gap_analysis_disconnected(self, gap_mock): collection = db.Node_collection() collection.neo_db.connected = False + gap_mock.return_value = (None, None) + self.assertEqual(collection.gap_analysis(["a", "b"]), None) @patch.object(db.NEO_DB, "gap_analysis") @@ -1157,9 +1160,10 @@ def test_gap_analysis_no_links(self, gap_mock): collection = db.Node_collection() collection.neo_db.connected = True - gap_mock.return_value = ([{"id": 1}], []) + gap_mock.return_value = ([defs.CRE(name="bob", id=1)], []) self.assertEqual( - collection.gap_analysis(["a", "b"]), {1: {"start": {"id": 1}, "paths": {}}} + collection.gap_analysis(["a", "b"]), + {1: {"start": defs.CRE(name="bob", id=1), "paths": {}}}, ) @patch.object(db.NEO_DB, "gap_analysis") @@ -1168,30 +1172,32 @@ def test_gap_analysis_one_link(self, gap_mock): collection.neo_db.connected = True path = [ { - "end": { - "id": 1, - }, + "end": defs.CRE(name="bob", id=1), "relationship": "LINKED_TO", - "start": { - "id": "a", - }, + "start": defs.CRE(name="bob", id="a"), }, { - "end": { - "id": 2, - }, + "end": defs.CRE(name="bob", id=2), "relationship": "LINKED_TO", - "start": {"id": "a"}, + "start": defs.CRE(name="bob", id="a"), }, ] gap_mock.return_value = ( - [{"id": 1}], - [{"start": {"id": 1}, "end": {"id": 2}, "path": path}], + [defs.CRE(name="bob", id=1)], + [ + { + "start": defs.CRE(name="bob", id=1), + "end": defs.CRE(name="bob", id=2), + "path": path, + } + ], ) expected = { 1: { - "start": {"id": 1}, - "paths": {2: {"end": {"id": 2}, "path": path, "score": 0}}, + "start": defs.CRE(name="bob", id=1), + "paths": { + 2: {"end": defs.CRE(name="bob", id=2), "path": path, "score": 0} + }, } } self.assertEqual(collection.gap_analysis(["a", "b"]), expected) @@ -1202,51 +1208,49 @@ def test_gap_analysis_duplicate_link_path_existing_lower(self, gap_mock): collection.neo_db.connected = True path = [ { - "end": { - "id": 1, - }, + "end": defs.CRE(name="bob", id=1), "relationship": "LINKED_TO", - "start": { - "id": "a", - }, + "start": defs.CRE(name="bob", id="a"), }, { - "end": { - "id": 2, - }, + "end": defs.CRE(name="bob", id=2), "relationship": "LINKED_TO", - "start": {"id": "a"}, + "start": defs.CRE(name="bob", id="a"), }, ] path2 = [ { - "end": { - "id": 1, - }, + "end": defs.CRE(name="bob", id=1), "relationship": "LINKED_TO", - "start": { - "id": "a", - }, + "start": defs.CRE(name="bob", id="a"), }, { - "end": { - "id": 2, - }, + "end": defs.CRE(name="bob", id=2), "relationship": "RELATED", - "start": {"id": "a"}, + "start": defs.CRE(name="bob", id="a"), }, ] gap_mock.return_value = ( - [{"id": 1}], + [defs.CRE(name="bob", id=1)], [ - {"start": {"id": 1}, "end": {"id": 2}, "path": path}, - {"start": {"id": 1}, "end": {"id": 2}, "path": path2}, + { + "start": defs.CRE(name="bob", id=1), + "end": defs.CRE(name="bob", id=2), + "path": path, + }, + { + "start": defs.CRE(name="bob", id=1), + "end": defs.CRE(name="bob", id=2), + "path": path2, + }, ], ) expected = { 1: { - "start": {"id": 1}, - "paths": {2: {"end": {"id": 2}, "path": path, "score": 0}}, + "start": defs.CRE(name="bob", id=1), + "paths": { + 2: {"end": defs.CRE(name="bob", id=2), "path": path, "score": 0} + }, } } self.assertEqual(collection.gap_analysis(["a", "b"]), expected) @@ -1257,51 +1261,49 @@ def test_gap_analysis_duplicate_link_path_existing_higher(self, gap_mock): collection.neo_db.connected = True path = [ { - "end": { - "id": 1, - }, + "end": defs.CRE(name="bob", id=1), "relationship": "LINKED_TO", - "start": { - "id": "a", - }, + "start": defs.CRE(name="bob", id="a"), }, { - "end": { - "id": 2, - }, + "end": defs.CRE(name="bob", id=2), "relationship": "LINKED_TO", - "start": {"id": "a"}, + "start": defs.CRE(name="bob", id="a"), }, ] path2 = [ { - "end": { - "id": 1, - }, + "end": defs.CRE(name="bob", id=1), "relationship": "LINKED_TO", - "start": { - "id": "a", - }, + "start": defs.CRE(name="bob", id="a"), }, { - "end": { - "id": 2, - }, + "end": defs.CRE(name="bob", id=2), "relationship": "RELATED", - "start": {"id": "a"}, + "start": defs.CRE(name="bob", id="a"), }, ] gap_mock.return_value = ( - [{"id": 1}], + [defs.CRE(name="bob", id=1)], [ - {"start": {"id": 1}, "end": {"id": 2}, "path": path2}, - {"start": {"id": 1}, "end": {"id": 2}, "path": path}, + { + "start": defs.CRE(name="bob", id=1), + "end": defs.CRE(name="bob", id=2), + "path": path2, + }, + { + "start": defs.CRE(name="bob", id=1), + "end": defs.CRE(name="bob", id=2), + "path": path, + }, ], ) expected = { 1: { - "start": {"id": 1}, - "paths": {2: {"end": {"id": 2}, "path": path, "score": 0}}, + "start": defs.CRE(name="bob", id=1), + "paths": { + 2: {"end": defs.CRE(name="bob", id=2), "path": path, "score": 0} + }, } } self.assertEqual(collection.gap_analysis(["a", "b"]), expected) diff --git a/application/tests/gap_analysis_test.py b/application/tests/gap_analysis_test.py index 396da8ee4..b4bf1a7ed 100644 --- a/application/tests/gap_analysis_test.py +++ b/application/tests/gap_analysis_test.py @@ -1,4 +1,5 @@ import unittest +from application.defs import cre_defs from application.utils.gap_analysis import ( get_path_score, @@ -16,47 +17,57 @@ def setUp(self) -> None: return None def test_get_relation_direction_UP(self): - step = {"start": {"id": "123"}, "end": {"id": "234"}} + step = { + "start": cre_defs.CRE(name="bob", id="123"), + "end": cre_defs.CRE(name="bob", id="234"), + } self.assertEqual(get_relation_direction(step, "123"), "UP") def test_get_relation_direction_DOWN(self): - step = {"start": {"id": "123"}, "end": {"id": "234"}} + step = { + "start": cre_defs.CRE(name="bob", id="123"), + "end": cre_defs.CRE(name="bob", id="234"), + } self.assertEqual(get_relation_direction(step, "234"), "DOWN") def test_get_next_id_start(self): - step = {"start": {"id": "123"}, "end": {"id": "234"}} + step = { + "start": cre_defs.CRE(name="bob", id="123"), + "end": cre_defs.CRE(name="bob", id="234"), + } self.assertEqual(get_next_id(step, "234"), "123") def test_get_next_id_end(self): - step = {"start": {"id": "123"}, "end": {"id": "234"}} + step = { + "start": cre_defs.CRE(name="bob", id="123"), + "end": cre_defs.CRE(name="bob", id="234"), + } self.assertEqual(get_next_id(step, "123"), "234") def test_get_path_score_direct_siblings_returns_zero(self): path = { - "start": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "start": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), + "end": cre_defs.CRE(name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d"), "path": [ { - "end": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, + "end": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), "relationship": "LINKED_TO", - "start": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "start": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), }, { - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "end": cre_defs.CRE( + name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d" + ), "relationship": "LINKED_TO", - "start": { - "id": "e2ac59b2-c1d8-4525-a6b3-155d480aecc9", - }, + "start": cre_defs.CRE( + name="bob", id="e2ac59b2-c1d8-4525-a6b3-155d480aecc9" + ), }, ], } @@ -64,39 +75,33 @@ def test_get_path_score_direct_siblings_returns_zero(self): def test_get_path_score_one_up_returns_one_up_penaltiy(self): path = { - "start": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "start": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), + "end": cre_defs.CRE(name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d"), "path": [ { - "end": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, + "end": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), "relationship": "LINKED_TO", - "start": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "start": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), }, { - "end": { - "id": "123", - }, + "end": cre_defs.CRE(name="bob", id="123"), "relationship": "CONTAINS", - "start": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "start": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), }, { - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "end": cre_defs.CRE( + name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d" + ), "relationship": "LINKED_TO", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, ], } @@ -104,39 +109,33 @@ def test_get_path_score_one_up_returns_one_up_penaltiy(self): def test_get_path_score_one_down_one_returns_one_down_penaltiy(self): path = { - "start": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "start": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), + "end": cre_defs.CRE(name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d"), "path": [ { - "end": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, + "end": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), "relationship": "LINKED_TO", - "start": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "start": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), }, { - "end": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "end": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), "relationship": "CONTAINS", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, { - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "end": cre_defs.CRE( + name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d" + ), "relationship": "LINKED_TO", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, ], } @@ -144,39 +143,33 @@ def test_get_path_score_one_down_one_returns_one_down_penaltiy(self): def test_get_path_score_related_returns_related_penalty(self): path = { - "start": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "start": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), + "end": cre_defs.CRE(name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d"), "path": [ { - "end": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, + "end": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), "relationship": "LINKED_TO", - "start": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "start": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), }, { - "end": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "end": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), "relationship": "RELATED", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, { - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "end": cre_defs.CRE( + name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d" + ), "relationship": "LINKED_TO", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, ], } @@ -184,57 +177,45 @@ def test_get_path_score_related_returns_related_penalty(self): def test_get_path_score_one_of_each_returns_penalty(self): path = { - "start": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "start": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), + "end": cre_defs.CRE(name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d"), "path": [ { - "end": { - "id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", - }, + "end": cre_defs.CRE( + name="bob", id="029f7cd7-ef2f-4f25-b0d2-3227cde4b34b" + ), "relationship": "LINKED_TO", - "start": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "start": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), }, { - "end": { - "id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", - }, + "end": cre_defs.CRE( + name="bob", id="07bc9f6f-5387-4dc6-b277-0022ed76049f" + ), "relationship": "CONTAINS", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, { - "end": { - "id": "456", - }, + "end": cre_defs.CRE(name="bob", id="456"), "relationship": "RELATED", - "start": { - "id": "123", - }, + "start": cre_defs.CRE(name="bob", id="123"), }, { - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "end": cre_defs.CRE( + name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d" + ), "relationship": "CONTAINS", - "start": { - "id": "456", - }, + "start": cre_defs.CRE(name="bob", id="456"), }, { - "end": { - "id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", - }, + "end": cre_defs.CRE( + name="bob", id="7d030730-14cc-4c43-8927-f2d0f5fbcf5d" + ), "relationship": "LINKED_TO", - "start": { - "id": "456", - }, + "start": cre_defs.CRE(name="bob", id="456"), }, ], }