From 9cd737994a6a904a45a3e95ed6844c5c716baf41 Mon Sep 17 00:00:00 2001 From: vpf26432 Date: Thu, 16 Mar 2023 13:44:20 +0000 Subject: [PATCH] adding some tests to work against a scicat v4 backend. --- pyscicat/tests/tests_local.py | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 pyscicat/tests/tests_local.py diff --git a/pyscicat/tests/tests_local.py b/pyscicat/tests/tests_local.py new file mode 100644 index 0000000..bef285b --- /dev/null +++ b/pyscicat/tests/tests_local.py @@ -0,0 +1,78 @@ +import unittest +from ..client import ScicatClient +from ..model import RawDataset +from datetime import datetime +import os + +class TestClientLocally(unittest.TestCase): + """ + These tests do not use mocks and are designed to connect to a v4 service for Scicat backend. You can run this easily + in docker-compose following the repo https://github.com/SciCatProject/scicatlive. You will also need to use one of + the default user accounts or add your own. + + You will need to set environmental variables for + BASE_URL - the url of your scicat service e.g. http://localhost:3000/api/v3 + SCICAT_USER - the name of your scicat user. + SCICAT_PASSWORD - the password for your scicat user. + """ + + def test_client(self): + sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], password="SCICAT_PASSWORD") + self.assertIsInstance(sci_clie, ScicatClient) + print(sci_clie._token) + + + + def test_upload_dataset(self): + sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], password="SCICAT_PASSWORD") + + payload = RawDataset( + datasetName="a guide book", + path="/foo/bar", + size=42, + owner=os.environ["SCICAT_USER"], + ownerGroup="Magrateheans", + contactEmail="slartibartfast@magrathea.org", + creationLocation="magrathea", + creationTime= datetime.isoformat(datetime.now()), + instrumentId="earth", + proposalId="deepthought", + dataFormat="planet", + principalInvestigator="A. Mouse", + sourceFolder="/foo/bar", + scientificMetadata={"a": "field"}, + sampleId="gargleblaster", + accessGroups=[] + ) + + sci_clie.upload_new_dataset(payload) + + + def test_replace_dataset(self): + sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], password="SCICAT_PASSWORD") + + pid="PID.SAMPLE.PREFIX48a8f164-166a-4557-bafc-5a7362e39fe7" + payload= RawDataset( + size=142, + owner="slartibartfast", + ownerGroup="Magrateheans", + contactEmail="slartibartfast@magrathea.org", + creationLocation="magrathea", + creationTime=datetime.isoformat(datetime.now()), + instrumentId="earth", + proposalId="deepthought", + dataFormat="planet", + principalInvestigator="A. Mouse", + sourceFolder="/foo/bar", + scientificMetadata={"a": "field"}, + sampleId="gargleblaster", + accessGroups=["Vogons"] + ) + sci_clie.update_dataset(payload, pid) + + + def test_get_dataset(self): + sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], password="SCICAT_PASSWORD") + datasets = sci_clie.get_datasets({"owner":os.environ["SCICAT_USER"]}) + with self.subTest(dataset=datasets): + self.assertEqual(dataset["owner"], os.environ["SCICAT_USER"])