Skip to content

Commit

Permalink
#150: Add test to create single investigation
Browse files Browse the repository at this point in the history
- Also remove assertion for data deletion in these tests - I've changed the name of the data used in these tests so they don't have an impact on later tests, so there's no need to highlight any failures in data deletion
  • Loading branch information
MRichards99 committed Nov 25, 2020
1 parent e1f07b7 commit b16098e
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions test/icat/test_standard_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_limit_skip_merge_get_with_filters(
assert response_json == filtered_investigation_data

def test_valid_create_data(self, flask_test_app, valid_credentials_header):
create_investigation_json = [
create_investigations_json = [
{
"name": "Test Data for API Testing, Data Creation 1",
"title": "Test data for the Python ICAT Backend on DataGateway API",
Expand Down Expand Up @@ -133,12 +133,12 @@ def test_valid_create_data(self, flask_test_app, valid_credentials_header):
test_response = flask_test_app.post(
"/investigations",
headers=valid_credentials_header,
json=create_investigation_json,
json=create_investigations_json,
)

test_data_ids = []
for investigation_request, investigation_response in zip(
create_investigation_json, test_response.json,
create_investigations_json, test_response.json,
):
investigation_request.pop("facility")
investigation_request.pop("type")
Expand All @@ -148,22 +148,49 @@ def test_valid_create_data(self, flask_test_app, valid_credentials_header):
test_response.json, remove_id=True,
)

assert create_investigation_json == response_json
assert create_investigations_json == response_json

# Delete the entities created by this test
for investigation_id in test_data_ids:
delete_test_data = flask_test_app.delete(
flask_test_app.delete(
f"/investigations/{investigation_id}", headers=valid_credentials_header,
)

# This test isn't testing DELETE requests but this will easily signpost if
# there's an issue here (which will inevitably impact tests in the same
# session)
assert delete_test_data.status_code == 204
def test_valid_boundary_create_data(self, flask_test_app, valid_credentials_header):
"""Create a single investigation, as opposed to multiple"""

create_investigation_json = {
"name": "Test Data for API Testing, Data Creation 0",
"title": "Test data for the Python ICAT Backend on the API",
"summary": "Test data for DataGateway API testing",
"releaseDate": "2020-03-03 08:00:08",
"startDate": "2020-02-02 09:00:09",
"endDate": "2020-02-03 10:00:10",
"visitId": "Data Creation Visit",
"doi": "DataGateway API Test DOI",
"facility": 1,
"type": 1,
}

def test_invalid_create_data(self):
# Invalid request body
pass
test_response = flask_test_app.post(
"/investigations",
headers=valid_credentials_header,
json=create_investigation_json,
)

create_investigation_json.pop("facility")
create_investigation_json.pop("type")
created_test_data_id = test_response.json[0]["id"]

response_json = prepare_icat_data_for_assertion(
test_response.json, remove_id=True,
)

assert [create_investigation_json] == response_json

flask_test_app.delete(
f"/investigations/{created_test_data_id}", headers=valid_credentials_header,
)

def test_invalid_create_data(self, flask_test_app, valid_credentials_header):
"""An investigation requires a minimum of: name, visitId, facility, type"""
Expand Down

0 comments on commit b16098e

Please sign in to comment.