From f78b6843797fd2f0e18cfa65ae008bcd6d343032 Mon Sep 17 00:00:00 2001 From: vpf26432 Date: Mon, 20 Mar 2023 13:44:55 +0000 Subject: [PATCH] porting tests to pyscicat and linting with flake8 --- pyscicat/__init__.py | 4 +- setup.py | 5 +- tests/test_pyscicat/tests_local.py | 136 ++++++++++++++++------------- 3 files changed, 76 insertions(+), 69 deletions(-) diff --git a/pyscicat/__init__.py b/pyscicat/__init__.py index 4f9eb34..32ac1d7 100644 --- a/pyscicat/__init__.py +++ b/pyscicat/__init__.py @@ -1,6 +1,6 @@ +from . import hdf5 +from . import ingest from ._version import get_versions __version__ = get_versions()["version"] del get_versions -from . import hdf5 -from . import ingest \ No newline at end of file diff --git a/setup.py b/setup.py index 9709c4e..6068493 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,3 @@ -from pathlib import Path -from setuptools import setup, find_packages -import sys +from setuptools import setup setup() - diff --git a/tests/test_pyscicat/tests_local.py b/tests/test_pyscicat/tests_local.py index 45da1f7..95204bd 100644 --- a/tests/test_pyscicat/tests_local.py +++ b/tests/test_pyscicat/tests_local.py @@ -1,81 +1,91 @@ -import unittest from pyscicat.client import ScicatClient from pyscicat.model import RawDataset from datetime import datetime import os -class TestClientLocally(unittest.TestCase): - """ - These test_pyscicat 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. - """ +""" +These test_pyscicat 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. - def test_client(self): - sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], password=os.environ["SCICAT_PASSWORD"]) - self.assertIsInstance(sci_clie, ScicatClient) - print(sci_clie._token) +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(): + 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(self): - sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], password=os.environ["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=[] - ) +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"]) - sci_clie.upload_new_dataset(payload) + 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=[] + ) - def test_get_dataset(self): - 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"}) - with self.subTest(dataset=datasets): - self.assertEqual(dataset["ownerGroup"], "Magratheans") + sci_clie.upload_new_dataset(payload) - def test_update_dataset(self): - sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], token=None, username=os.environ["SCICAT_USER"], - password=os.environ["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(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"}) + for dataset in datasets: + with subtests.tests(dataset=dataset): + assert dataset["ownerGroup"] == "Magratheans" +def test_update_dataset(): + sci_clie = ScicatClient(base_url=os.environ["BASE_URL"], + token=None, + username=os.environ["SCICAT_USER"], + password=os.environ["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)