Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-880 committed Aug 2, 2024
1 parent 314aec3 commit 4529e15
Showing 1 changed file with 47 additions and 41 deletions.
88 changes: 47 additions & 41 deletions python/tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import json


def normalize_path(path):
return path.replace('\\', '/')


def test_failed_server_start_in_time():
tmp_work_dir = tempfile.mkdtemp()
server = None
Expand Down Expand Up @@ -153,7 +157,7 @@ def test_send_graph_fails_if_graph_already_exists_at_namespace():
try:
client.send_graph(path="shivam/g", graph=g)
except Exception as e:
assert "Graph already exists by name = shivam/g" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_send_graph_succeeds_if_graph_already_exists_at_namespace_with_overwrite_enabled():
Expand Down Expand Up @@ -303,7 +307,7 @@ def test_upload_graph_fails_if_graph_already_exists():
try:
client.upload_graph(path="g", file_path=g_file_path)
except Exception as e:
assert "Graph already exists by name = g" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_upload_graph_succeeds_if_graph_already_exists_with_overwrite_enabled():
Expand Down Expand Up @@ -379,7 +383,7 @@ def test_upload_graph_fails_if_graph_already_exists_at_namespace():
try:
client.upload_graph(path="shivam/g", file_path=g_file_path, overwrite=False)
except Exception as e:
assert "Graph already exists by name = shivam/g" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_upload_graph_succeeds_if_graph_already_exists_at_namespace_with_overwrite_enabled():
Expand Down Expand Up @@ -452,7 +456,7 @@ def test_load_graph_fails_if_graph_already_exists():
try:
client.load_graph(file_path=g_file_path)
except Exception as e:
assert "Graph already exists by name = " + path in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_load_graph_succeeds_if_graph_already_exists_with_overwrite_enabled():
Expand Down Expand Up @@ -529,7 +533,7 @@ def test_load_graph_fails_if_graph_already_exists_at_namespace():
try:
client.load_graph(file_path=g_file_path, overwrite=False, namespace="shivam")
except Exception as e:
assert "Graph already exists by name = " + path in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_load_graph_succeeds_if_graph_already_exists_at_namespace_with_overwrite_enabled():
Expand Down Expand Up @@ -572,7 +576,7 @@ def test_get_graph_fails_if_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_get_graph_fails_if_graph_not_found_at_namespace():
Expand All @@ -584,7 +588,7 @@ def test_get_graph_fails_if_graph_not_found_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_get_graph_succeeds_if_graph_found():
Expand Down Expand Up @@ -620,9 +624,10 @@ def test_get_graph_succeeds_if_graph_found_at_namespace():
g.save_to_file(os.path.join(work_dir, "shivam", "g2"))

query = """{ graph(path: "shivam/g2") { name, path, nodes { list { name } } } }"""
assert client.query(query) == {
'graph': {'name': 'g2', 'nodes': {'list': [{'name': 'ben'}, {'name': 'hamza'}, {'name': 'haaroon'}]},
'path': 'shivam/g2'}}
response = client.query(query)
assert response['graph']['name'] == 'g2'
assert response['graph']['nodes'] == {'list': [{'name': 'ben'}, {'name': 'hamza'}, {'name': 'haaroon'}]}
assert normalize_path(response['graph']['path']) == 'shivam/g2'


def test_get_graphs_returns_emtpy_list_if_no_graphs_found():
Expand All @@ -637,6 +642,7 @@ def test_get_graphs_returns_emtpy_list_if_no_graphs_found():
}



