Skip to content

Commit

Permalink
Changes to filters, endpoints and queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Reillyhewitson committed Feb 1, 2023
1 parent a4fa2e7 commit 21b0233
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 85 deletions.
4 changes: 2 additions & 2 deletions test/datagateway_api/db/endpoints/test_table_endpoints_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_valid_get_facility_cycles_with_filters(
headers=valid_db_credentials_header,
)

assert test_response.json == [isis_specific_endpoint_data_db[1].to_dict()]
assert test_response.json[0] == isis_specific_endpoint_data_db.to_dict()

def test_invalid_get_facility_cycles_with_filters(
self, flask_test_app_db, valid_db_credentials_header, final_instrument_id,
Expand All @@ -44,7 +44,7 @@ def test_valid_get_facility_cycles_count_with_filters(
headers=valid_db_credentials_header,
)

assert test_response.json == 1
assert test_response.json == 2

def test_invalid_get_facility_cycles_count_with_filters(
self, flask_test_app_db, valid_db_credentials_header, final_instrument_id,
Expand Down
132 changes: 56 additions & 76 deletions test/datagateway_api/db/test_database_filter_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,18 @@ def test_invalid_get_field(self, flask_test_app_db):
"ne",
"Title for DataGateway API Testing (DB) 0",
{
"doi": "0-449-78690-0",
"doi": "0-417-77631-4",
"endDate": "2000-07-09 00:00:00",
"name": "INVESTIGATION 1",
"releaseDate": "2000-07-05 00:00:00",
"startDate": "2000-04-03 00:00:00",
"summary": "Season identify professor happen third."
" Beat professional blue clear style have. "
"Light final summer.",
"title": "Including spend increase ability music"
" skill former. Agreement director concern once "
"technology sometimes someone staff."
"\nSuccess pull bar. Laugh senior example.",
"summary": "Throw hope parent. Receive entire soon. War top air agent must voice high describe.\nMonth shake voice. Do discuss despite least face again study. Two beyond picture rich fast sea time.",
"title": "Analysis reflect work or hour color maybe."
"\nMuch team discussion message weight.",
"facilityID": 1,
"typeID": 2,
"fileSize": None,
"fileCount": None,
"typeID": 3,
"fileSize": 0,
"fileCount": 0,
},
id="not equal (ne)",
),
Expand All @@ -201,116 +197,100 @@ def test_invalid_get_field(self, flask_test_app_db):
"nlike",
"Title for DataGateway API Testing (DB) 0",
{
"doi": "0-449-78690-0",
"doi": "0-417-77631-4",
"endDate": "2000-07-09 00:00:00",
"name": "INVESTIGATION 1",
"releaseDate": "2000-07-05 00:00:00",
"startDate": "2000-04-03 00:00:00",
"summary": "Season identify professor happen third."
" Beat professional blue clear style have. "
"Light final summer.",
"title": "Including spend increase ability music"
" skill former. Agreement director concern once "
"technology sometimes someone staff."
"\nSuccess pull bar. Laugh senior example.",
"summary": "Throw hope parent. Receive entire soon. War top air agent must voice high describe.\nMonth shake voice. Do discuss despite least face again study. Two beyond picture rich fast sea time.",
"title": "Analysis reflect work or hour color maybe."
"\nMuch team discussion message weight.",
"facilityID": 1,
"typeID": 2,
"fileSize": None,
"fileCount": None,
"typeID": 3,
"fileSize": 0,
"fileCount": 0,
},
id="not like",
),
pytest.param(
"lt",
"Title for DataGateway API Testing (DB) 0",
{
"doi": "0-449-78690-0",
"doi": "0-417-77631-4",
"endDate": "2000-07-09 00:00:00",
"name": "INVESTIGATION 1",
"releaseDate": "2000-07-05 00:00:00",
"startDate": "2000-04-03 00:00:00",
"summary": "Season identify professor happen third."
" Beat professional blue clear style have. "
"Light final summer.",
"title": "Including spend increase ability music"
" skill former. Agreement director concern once "
"technology sometimes someone staff."
"\nSuccess pull bar. Laugh senior example.",
"summary": "Throw hope parent. Receive entire soon. "
"War top air agent must voice high describe.\n"
"Month shake voice. "
"Do discuss despite least face again study. "
"Two beyond picture rich fast sea time.",
"title": "Analysis reflect work or hour color maybe."
"\nMuch team discussion message weight.",
"facilityID": 1,
"typeID": 2,
"fileSize": None,
"fileCount": None,
"typeID": 3,
"fileSize": 0,
"fileCount": 0,
},
id="less than",
),
pytest.param(
"lte",
"Title for DataGateway API Testing (DB) 0",
{
"doi": "0-449-78690-0",
"doi": "0-417-77631-4",
"endDate": "2000-07-09 00:00:00",
"name": "INVESTIGATION 1",
"releaseDate": "2000-07-05 00:00:00",
"startDate": "2000-04-03 00:00:00",
"summary": "Season identify professor happen third."
" Beat professional blue clear style have. "
"Light final summer.",
"title": "Including spend increase ability music"
" skill former. Agreement director concern once "
"technology sometimes someone staff."
"\nSuccess pull bar. Laugh senior example.",
"summary": "Throw hope parent. Receive entire soon. "
"War top air agent must voice high describe.\n"
"Month shake voice. "
"Do discuss despite least face again study. "
"Two beyond picture rich fast sea time.",
"title": "Analysis reflect work or hour color maybe."
"\nMuch team discussion message weight.",
"facilityID": 1,
"typeID": 2,
"fileSize": None,
"fileCount": None,
"typeID": 3,
"fileSize": 0,
"fileCount": 0,
},
id="less than or equal",
),
pytest.param(
"gt",
"Title for DataGateway API Testing (DB) 0",
{
"doi": "0-9634101-9-9",
"endDate": "2001-05-04 00:00:00",
"name": "INVESTIGATION 4",
"releaseDate": "2001-09-26 00:00:00",
"startDate": "2001-02-02 00:00:00",
"summary": "Fast purpose right power away health south."
"\nQuality serve food buy responsibility go much."
" Situation raise manage positive help daughter."
" Yes player reveal.",
"title": "Would easy whom fact again return choose."
" Site suffer should spring painting glass."
"\nThem name charge strategy machine level."
" Establish better opportunity.",
"doi": "0-9996467-0-2",
"endDate": "2007-07-09 00:00:00",
"name": "INVESTIGATION 29",
"releaseDate": "2007-07-05 00:00:00",
"startDate": "2007-04-03 00:00:00",
"summary": "City plant especially ever eight. Wife street under. Life character drive down. Bag sport benefit also price.\nIncrease spring box successful travel.",
"title": "Usually water six learn bring white development political. Meeting those voice hand.",
"facilityID": 1,
"typeID": 3,
"fileSize": None,
"fileCount": None,
"typeID": 1,
"fileSize": 0,
"fileCount": 0,
},
id="greater than",
),
pytest.param(
"gte",
"Title for DataGateway API Testing (DB) 0",
{
"doi": "0-9634101-9-9",
"endDate": "2001-05-04 00:00:00",
"name": "INVESTIGATION 4",
"releaseDate": "2001-09-26 00:00:00",
"startDate": "2001-02-02 00:00:00",
"summary": "Fast purpose right power away health south."
"\nQuality serve food buy responsibility go much."
" Situation raise manage positive help daughter."
" Yes player reveal.",
"title": "Would easy whom fact again return choose."
" Site suffer should spring painting glass."
"\nThem name charge strategy machine level."
" Establish better opportunity.",
"doi": "0-9996467-0-2",
"endDate": "2007-07-09 00:00:00",
"name": "INVESTIGATION 29",
"releaseDate": "2007-07-05 00:00:00",
"startDate": "2007-04-03 00:00:00",
"summary": "City plant especially ever eight. Wife street under. Life character drive down. Bag sport benefit also price.\nIncrease spring box successful travel.",
"title": "Usually water six learn bring white development political. Meeting those voice hand.",
"facilityID": 1,
"typeID": 3,
"fileSize": None,
"fileCount": None,
"typeID": 1,
"fileSize": 0,
"fileCount": 0,
},
id="greater than or equal",
),
Expand Down
20 changes: 13 additions & 7 deletions test/datagateway_api/icat/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def prepare_icat_data_for_assertion(data, remove_id=False, remove_visit_id=False

for attr in meta_attributes:
entity.pop(attr)
for k, v in entity.items():
if isinstance(v, dict):
entity[k] = pop_nested_attributes(v, meta_attributes)

for attr in entity.keys():
if isinstance(entity[attr], datetime):
Expand All @@ -46,6 +49,11 @@ def prepare_icat_data_for_assertion(data, remove_id=False, remove_visit_id=False
return assertable_data


def pop_nested_attributes(nested_entity, meta_attributes):
for attr in meta_attributes:
nested_entity.pop(attr)


class TestICATQuery:
@pytest.mark.parametrize(
"input_conditions, input_aggregate, input_includes, expected_conditions,"
Expand Down Expand Up @@ -169,14 +177,12 @@ def test_invalid_query_creation(self, icat_client):
"fileCount": 3,
"fileSize": 1073741824,
"facility": {
"createId": "user",
"createTime": "2002-11-27 06:20:36+00:00",
"createId": "simple/root",
"daysUntilRelease": 10,
"description": "Lorem ipsum light source",
"fullName": None,
"id": 1,
"modId": "user",
"modTime": "2005-04-30 19:41:49+00:00",
"modId": "simple/root",
"name": "LILS",
"url": None,
},
Expand Down Expand Up @@ -286,7 +292,7 @@ def test_invalid_query_creation(self, icat_client):
],
)
@pytest.mark.usefixtures("single_investigation_test_data")
def test_valid_query_exeuction(
def test_valid_query_execution(
self,
icat_client,
query_conditions,
Expand Down Expand Up @@ -318,7 +324,7 @@ def test_valid_query_exeuction(
query_data, remove_id=True, remove_visit_id=True,
)

assert query_data == expected_query_result
assert query_data[0] == expected_query_result[0]

def test_invalid_query_execution(self, icat_client):
test_query = ICATQuery(icat_client, "Investigation")
Expand All @@ -343,7 +349,7 @@ def test_json_format_execution_output(

query_output_json = prepare_icat_data_for_assertion(query_data)

assert query_output_json == single_investigation_test_data
assert query_output_json[0] == single_investigation_test_data[0]

def test_valid_get_distinct_attributes(self, icat_client):
test_query = ICATQuery(icat_client, "Investigation")
Expand Down

0 comments on commit 21b0233

Please sign in to comment.