Skip to content

Commit

Permalink
test(routes): test Bento responses
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Apr 15, 2024
1 parent 5f258c5 commit 6cf5e0d
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
NON_EXISTENT_ID = "123"


def validate_object_fields(data, existing_id=None, with_internal_path=False):
def validate_object_fields(
data,
existing_id: bool = None,
with_internal_path: bool = False,
with_bento_properties: bool = False,
):
is_local = current_app.config["SERVICE_DATA_SOURCE"] == DATA_SOURCE_LOCAL
is_minio = current_app.config["SERVICE_DATA_SOURCE"] == DATA_SOURCE_MINIO

Expand All @@ -36,6 +41,16 @@ def validate_object_fields(data, existing_id=None, with_internal_path=False):
if existing_id:
assert "id" in data and data["id"] == existing_id

if with_bento_properties:
assert "bento" in data
bento_data = data["bento"]
assert "project_id" in bento_data
assert "dataset_id" in bento_data
assert "data_type" in bento_data
assert "public" in bento_data
else:
assert "bento" not in data


def test_service_info(client):
from chord_drs.app import application
Expand Down Expand Up @@ -100,10 +115,15 @@ def test_object_access_fail(client):
def _test_object_and_download(client, obj, test_range=False):
res = client.get(f"/objects/{obj.id}")
data = res.get_json()

assert res.status_code == 200
validate_object_fields(data, existing_id=obj.id)

# Check that we can get extra Bento data
res = client.get(f"/objects/{obj.id}?with_bento_properties=true")
data = res.get_json()
assert res.status_code == 200
validate_object_fields(data, existing_id=obj.id, with_bento_properties=True)

# Check that we don't have access via an access ID (since we don't generate them)
res = client.get(f"/objects/{obj.id}/access/no_access")
assert res.status_code == 404
Expand Down Expand Up @@ -178,8 +198,8 @@ def test_object_and_download_minio(client_minio, drs_object_minio):

@responses.activate
def test_object_and_download_minio_specific_perms(client_minio, drs_object_minio):
# _test_object_and_download does 3 different accesses
authz_drs_specific_obj(iters=4)
# _test_object_and_download does 5 different accesses
authz_drs_specific_obj(iters=5)
_test_object_and_download(client_minio, drs_object_minio)


Expand All @@ -191,8 +211,8 @@ def test_object_and_download(client, drs_object):

@responses.activate
def test_object_and_download_specific_perms(client, drs_object):
# _test_object_and_download does 3 different accesses
authz_drs_specific_obj(iters=4)
# _test_object_and_download does 5 different accesses
authz_drs_specific_obj(iters=5)
_test_object_and_download(client, drs_object)


Expand Down

0 comments on commit 6cf5e0d

Please sign in to comment.