diff --git a/test/conftest.py b/test/conftest.py index 2977e6b0..92f4f80a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -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) diff --git a/test/icat/endpoints/test_table_endpoints.py b/test/icat/endpoints/test_table_endpoints.py index 6c784244..6415d279 100644 --- a/test/icat/endpoints/test_table_endpoints.py +++ b/test/icat/endpoints/test_table_endpoints.py @@ -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, @@ -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, @@ -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, @@ -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,