Skip to content

Commit

Permalink
#150: Add fixture to inject multiple investigation results
Browse files Browse the repository at this point in the history
- Add test to utilise said fixture
- Add invalid test
  • Loading branch information
MRichards99 committed Nov 24, 2020
1 parent 9e0c56b commit 9c3ece5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
30 changes: 30 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,36 @@ def single_investigation_test_data(icat_client):
icat_client.delete(investigation)


@pytest.fixture()
def multiple_investigation_test_data(icat_client):
investigation_test_data = []
investigation_dicts = []
meta_attributes = Entity.MetaAttr

for i in range(5):
investigation = icat_client.new("investigation")
investigation.name = f"Test Data for DataGateway API Testing {i}"
investigation.title = (
f"Test data for the Python ICAT Backend on DataGateway API {i}"
)
investigation.visitId = str(uuid.uuid1())
investigation.facility = icat_client.get("Facility", 1)
investigation.type = icat_client.get("InvestigationType", 1)
investigation.create()
investigation_test_data.append(investigation)
investigation_dict = investigation.as_dict()

for attr in meta_attributes:
investigation_dict.pop(attr)

investigation_dicts.append(investigation_dict)

yield investigation_dicts

for entity in investigation_test_data:
icat_client.delete(entity)


@pytest.fixture()
def flask_test_app():
app.config["TESTING"] = True
Expand Down
35 changes: 33 additions & 2 deletions test/icat/test_standard_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def test_valid_get_with_filters(

assert response_json == single_investigation_test_data

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

expected = [
{
"title": f"Test data for the Python ICAT Backend on DataGateway API {i}"
for i in range(5)
},
]

for title in expected:
assert title in test_response.json

def test_invalid_get_with_filters(self):
# Invalid data?
pass
Expand Down Expand Up @@ -113,10 +133,21 @@ def test_valid_get_with_id(

assert response_json == single_investigation_test_data

def test_invalid_get_with_id(self):
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
pass
# Need to identify the ID given to the test data
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.get(
f"/investigations/{test_data_id + 100}", headers=valid_credentials_header,
)

assert test_response.status_code == 404

def test_valid_delete_with_id(self):
pass
Expand Down

0 comments on commit 9c3ece5

Please sign in to comment.