Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #421 from multinet-app/fix-csv-table-check
Browse files Browse the repository at this point in the history
Change order of checking edge vs node table
  • Loading branch information
jjnesbitt committed Jul 13, 2020
2 parents 0137066 + ae534ef commit 22684b2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions multinet/uploaders/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ def validate_csv(
if not rows:
raise ValidationFailed([MissingBody()])

if is_node_table(rows, key_field):
validate_node_table(rows, key_field, overwrite)
elif is_edge_table(rows):
if is_edge_table(rows):
validate_edge_table(rows)
elif is_node_table(rows, key_field):
validate_node_table(rows, key_field, overwrite)
else:
raise ValidationFailed([UnsupportedTable()])

Expand Down
4 changes: 4 additions & 0 deletions test/data/membership_with_keys.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_key,_to,_from
1783831,clubs/4,members/260
1783830,clubs/2,members/260
1783827,clubs/2,members/258
28 changes: 28 additions & 0 deletions test/test_csv_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ def read_csv(filename: str):
return list(csv.DictReader(StringIO(path_file.read())))


def test_edge_table_with_key_field(
server, managed_workspace, managed_user, data_directory
):
"""Test that an edge table with a key field is recognized as an edge table."""
with open(data_directory / "membership_with_keys.csv") as csv_file:
request_body = csv_file.read()

table_name = "membership_with_keys"
with managed_user.login(server):
resp = server.post(
f"/api/csv/{managed_workspace}/{table_name}", data=request_body
)
assert resp.status_code == 200

edge_table_resp = server.get(
f"/api/workspaces/{managed_workspace}/tables", query_string={"type": "edge"}
)
node_table_resp = server.get(
f"/api/workspaces/{managed_workspace}/tables", query_string={"type": "node"}
)

assert edge_table_resp.status_code == 200
assert table_name in edge_table_resp.json

assert node_table_resp.status_code == 200
assert table_name not in node_table_resp.json


def test_missing_key_field():
"""Test that missing key fields are handled properly."""
rows = read_csv("startrek_no_key_field.csv")
Expand Down

0 comments on commit 22684b2

Please sign in to comment.