def test_get_graphs_returns_graph_list_if_graphs_found():
work_dir = tempfile.mkdtemp()
with RaphtoryServer(work_dir).start() as server:
Expand All @@ -658,7 +664,7 @@ def test_get_graphs_returns_graph_list_if_graphs_found():
sorted_response = {
'graphs': {
'name': sorted(response['graphs']['name']),
'path': sorted(response['graphs']['path'])
'path': sorted(normalize_path(p) for p in response['graphs']['path'])
}
}
assert sorted_response == {
Expand Down Expand Up @@ -731,7 +737,7 @@ def test_receive_graph_fails_if_no_graph_found_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g2" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_receive_graph_succeeds_if_graph_found_at_namespace():
Expand Down Expand Up @@ -770,7 +776,7 @@ def test_move_graph_fails_if_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found ben/g5" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_move_graph_fails_if_graph_with_same_name_already_exists():
Expand All @@ -796,7 +802,7 @@ def test_move_graph_fails_if_graph_with_same_name_already_exists():
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = g6" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_move_graph_fails_if_graph_with_same_name_already_exists_at_same_namespace_as_graph():
Expand All @@ -822,7 +828,7 @@ def test_move_graph_fails_if_graph_with_same_name_already_exists_at_same_namespa
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = ben/g6" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_move_graph_fails_if_graph_with_same_name_already_exists_at_diff_namespace_as_graph():
Expand All @@ -849,7 +855,7 @@ def test_move_graph_fails_if_graph_with_same_name_already_exists_at_diff_namespa
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = shivam/g6" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_move_graph_succeeds():
Expand Down Expand Up @@ -878,7 +884,7 @@ def test_move_graph_succeeds():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"

query = """{graph(path: "g4") {
nodes {list {name}}
Expand Down Expand Up @@ -917,7 +923,7 @@ def test_move_graph_using_client_api_succeeds():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"

query = """{graph(path: "ben/g4") {
nodes {list {name}}
Expand Down Expand Up @@ -962,7 +968,7 @@ def test_move_graph_succeeds_at_same_namespace_as_graph():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"

query = """{graph(path: "shivam/g4") {
nodes {list {name}}
Expand Down Expand Up @@ -1008,7 +1014,7 @@ def test_move_graph_succeeds_at_diff_namespace_as_graph():
try:
client.query(query)
except Exception as e:
assert "Graph not found ben/g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"

query = """{graph(path: "shivam/g4") {
nodes {list {name}}
Expand Down Expand Up @@ -1040,7 +1046,7 @@ def test_copy_graph_fails_if_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found ben/g5" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_copy_graph_fails_if_graph_with_same_name_already_exists():
Expand All @@ -1066,7 +1072,7 @@ def test_copy_graph_fails_if_graph_with_same_name_already_exists():
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = g6" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_copy_graph_fails_if_graph_with_same_name_already_exists_at_same_namespace_as_graph():
Expand All @@ -1092,7 +1098,7 @@ def test_copy_graph_fails_if_graph_with_same_name_already_exists_at_same_namespa
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = ben/g6" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_copy_graph_fails_if_graph_with_same_name_already_exists_at_diff_namespace_as_graph():
Expand All @@ -1119,7 +1125,7 @@ def test_copy_graph_fails_if_graph_with_same_name_already_exists_at_diff_namespa
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = shivam/g6" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_copy_graph_succeeds():
Expand Down Expand Up @@ -1294,7 +1300,7 @@ def test_delete_graph_fails_if_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found ben/g5" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_delete_graph_succeeds_if_graph_found():
Expand All @@ -1317,7 +1323,7 @@ def test_delete_graph_succeeds_if_graph_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found ben/g5" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_delete_graph_using_client_api_succeeds_if_graph_found():
Expand All @@ -1335,7 +1341,7 @@ def test_delete_graph_using_client_api_succeeds_if_graph_found():
try:
client.delete_graph("g1")
except Exception as e:
assert "Graph not found ben/g5" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_delete_graph_succeeds_if_graph_found_at_namespace():
Expand All @@ -1359,7 +1365,7 @@ def test_delete_graph_succeeds_if_graph_found_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_create_graph_fail_if_parent_graph_not_found():
Expand All @@ -1379,7 +1385,7 @@ def test_create_graph_fail_if_parent_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found g0" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_create_graph_fail_if_parent_graph_not_found_at_namespace():
Expand All @@ -1399,7 +1405,7 @@ def test_create_graph_fail_if_parent_graph_not_found_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g0" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_create_graph_fail_if_graph_already_exists():
Expand All @@ -1424,7 +1430,7 @@ def test_create_graph_fail_if_graph_already_exists():
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_create_graph_fail_if_graph_already_exists_at_namespace():
Expand All @@ -1450,7 +1456,7 @@ def test_create_graph_fail_if_graph_already_exists_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = shivam/g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_create_graph_succeeds():
Expand Down Expand Up @@ -1590,7 +1596,7 @@ def test_update_graph_with_new_graph_name_fails_if_parent_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found g0" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_with_new_graph_name_fails_if_current_graph_not_found():
Expand All @@ -1613,7 +1619,7 @@ def test_update_graph_with_new_graph_name_fails_if_current_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g0" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_with_new_graph_name_fails_if_new_graph_already_exists():
Expand Down Expand Up @@ -1645,7 +1651,7 @@ def test_update_graph_with_new_graph_name_fails_if_new_graph_already_exists():
try:
client.query(query)
except Exception as e:
assert "Graph already exists by name = g3" in str(e), f"Unexpected exception message: {e}"
assert "Graph already exists by name" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_with_new_graph_name_succeeds_if_parent_graph_belongs_to_different_namespace():
Expand Down Expand Up @@ -1923,7 +1929,7 @@ def test_update_graph_fails_if_parent_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found g0" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_fails_if_current_graph_not_found():
Expand All @@ -1946,7 +1952,7 @@ def test_update_graph_fails_if_current_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g0" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_succeeds_if_parent_graph_belongs_to_different_namespace():
Expand Down Expand Up @@ -2208,7 +2214,7 @@ def test_update_graph_last_opened_fails_if_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_last_opened_fails_if_graph_not_found_at_namespace():
Expand All @@ -2220,7 +2226,7 @@ def test_update_graph_last_opened_fails_if_graph_not_found_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_update_graph_last_opened_succeeds():
Expand Down Expand Up @@ -2283,7 +2289,7 @@ def test_archive_graph_fails_if_graph_not_found():
try:
client.query(query)
except Exception as e:
assert "Graph not found g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_archive_graph_fails_if_graph_not_found_at_namespace():
Expand All @@ -2295,7 +2301,7 @@ def test_archive_graph_fails_if_graph_not_found_at_namespace():
try:
client.query(query)
except Exception as e:
assert "Graph not found shivam/g1" in str(e), f"Unexpected exception message: {e}"
assert "Graph not found" in str(e), f"Unexpected exception message: {e}"


def test_archive_graph_succeeds():
Expand Down

0 comments on commit 4529e15

Please sign in to comment.