Skip to content

Commit

Permalink
#223: Add tests for distinct filter with related entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed May 14, 2021
1 parent 2623b18 commit f261f7b
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/db/endpoints/test_get_with_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

from datagateway_api.common.constants import Constants
from datagateway_api.common.date_handler import DateHandler


class TestDBGetWithFilters:
def test_valid_get_with_filters(
Expand Down Expand Up @@ -43,6 +46,68 @@ def test_valid_get_with_filters_multiple_distinct(

assert test_response.json == expected

@pytest.mark.parametrize(
"distinct_param, expected_response",
[
pytest.param(
'"title"',
[{"title": "Title for DataGateway API Testing (DB) 0"}],
id="Single unrelated distinct field",
),
pytest.param(
'["createTime", "investigationInstruments.createTime"]',
[
{
"createTime": DateHandler.datetime_object_to_str(
Constants.TEST_MOD_CREATE_DATETIME,
),
"investigationInstruments": {
"createTime": DateHandler.datetime_object_to_str(
Constants.TEST_MOD_CREATE_DATETIME,
),
},
},
],
id="List containing related distinct field",
),
pytest.param(
'["createTime", "investigationInstruments.createTime", "facility.id"]',
[
{
"createTime": DateHandler.datetime_object_to_str(
Constants.TEST_MOD_CREATE_DATETIME,
),
"facility": {"id": 1},
"investigationInstruments": {
"createTime": DateHandler.datetime_object_to_str(
Constants.TEST_MOD_CREATE_DATETIME,
),
},
},
],
id="Multiple related distinct fields",
),
],
)
@pytest.mark.usefixtures("isis_specific_endpoint_data_db")
def test_valid_get_with_filters_related_distinct(
self,
flask_test_app_db,
valid_db_credentials_header,
distinct_param,
expected_response,
):
test_response = flask_test_app_db.get(
'/investigations?where={"title": {"like": "Title for DataGateway API'
' Testing (DB)"}}'
f"&distinct={distinct_param}",
headers=valid_db_credentials_header,
)

print(test_response.json)

assert test_response.json == expected_response

def test_limit_skip_merge_get_with_filters(
self,
flask_test_app_db,
Expand Down

0 comments on commit f261f7b

Please sign in to comment.