From 21691adb7a9b098537bbe131d101ee567ef9d392 Mon Sep 17 00:00:00 2001 From: vpf26432 Date: Wed, 19 Apr 2023 13:52:17 +0000 Subject: [PATCH] Removing the forward / before Datasets. If this is given in the endpoint then this is treated by urllib.parse like a full path. --- pyscicat/client.py | 6 +-- .../{tests_local.py => tests_integration.py} | 49 +++++++++++-------- 2 files changed, 31 insertions(+), 24 deletions(-) rename tests/test_pyscicat/{tests_local.py => tests_integration.py} (66%) diff --git a/pyscicat/client.py b/pyscicat/client.py index dabe89d..f7ce80d 100644 --- a/pyscicat/client.py +++ b/pyscicat/client.py @@ -739,7 +739,7 @@ def datasets_get_many(self, filter_fields: Optional[dict] = None) -> Optional[di if not filter_fields: filter_fields = {} filter_fields = json.dumps(filter_fields) - endpoint = f'/Datasets/?filter={{"where":{filter_fields}}}' + endpoint = f'Datasets?filter={{"where":{filter_fields}}}' return self._call_endpoint( cmd="get", endpoint=endpoint, operation="datasets_get_many", allow_404=True ) @@ -912,7 +912,7 @@ def datasets_origdatablocks_get_one(self, pid: str) -> Optional[dict]: """ return self._call_endpoint( cmd="get", - endpoint=f"/Datasets/{quote_plus(pid)}/origdatablocks", + endpoint=f"Datasets/{quote_plus(pid)}/origdatablocks", operation="datasets_origdatablocks_get_one", allow_404=True, ) @@ -937,7 +937,7 @@ def datasets_delete(self, pid: str) -> Optional[dict]: """ return self._call_endpoint( cmd="delete", - endpoint=f"/Datasets/{quote_plus(pid)}", + endpoint=f"Datasets/{quote_plus(pid)}", operation="datasets_delete", allow_404=True, ) diff --git a/tests/test_pyscicat/tests_local.py b/tests/test_pyscicat/tests_integration.py similarity index 66% rename from tests/test_pyscicat/tests_local.py rename to tests/test_pyscicat/tests_integration.py index 95204bd..387fbe1 100644 --- a/tests/test_pyscicat/tests_local.py +++ b/tests/test_pyscicat/tests_integration.py @@ -1,7 +1,8 @@ from pyscicat.client import ScicatClient -from pyscicat.model import RawDataset +from pyscicat.model import RawDataset, Ownable from datetime import datetime import os +import requests """ @@ -18,51 +19,57 @@ SCICAT_PASSWORD - the password for your scicat user. """ - +sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], + token=None, + username=os.environ["SCICAT_USER"], + password=os.environ["SCICAT_PASSWORD"]) def test_client(): - sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], - token=None, - username=os.environ["SCICAT_USER"], - password=os.environ["SCICAT_PASSWORD"]) + assert type(sci_clie) == ScicatClient + def test_upload_dataset(): - sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], - token=None, username=os.environ["SCICAT_USER"], - password=os.environ["SCICAT_PASSWORD"]) + + ownable = Ownable(ownerGroup="ingestor", accessGroups=[]) payload = RawDataset( - datasetName="a guide book", + datasetName="a new guide book", path="/foo/bar", size=42, + packedSize=0, owner=os.environ["SCICAT_USER"], - ownerGroup="Magrateheans", contactEmail="slartibartfast@magrathea.org", - creationLocation="magrathea", + creationLocation="Magrathea", creationTime=datetime.isoformat(datetime.now()), instrumentId="earth", proposalId="deepthought", dataFormat="planet", principalInvestigator="A. Mouse", sourceFolder="/foo/bar", - scientificMetadata={"a": "field"}, + scientificMetadata={"type": "string", "value": {"a": "field"}}, sampleId="gargleblaster", - accessGroups=[] + type="raw", + ownerEmail="scicatingestor@your.site", + sourceFolderHost="s3.heartofgold.org", + endTime=datetime.isoformat(datetime.now()), + techniques=[], + numberOfFiles=0, + numberOfFilesArchived=0, + **ownable.dict() ) sci_clie.upload_new_dataset(payload) def test_get_dataset(subtests): - sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], - token=None, - username=os.environ["SCICAT_USER"], - password=os.environ["SCICAT_PASSWORD"]) - datasets = sci_clie.get_datasets({"ownerGroup": "Magratheans"}) + + datasets = sci_clie.get_datasets({"ownerGroup": "ingestor"}) + + for dataset in datasets: - with subtests.tests(dataset=dataset): - assert dataset["ownerGroup"] == "Magratheans" + + assert dataset["ownerGroup"] == "ingestor" def test_update_dataset():