Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/tests/test_api_client.py
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def graph_client(): | ||||
server.kill() | server.kill() | ||||
class TestEndpoints: | class TestEndpoints: | ||||
@pytest.fixture(autouse=True) | @pytest.fixture(autouse=True) | ||||
def init_graph_client(self, graph_client): | def init_graph_client(self, graph_client): | ||||
self.client = graph_client | self.client = graph_client | ||||
@staticmethod | |||||
def assert_endpoint_output(actual, expected): | |||||
assert set(actual.keys()) == {'result', 'meta'} | |||||
assert set(actual['result']) == set(expected['result']) | |||||
assert actual['meta'] == expected['meta'] | |||||
def test_leaves(self): | def test_leaves(self): | ||||
actual = self.client.leaves( | actual = self.client.leaves( | ||||
'swh:1:ori:0000000000000000000000000000000000000021' | 'swh:1:ori:0000000000000000000000000000000000000021' | ||||
) | ) | ||||
expected = [ | expected = { | ||||
'result': [ | |||||
'swh:1:cnt:0000000000000000000000000000000000000001', | 'swh:1:cnt:0000000000000000000000000000000000000001', | ||||
'swh:1:cnt:0000000000000000000000000000000000000004', | 'swh:1:cnt:0000000000000000000000000000000000000004', | ||||
'swh:1:cnt:0000000000000000000000000000000000000005', | 'swh:1:cnt:0000000000000000000000000000000000000005', | ||||
'swh:1:cnt:0000000000000000000000000000000000000007' | 'swh:1:cnt:0000000000000000000000000000000000000007' | ||||
] | ], | ||||
assert set(actual.keys()) == {'result'} | 'meta': { | ||||
assert set(actual['result']) == set(expected) | 'nb_edges_accessed': 13 | ||||
} | |||||
} | |||||
TestEndpoints.assert_endpoint_output(actual, expected) | |||||
def test_neighbors(self): | def test_neighbors(self): | ||||
actual = self.client.neighbors( | actual = self.client.neighbors( | ||||
'swh:1:rev:0000000000000000000000000000000000000009', | 'swh:1:rev:0000000000000000000000000000000000000009', | ||||
direction='backward' | direction='backward' | ||||
) | ) | ||||
expected = [ | expected = { | ||||
'result': [ | |||||
'swh:1:snp:0000000000000000000000000000000000000020', | 'swh:1:snp:0000000000000000000000000000000000000020', | ||||
'swh:1:rel:0000000000000000000000000000000000000010', | 'swh:1:rel:0000000000000000000000000000000000000010', | ||||
'swh:1:rev:0000000000000000000000000000000000000013' | 'swh:1:rev:0000000000000000000000000000000000000013' | ||||
] | ], | ||||
assert set(actual.keys()) == {'result'} | 'meta': { | ||||
assert set(actual['result']) == set(expected) | 'nb_edges_accessed': 3 | ||||
} | |||||
} | |||||
TestEndpoints.assert_endpoint_output(actual, expected) | |||||
def test_stats(self): | def test_stats(self): | ||||
stats = self.client.stats() | stats = self.client.stats() | ||||
assert set(stats.keys()) == {'counts', 'ratios', 'indegree', | assert set(stats.keys()) == {'counts', 'ratios', 'indegree', | ||||
'outdegree'} | 'outdegree'} | ||||
assert set(stats['counts'].keys()) == {'nodes', 'edges'} | assert set(stats['counts'].keys()) == {'nodes', 'edges'} | ||||
Show All 15 Lines | def test_stats(self): | ||||
assert stats['outdegree']['max'] == 3 | assert stats['outdegree']['max'] == 3 | ||||
assert isinstance(stats['outdegree']['avg'], float) | assert isinstance(stats['outdegree']['avg'], float) | ||||
def test_visit_nodes(self): | def test_visit_nodes(self): | ||||
actual = self.client.visit_nodes( | actual = self.client.visit_nodes( | ||||
'swh:1:rel:0000000000000000000000000000000000000010', | 'swh:1:rel:0000000000000000000000000000000000000010', | ||||
edges='rel:rev,rev:rev' | edges='rel:rev,rev:rev' | ||||
) | ) | ||||
expected = [ | expected = { | ||||
'result': [ | |||||
'swh:1:rel:0000000000000000000000000000000000000010', | 'swh:1:rel:0000000000000000000000000000000000000010', | ||||
'swh:1:rev:0000000000000000000000000000000000000009', | 'swh:1:rev:0000000000000000000000000000000000000009', | ||||
'swh:1:rev:0000000000000000000000000000000000000003' | 'swh:1:rev:0000000000000000000000000000000000000003' | ||||
] | ], | ||||
assert set(actual.keys()) == {'result'} | 'meta': { | ||||
assert set(actual['result']) == set(expected) | 'nb_edges_accessed': 4 | ||||
} | |||||
} | |||||
TestEndpoints.assert_endpoint_output(actual, expected) | |||||
def test_visit_paths(self): | def test_visit_paths(self): | ||||
actual = self.client.visit_paths( | actual = self.client.visit_paths( | ||||
'swh:1:snp:0000000000000000000000000000000000000020', | 'swh:1:snp:0000000000000000000000000000000000000020', | ||||
edges='snp:*,rev:*') | edges='snp:*,rev:*') | ||||
assert set(actual.keys()) == {'result'} | actual['result'] = [tuple(path) for path in actual['result']] | ||||
actual = [tuple(path) for path in actual['result']] | expected = { | ||||
expected = [ | 'result': [ | ||||
( | ( | ||||
'swh:1:snp:0000000000000000000000000000000000000020', | 'swh:1:snp:0000000000000000000000000000000000000020', | ||||
'swh:1:rev:0000000000000000000000000000000000000009', | 'swh:1:rev:0000000000000000000000000000000000000009', | ||||
'swh:1:rev:0000000000000000000000000000000000000003', | 'swh:1:rev:0000000000000000000000000000000000000003', | ||||
'swh:1:dir:0000000000000000000000000000000000000002' | 'swh:1:dir:0000000000000000000000000000000000000002' | ||||
), | ), | ||||
( | ( | ||||
'swh:1:snp:0000000000000000000000000000000000000020', | 'swh:1:snp:0000000000000000000000000000000000000020', | ||||
'swh:1:rev:0000000000000000000000000000000000000009', | 'swh:1:rev:0000000000000000000000000000000000000009', | ||||
'swh:1:dir:0000000000000000000000000000000000000008' | 'swh:1:dir:0000000000000000000000000000000000000008' | ||||
), | ), | ||||
( | ( | ||||
'swh:1:snp:0000000000000000000000000000000000000020', | 'swh:1:snp:0000000000000000000000000000000000000020', | ||||
'swh:1:rel:0000000000000000000000000000000000000010' | 'swh:1:rel:0000000000000000000000000000000000000010' | ||||
) | ) | ||||
] | ], | ||||
assert set(actual) == set(expected) | 'meta': { | ||||
'nb_edges_accessed': 10 | |||||
} | |||||
} | |||||
TestEndpoints.assert_endpoint_output(actual, expected) | |||||
def test_walk(self): | def test_walk(self): | ||||
actual = self.client.walk( | actual = self.client.walk( | ||||
'swh:1:dir:0000000000000000000000000000000000000016', 'rel', | 'swh:1:dir:0000000000000000000000000000000000000016', 'rel', | ||||
edges='dir:dir,dir:rev,rev:*', | edges='dir:dir,dir:rev,rev:*', | ||||
direction='backward', | direction='backward', | ||||
traversal='bfs' | traversal='bfs' | ||||
) | ) | ||||
expected = [ | expected = { | ||||
'result': [ | |||||
'swh:1:dir:0000000000000000000000000000000000000016', | 'swh:1:dir:0000000000000000000000000000000000000016', | ||||
'swh:1:dir:0000000000000000000000000000000000000017', | 'swh:1:dir:0000000000000000000000000000000000000017', | ||||
'swh:1:rev:0000000000000000000000000000000000000018', | 'swh:1:rev:0000000000000000000000000000000000000018', | ||||
'swh:1:rel:0000000000000000000000000000000000000019' | 'swh:1:rel:0000000000000000000000000000000000000019' | ||||
] | ], | ||||
assert set(actual.keys()) == {'result'} | 'meta': { | ||||
assert set(actual['result']) == set(expected) | 'nb_edges_accessed': 3 | ||||
} | |||||
} | |||||
TestEndpoints.assert_endpoint_output(actual, expected) |