Skip to content

Commit

Permalink
#150: Rename valid ICAT creds header
Browse files Browse the repository at this point in the history
- This has been renamed due to the addition of a valid credentials header for the DB backend
  • Loading branch information
MRichards99 committed Dec 3, 2020
1 parent a07f0db commit 89d58d6
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 83 deletions.
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def icat_client():


@pytest.fixture()
def valid_credentials_header(icat_client):
def valid_icat_credentials_header(icat_client):
return {"Authorization": f"Bearer {icat_client.sessionId}"}


Expand Down
8 changes: 4 additions & 4 deletions test/icat/endpoints/test_count_with_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
class TestCountWithFilters:
@pytest.mark.usefixtures("single_investigation_test_data")
def test_valid_count_with_filters(
self, flask_test_app_icat, valid_credentials_header,
self, flask_test_app_icat, valid_icat_credentials_header,
):
test_response = flask_test_app_icat.get(
'/investigations/count?where={"title": {"like": "Test data for the Python'
' ICAT Backend on DataGateway API"}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)

assert test_response.json == 1

def test_valid_no_results_count_with_filters(
self, flask_test_app_icat, valid_credentials_header,
self, flask_test_app_icat, valid_icat_credentials_header,
):
test_response = flask_test_app_icat.get(
'/investigations/count?where={"title": {"like": "This filter should cause a'
'404 for testing purposes..."}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)

assert test_response.json == 0
26 changes: 16 additions & 10 deletions test/icat/endpoints/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


class TestCreateData:
def test_valid_create_data(self, flask_test_app_icat, valid_credentials_header):
def test_valid_create_data(
self, flask_test_app_icat, valid_icat_credentials_header
):
create_investigations_json = [
{
"name": "Test Data for API Testing, Data Creation 1",
Expand Down Expand Up @@ -32,7 +34,7 @@ def test_valid_create_data(self, flask_test_app_icat, valid_credentials_header):

test_response = flask_test_app_icat.post(
"/investigations",
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
json=create_investigations_json,
)

Expand All @@ -53,11 +55,12 @@ def test_valid_create_data(self, flask_test_app_icat, valid_credentials_header):
# Delete the entities created by this test
for investigation_id in test_data_ids:
flask_test_app_icat.delete(
f"/investigations/{investigation_id}", headers=valid_credentials_header,
f"/investigations/{investigation_id}",
headers=valid_icat_credentials_header,
)

def test_valid_boundary_create_data(
self, flask_test_app_icat, valid_credentials_header,
self, flask_test_app_icat, valid_icat_credentials_header,
):
"""Create a single investigation, as opposed to multiple"""

Expand All @@ -76,7 +79,7 @@ def test_valid_boundary_create_data(

test_response = flask_test_app_icat.post(
"/investigations",
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
json=create_investigation_json,
)

Expand All @@ -91,10 +94,13 @@ def test_valid_boundary_create_data(
assert [create_investigation_json] == response_json

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

def test_invalid_create_data(self, flask_test_app_icat, valid_credentials_header):
def test_invalid_create_data(
self, flask_test_app_icat, valid_icat_credentials_header
):
"""An investigation requires a minimum of: name, visitId, facility, type"""

invalid_request_body = {
Expand All @@ -103,7 +109,7 @@ def test_invalid_create_data(self, flask_test_app_icat, valid_credentials_header

test_response = flask_test_app_icat.post(
"/investigations",
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
json=invalid_request_body,
)

Expand All @@ -112,7 +118,7 @@ def test_invalid_create_data(self, flask_test_app_icat, valid_credentials_header
def test_invalid_existing_data_create(
self,
flask_test_app_icat,
valid_credentials_header,
valid_icat_credentials_header,
single_investigation_test_data,
):
"""This test targets raising ICATObjectExistsError, causing a 400"""
Expand All @@ -129,7 +135,7 @@ def test_invalid_existing_data_create(

test_response = flask_test_app_icat.post(
"/investigations",
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
json=existing_object_json,
)

Expand Down
12 changes: 7 additions & 5 deletions test/icat/endpoints/test_delete_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@ class TestDeleteByID:
def test_valid_delete_with_id(
self,
flask_test_app_icat,
valid_credentials_header,
valid_icat_credentials_header,
single_investigation_test_data,
):
test_response = flask_test_app_icat.delete(
f'/investigations/{single_investigation_test_data[0]["id"]}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)

assert test_response.status_code == 204

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

final_investigation_result = flask_test_app_icat.get(
'/investigations/findone?order="id DESC"', headers=valid_credentials_header,
'/investigations/findone?order="id DESC"',
headers=valid_icat_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_icat.delete(
f"/investigations/{test_data_id + 100}", headers=valid_credentials_header,
f"/investigations/{test_data_id + 100}",
headers=valid_icat_credentials_header,
)

assert test_response.status_code == 404
8 changes: 4 additions & 4 deletions test/icat/endpoints/test_findone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ class TestFindone:
def test_valid_findone_with_filters(
self,
flask_test_app_icat,
valid_credentials_header,
valid_icat_credentials_header,
single_investigation_test_data,
):
test_response = flask_test_app_icat.get(
'/investigations/findone?where={"title": {"like": "Test data for the Python'
' ICAT Backend on DataGateway API"}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)
response_json = prepare_icat_data_for_assertion([test_response.json])

assert response_json == single_investigation_test_data

def test_valid_no_results_findone_with_filters(
self, flask_test_app_icat, valid_credentials_header,
self, flask_test_app_icat, valid_icat_credentials_header,
):
test_response = flask_test_app_icat.get(
'/investigations/findone?where={"title": {"eq": "This filter should cause a'
'404 for testing purposes..."}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)

assert test_response.status_code == 404
16 changes: 10 additions & 6 deletions test/icat/endpoints/test_get_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,41 @@ class TestGetByID:
def test_valid_get_with_id(
self,
flask_test_app_icat,
valid_credentials_header,
valid_icat_credentials_header,
single_investigation_test_data,
):
# Need to identify the ID given to the test data
investigation_data = flask_test_app_icat.get(
'/investigations?where={"title": {"like": "Test data for the Python ICAT'
' Backend on DataGateway API"}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)
test_data_id = investigation_data.json[0]["id"]

test_response = flask_test_app_icat.get(
f"/investigations/{test_data_id}", headers=valid_credentials_header,
f"/investigations/{test_data_id}", headers=valid_icat_credentials_header,
)
# Get with ID gives a dictionary response (only ever one result from that kind
# of request), so list around json is required for the call
response_json = prepare_icat_data_for_assertion([test_response.json])

assert response_json == single_investigation_test_data

def test_invalid_get_with_id(self, flask_test_app_icat, valid_credentials_header):
def test_invalid_get_with_id(
self, flask_test_app_icat, valid_icat_credentials_header
):
"""Request with a non-existent ID"""

final_investigation_result = flask_test_app_icat.get(
'/investigations/findone?order="id DESC"', headers=valid_credentials_header,
'/investigations/findone?order="id DESC"',
headers=valid_icat_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_icat.get(
f"/investigations/{test_data_id + 100}", headers=valid_credentials_header,
f"/investigations/{test_data_id + 100}",
headers=valid_icat_credentials_header,
)

assert test_response.status_code == 404
16 changes: 8 additions & 8 deletions test/icat/endpoints/test_get_with_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ class TestGetWithFilters:
def test_valid_get_with_filters(
self,
flask_test_app_icat,
valid_credentials_header,
valid_icat_credentials_header,
single_investigation_test_data,
):
test_response = flask_test_app_icat.get(
'/investigations?where={"title": {"like": "Test data for the Python ICAT'
' Backend on DataGateway API"}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)
response_json = prepare_icat_data_for_assertion(test_response.json)

assert response_json == single_investigation_test_data

def test_valid_no_results_get_with_filters(
self, flask_test_app_icat, valid_credentials_header,
self, flask_test_app_icat, valid_icat_credentials_header,
):
test_response = flask_test_app_icat.get(
'/investigations?where={"title": {"eq": "This filter should cause a 404 for'
'testing purposes..."}}',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)

assert test_response.status_code == 404

@pytest.mark.usefixtures("multiple_investigation_test_data")
def test_valid_get_with_filters_distinct(
self, flask_test_app_icat, valid_credentials_header,
self, flask_test_app_icat, valid_icat_credentials_header,
):
test_response = flask_test_app_icat.get(
'/investigations?where={"title": {"like": "Test data for the Python ICAT'
' Backend on DataGateway API"}}&distinct="title"',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)

expected = [
Expand All @@ -53,7 +53,7 @@ def test_valid_get_with_filters_distinct(
def test_limit_skip_merge_get_with_filters(
self,
flask_test_app_icat,
valid_credentials_header,
valid_icat_credentials_header,
multiple_investigation_test_data,
):
skip_value = 1
Expand All @@ -63,7 +63,7 @@ def test_limit_skip_merge_get_with_filters(
'/investigations?where={"title": {"like": "Test data for the Python ICAT'
' Backend on DataGateway API"}}'
f'&skip={skip_value}&limit={limit_value}&order="id ASC"',
headers=valid_credentials_header,
headers=valid_icat_credentials_header,
)
response_json = prepare_icat_data_for_assertion(test_response.json)

Expand Down
Loading

0 comments on commit 89d58d6

Please sign in to comment.