Skip to content

Commit

Permalink
#150: Add way of injecting data into ICAT for testing endpoint and I…
Browse files Browse the repository at this point in the history
…CATQuery

- This fixture also removes the data from ICAT at the end of the test
  • Loading branch information
MRichards99 committed Nov 19, 2020
1 parent 7bf1141 commit 5444bd5
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import uuid

from icat.client import Client
from icat.query import Query
import pytest

from datagateway_api.common.config import config
from test.icat.test_query import remove_meta_attributes


@pytest.fixture(scope="package")
def icat_client():
client = Client(config.get_icat_url(), checkCert=config.get_icat_check_cert())
client.login(config.get_test_mechanism(), config.get_test_user_credentials())
print(f"ID: {client.sessionId}")
return client


Expand All @@ -18,3 +20,29 @@ def icat_query(icat_client):
query = Query(icat_client, "Investigation")

return query


@pytest.fixture()
def add_single_investigation_test_data(icat_client):
# Inject data
investigation = icat_client.new("investigation")
investigation.name = "Test Data for DataGateway API Testing"
investigation.title = "Test data for the Python ICAT Backend on DataGateway API"
# UUID visit ID means uniquesness constraint should always be met
investigation.visitId = str(uuid.uuid1())
investigation.facility = icat_client.get("Facility", 1)
investigation.type = icat_client.get("InvestigationType", 1)
investigation.create()

investigation_dict = investigation.as_dict()
remove_meta_attributes(investigation_dict)

yield [investigation_dict]

# Remove data from ICAT
icat_client.delete(investigation)


@pytest.fixture()
def remove_single_investiation_result():
pass

0 comments on commit 5444bd5

Please sign in to comment.