Skip to content

Commit

Permalink
Link to file instead of URL for dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
fivegrant committed Aug 8, 2023
1 parent 2f2ec4c commit dc9231d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ def operation_context(request):
with open(f"{path_prefix}/output/tds_simulation.json", "r") as file:
ctx["tds_simulation"] = json.load(file)

def fetch(handle):
def fetch(handle, return_path=False):
io_dir = (
"input" if os.path.exists(f"{path_prefix}/input/{handle}") else "output"
)
with open(f"./tests/examples/{chosen}/{io_dir}/{handle}", "r") as file:
path = f"{path_prefix}/{io_dir}/{handle}"
if return_path:
return os.path.abspath(path)
with open(path, "r") as file:
return file.read()

ctx["fetch"] = fetch
Expand Down Expand Up @@ -59,13 +62,12 @@ def test_example_conversion(self, operation_context, requests_mock):

dataset_id = operation_context["request"]["dataset"]["id"]
filename = operation_context["request"]["dataset"]["filename"]
dataset = operation_context["fetch"](filename)
dataset_loc = {"method": "GET", "url": "http://dataset"}
dataset = operation_context["fetch"](filename, True)
dataset_loc = {"method": "GET", "url": dataset}
requests_mock.get(
f"{TDS_URL}/datasets/{dataset_id}/download-url?filename={filename}",
json=dataset_loc,
)
requests_mock.get("http://dataset", text=dataset)

### Act and Assert

Expand Down Expand Up @@ -110,8 +112,8 @@ def test_example_conversion(self, operation_context, requests_mock):

dataset_id = operation_context["request"]["dataset"]["id"]
filename = operation_context["request"]["dataset"]["filename"]
dataset = operation_context["fetch"](filename)
dataset_loc = {"method": "GET", "url": "http://dataset"}
dataset = operation_context["fetch"](filename, True)
dataset_loc = {"method": "GET", "url": dataset}
requests_mock.get(
f"{TDS_URL}/datasets/{dataset_id}/download-url?filename={filename}",
json=dataset_loc,
Expand Down

0 comments on commit dc9231d

Please sign in to comment.