Skip to content

Commit

Permalink
#150: Add tests for DELETE endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 25, 2020
1 parent a2fd644 commit 03c7c8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
7 changes: 6 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from icat.client import Client
from icat.entity import Entity
from icat.exception import ICATNoObjectError
from icat.query import Query
import pytest

Expand Down Expand Up @@ -48,7 +49,11 @@ def single_investigation_test_data(icat_client):
yield [investigation_dict]

# Remove data from ICAT
icat_client.delete(investigation)
try:
icat_client.delete(investigation)
except ICATNoObjectError as e:
# This should occur on DELETE endpoints, normal behaviour for those tests
print(e)


@pytest.fixture()
Expand Down
33 changes: 25 additions & 8 deletions test/icat/test_standard_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,8 @@ def test_valid_get_with_id(
assert response_json == single_investigation_test_data

def test_invalid_get_with_id(self, flask_test_app, valid_credentials_header):
# Do a get one with filters (order desc), extract the id of that, add 5 and do a
# request for that
# Need to identify the ID given to the test data
"""Request with a non-existent ID"""

final_investigation_result = flask_test_app.get(
'/investigations/findone?order="id DESC"', headers=valid_credentials_header,
)
Expand All @@ -290,12 +289,30 @@ def test_invalid_get_with_id(self, flask_test_app, valid_credentials_header):

assert test_response.status_code == 404

def test_valid_delete_with_id(self):
pass
def test_valid_delete_with_id(
self, flask_test_app, valid_credentials_header, single_investigation_test_data,
):
test_response = flask_test_app.delete(
f'/investigations/{single_investigation_test_data[0]["id"]}',
headers=valid_credentials_header,
)

def test_invalid_delete_with_id(self):
# like invalid get, but try to delete
pass
assert test_response.status_code == 204

def test_invalid_delete_with_id(self, flask_test_app, valid_credentials_header):
"""Request with a non-existent ID"""

final_investigation_result = flask_test_app.get(
'/investigations/findone?order="id DESC"', headers=valid_credentials_header,
)
test_data_id = final_investigation_result.json["id"]

# Adding 100 onto the ID to the most recent result should ensure a 404
test_response = flask_test_app.delete(
f"/investigations/{test_data_id + 100}", headers=valid_credentials_header,
)

assert test_response.status_code == 404

def test_valid_update_with_id(
self, flask_test_app, valid_credentials_header, single_investigation_test_data,
Expand Down

0 comments on commit 03c7c8f

Please sign in to comment.