Skip to content

Commit

Permalink
Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Sep 15, 2023
1 parent 5b1c3b1 commit a5aa263
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 197 deletions.
136 changes: 69 additions & 67 deletions application/tests/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit a5aa263

Please sign in to comment.