-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1e38eae
commit a17fb9a
Showing
6 changed files
with
311 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
|
||
|
||
class TestSearchAPICountDatasetFilesEndpoint: | ||
@pytest.mark.parametrize( | ||
"pid, request_filter, expected_json", | ||
[ | ||
pytest.param( | ||
"0-8401-1070-7", | ||
"{}", | ||
{"count": 56}, | ||
id="Basic /datasets/{pid}/files/count request", | ||
), | ||
], | ||
) | ||
def test_valid_count_dataset_files_endpoint( | ||
self, flask_test_app_search_api, pid, request_filter, expected_json, | ||
): | ||
test_response = flask_test_app_search_api.get( | ||
f"{Config.config.search_api.extension}/datasets/{pid}/files/count" | ||
f"?filter={request_filter}", | ||
) | ||
|
||
print(test_response) | ||
print(test_response.json) | ||
|
||
assert test_response.status_code == 200 | ||
assert test_response.json == expected_json | ||
|
||
def test_invalid_count_dataset_files_endpoint(self): | ||
# TODO - test for bad filter (where only) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
|
||
|
||
class TestSearchAPICountEndpoint: | ||
@pytest.mark.parametrize( | ||
"endpoint_name, request_filter, expected_json", | ||
[ | ||
pytest.param( | ||
"datasets", "{}", {"count": 479}, id="Basic /datasets/count request", | ||
), | ||
pytest.param( | ||
"documents", "{}", {"count": 239}, id="Basic /documents/count request", | ||
), | ||
pytest.param( | ||
"instruments", | ||
"{}", | ||
{"count": 14}, | ||
id="Basic /instruments/count request", | ||
), | ||
], | ||
) | ||
def test_valid_count_endpoint( | ||
self, flask_test_app_search_api, endpoint_name, request_filter, expected_json, | ||
): | ||
test_response = flask_test_app_search_api.get( | ||
f"{Config.config.search_api.extension}/{endpoint_name}/count?filter=" | ||
f"{request_filter}", | ||
) | ||
|
||
print(test_response) | ||
print(test_response.json) | ||
|
||
assert test_response.status_code == 200 | ||
assert test_response.json == expected_json | ||
|
||
def test_invalid_count_endpoint(self): | ||
# TODO - test for bad filter (where only) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
|
||
|
||
class TestSearchAPIGetDatasetFilesEndpoint: | ||
@pytest.mark.parametrize( | ||
"pid, request_filter, expected_json", | ||
[ | ||
pytest.param( | ||
"0-8401-1070-7", | ||
'{"limit": 2}', | ||
[ | ||
{ | ||
"id": 1, | ||
"name": "Datafile 1", | ||
"path": "/hit/consumer/red.jpg", | ||
"size": 199643799, | ||
"dataset": None, | ||
}, | ||
{ | ||
"id": 10060, | ||
"name": "Datafile 10060", | ||
"path": "/the/current/next.jpg", | ||
"size": 124327237, | ||
"dataset": None, | ||
}, | ||
], | ||
id="Basic /datasets/{pid}/files request", | ||
), | ||
], | ||
) | ||
def test_valid_get_dataset_files_endpoint( | ||
self, flask_test_app_search_api, pid, request_filter, expected_json, | ||
): | ||
test_response = flask_test_app_search_api.get( | ||
f"{Config.config.search_api.extension}/datasets/{pid}/files" | ||
f"?filter={request_filter}", | ||
) | ||
|
||
print(test_response) | ||
print(test_response.json) | ||
|
||
assert test_response.status_code == 200 | ||
assert test_response.json == expected_json | ||
|
||
def test_invalid_get_dataset_files_endpoint(self): | ||
# TODO - test bad filter and bad pid | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
|
||
|
||
class TestSearchAPIGetByPIDEndpoint: | ||
@pytest.mark.parametrize( | ||
"endpoint_name, pid, request_filter, expected_json", | ||
[ | ||
pytest.param( | ||
"datasets", | ||
"0-8401-1070-7", | ||
"{}", | ||
{ | ||
"description": "Beat professional blue clear style have. Light" | ||
" final summer. Or hour color maybe word side much team.\nMessage" | ||
" weight official learn especially nature. Himself tax west.", | ||
"modTime": "2006-08-24 01:28:06+00:00", | ||
"modId": "user", | ||
"startDate": "2000-10-13 00:00:00+00:00", | ||
"endDate": "2000-02-10 00:00:00+00:00", | ||
"createId": "user", | ||
"complete": True, | ||
"id": 2, | ||
"name": "DATASET 2", | ||
"doi": "0-8401-1070-7", | ||
"createTime": "2013-04-01 10:56:52+00:00", | ||
"location": "/subject/break.jpeg", | ||
}, | ||
id="Basic /datasets/{pid} request", | ||
), | ||
pytest.param( | ||
"documents", | ||
"0-449-78690-0", | ||
"{}", | ||
{ | ||
"visitId": "42", | ||
"modId": "user", | ||
"name": "INVESTIGATION 1", | ||
"createId": "user", | ||
"createTime": "2002-11-27 06:20:36+00:00", | ||
"doi": "0-449-78690-0", | ||
"id": 1, | ||
"summary": "Season identify professor happen third. Beat" | ||
" professional blue clear style have. Light final summer.", | ||
"endDate": "2000-07-09 00:00:00+00:00", | ||
"modTime": "2005-04-30 19:41:49+00:00", | ||
"releaseDate": "2000-07-05 00:00:00+00:00", | ||
"startDate": "2000-04-03 00:00:00+00:00", | ||
"title": "Including spend increase ability music skill former." | ||
" Agreement director concern once technology sometimes someone" | ||
" staff.\nSuccess pull bar. Laugh senior example.", | ||
}, | ||
id="Basic /documents/{pid} request", | ||
), | ||
pytest.param( | ||
"instruments", | ||
"2", | ||
"{}", | ||
{ | ||
"description": "Former outside source play nearly Congress before" | ||
" necessary. Allow want audience test laugh. Economic body person" | ||
" general attorney. Effort weight prevent possible.", | ||
"modId": "user", | ||
"createTime": "2019-02-19 05:57:03+00:00", | ||
"pid": None, | ||
"createId": "user", | ||
"type": "2", | ||
"name": "INSTRUMENT 2", | ||
"modTime": "2019-01-29 23:33:20+00:00", | ||
"id": 2, | ||
"fullName": "With piece reason late model. House office fly." | ||
" International scene call deep answer audience baby true.\n" | ||
"Indicate education across these. Opportunity design too.", | ||
"url": "https://moore.org/", | ||
}, | ||
id="Basic /instruments/{pid} request", | ||
), | ||
], | ||
) | ||
def test_valid_get_by_pid_endpoint( | ||
self, | ||
flask_test_app_search_api, | ||
endpoint_name, | ||
pid, | ||
request_filter, | ||
expected_json, | ||
): | ||
test_response = flask_test_app_search_api.get( | ||
f"{Config.config.search_api.extension}/{endpoint_name}/{pid}?filter=" | ||
f"{request_filter}", | ||
) | ||
|
||
assert test_response.status_code == 200 | ||
assert test_response.json == expected_json | ||
|
||
def test_invalid_get_by_pid_endpoint(self): | ||
# TODO - test for bad filter and bad/unknown PID | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
|
||
from datagateway_api.src.common.config import Config | ||
|
||
|
||
class TestSearchAPISearchEndpoint: | ||
@pytest.mark.parametrize( | ||
"endpoint_name, request_filter, expected_json", | ||
[ | ||
pytest.param( | ||
"datasets", | ||
'{"limit": 2}', | ||
[ | ||
{ | ||
"pid": "0-449-78690-0", | ||
"title": "DATASET 1", | ||
"creationDate": "2002-11-27T06:20:36+00:00", | ||
"size": None, | ||
"documents": [], | ||
"techniques": [], | ||
"instrument": None, | ||
"files": [], | ||
"parameters": [], | ||
"samples": [], | ||
}, | ||
{ | ||
"pid": "0-8401-1070-7", | ||
"title": "DATASET 2", | ||
"creationDate": "2013-04-01T10:56:52+00:00", | ||
"size": None, | ||
"documents": [], | ||
"techniques": [], | ||
"instrument": None, | ||
"files": [], | ||
"parameters": [], | ||
"samples": [], | ||
}, | ||
], | ||
id="Basic /datasets request", | ||
), | ||
pytest.param( | ||
"documents", '{"limit": 2}', [{}, {}], id="Basic /documents request", | ||
), | ||
# TODO - test data will need changing once facility has been fixed | ||
pytest.param( | ||
"instruments", | ||
'{"limit": 2}', | ||
[ | ||
{"pid": 1, "name": "INSTRUMENT 1", "datasets": None}, | ||
{"pid": 2, "name": "INSTRUMENT 2", "datasets": None}, | ||
], | ||
id="Basic /instruments request", | ||
), | ||
], | ||
) | ||
def test_valid_search_endpoint( | ||
self, flask_test_app_search_api, endpoint_name, request_filter, expected_json, | ||
): | ||
print(f"RF: {request_filter}") | ||
test_response = flask_test_app_search_api.get( | ||
f"{Config.config.search_api.extension}/{endpoint_name}?filter=" | ||
f"{request_filter}", | ||
) | ||
print(test_response) | ||
print(test_response.json) | ||
|
||
assert test_response.json == expected_json | ||
|
||
def test_invalid_search_endpoint(self): | ||
# TODO - test for bad filters | ||
pass |