Skip to content

Commit

Permalink
#150: Add valid tests for table endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 30, 2020
1 parent 9ed2694 commit 5910404
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 8 deletions.
39 changes: 39 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,42 @@ def multiple_investigation_test_data(icat_client):
def flask_test_app():
app.config["TESTING"] = True
return app.test_client()


@pytest.fixture()
def isis_specific_endpoint_data(icat_client):
facility_cycle = icat_client.new("facilityCycle")
facility_cycle.name = "Test cycle for DataGateway API testing"
facility_cycle.startDate = datetime(
year=2020, month=1, day=1, hour=1, minute=1, second=1,
)
facility_cycle.endDate = datetime(
year=2020, month=2, day=1, hour=1, minute=1, second=1,
)
facility_cycle.facility = icat_client.get("Facility", 1)
facility_cycle.create()

investigation = create_investigation_test_data(icat_client)
investigation_dict = prepare_icat_data_for_assertion([investigation])

instrument = icat_client.new("instrument")
instrument.name = "Test Instrument for DataGateway API Endpoint Testing"
instrument.facility = icat_client.get("Facility", 1)
instrument.create()

investigation_instrument = icat_client.new("investigationInstrument")
investigation_instrument.investigation = investigation
investigation_instrument.instrument = instrument
investigation_instrument.create()

facility_cycle_dict = prepare_icat_data_for_assertion([facility_cycle])

yield (instrument.id, facility_cycle_dict, facility_cycle.id, investigation_dict)

try:
# investigation_instrument removed when deleting the objects its related objects
icat_client.delete(facility_cycle)
icat_client.delete(investigation)
icat_client.delete(instrument)
except ICATNoObjectError as e:
print(e)
53 changes: 45 additions & 8 deletions test/icat/endpoints/test_table_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
from test.icat.test_query import prepare_icat_data_for_assertion


class TestTableEndpoints:
"""
This class tests the endpoints defined in table_endpoints.py, commonly referred to
as the ISIS specific endpoints
"""

def test_valid_get_facility_cycles_with_filters(self):
pass
def test_valid_get_facility_cycles_with_filters(
self, flask_test_app, valid_credentials_header, isis_specific_endpoint_data,
):
test_response = flask_test_app.get(
f"/instruments/{isis_specific_endpoint_data[0]}/facilitycycles",
headers=valid_credentials_header,
)

response_json = prepare_icat_data_for_assertion(test_response.json)

assert response_json == isis_specific_endpoint_data[1]

def test_invalid_get_facility_cycles_with_filters(
self, flask_test_app, valid_credentials_header,
Expand All @@ -22,8 +34,15 @@ def test_invalid_get_facility_cycles_with_filters(

assert test_response.status_code == 404

def test_valid_get_facility_cycles_count_with_filters(self):
pass
def test_valid_get_facility_cycles_count_with_filters(
self, flask_test_app, valid_credentials_header, isis_specific_endpoint_data,
):
test_response = flask_test_app.get(
f"/instruments/{isis_specific_endpoint_data[0]}/facilitycycles/count",
headers=valid_credentials_header,
)

assert test_response.json == 1

def test_invalid_get_facility_cycles_count_with_filters(
self, flask_test_app, valid_credentials_header,
Expand All @@ -40,8 +59,18 @@ def test_invalid_get_facility_cycles_count_with_filters(

assert test_response.json == 0

def test_valid_get_investigations_with_filters(self):
pass
def test_valid_get_investigations_with_filters(
self, flask_test_app, valid_credentials_header, isis_specific_endpoint_data,
):
test_response = flask_test_app.get(
f"/instruments/{isis_specific_endpoint_data[0]}/facilitycycles/"
f"{isis_specific_endpoint_data[2]}/investigations",
headers=valid_credentials_header,
)

response_json = prepare_icat_data_for_assertion(test_response.json)

assert response_json == isis_specific_endpoint_data[3]

def test_invalid_get_investigations_with_filters(
self, flask_test_app, valid_credentials_header,
Expand All @@ -63,8 +92,16 @@ def test_invalid_get_investigations_with_filters(

assert test_response.status_code == 404

def test_valid_get_investigations_count_with_filters(self):
pass
def test_valid_get_investigations_count_with_filters(
self, flask_test_app, valid_credentials_header, isis_specific_endpoint_data,
):
test_response = flask_test_app.get(
f"/instruments/{isis_specific_endpoint_data[0]}/facilitycycles/"
f"{isis_specific_endpoint_data[2]}/investigations/count",
headers=valid_credentials_header,
)

assert test_response.json == 1

def test_invalid_get_investigations_count_with_filters(
self, flask_test_app, valid_credentials_header,
Expand Down

0 comments on commit 5910404

Please sign in to comment.