-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
567 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,18 @@ | |
import json | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import TypedDict | ||
|
||
|
||
class ScicatCredentials(TypedDict): | ||
"""A dict with testing credentials for SciCat.""" | ||
|
||
username: str | ||
password: str | ||
|
||
|
||
@dataclass | ||
class SciCatUser: | ||
class ScicatUser: | ||
"""A SciCat user. | ||
Warning | ||
|
@@ -24,7 +32,7 @@ class SciCatUser: | |
group: str | ||
|
||
@property | ||
def credentials(self) -> dict[str, str]: | ||
def credentials(self) -> ScicatCredentials: | ||
"""Return login credentials for this user. | ||
User as | ||
|
@@ -51,43 +59,43 @@ def dump(self) -> dict[str, str | bool]: | |
|
||
# see https://github.com/SciCatProject/scicat-backend-next/blob/master/src/config/configuration.ts | ||
USERS = { | ||
"ingestor": SciCatUser( | ||
"ingestor": ScicatUser( | ||
username="ingestor", | ||
password="aman", # noqa: S106 | ||
email="[email protected]", | ||
group="ingestor", | ||
), | ||
"user1": SciCatUser( | ||
"user1": ScicatUser( | ||
username="user1", | ||
password="a609316768619f154ef58db4d847b75e", # noqa: S106 | ||
email="[email protected]", | ||
group="group1", | ||
), | ||
"user2": SciCatUser( | ||
"user2": ScicatUser( | ||
username="user2", | ||
password="f522d1d715970073a6413474ca0e0f63", # noqa: S106 | ||
email="[email protected]", | ||
group="group2", | ||
), | ||
"user3": SciCatUser( | ||
"user3": ScicatUser( | ||
username="user3", | ||
password="70dc489e8ee823ae815e18d664424df2", # noqa: S106 | ||
email="[email protected]", | ||
group="group3", | ||
), | ||
"user4": SciCatUser( | ||
"user4": ScicatUser( | ||
username="user4", | ||
password="0014890e7020f515b92b767227ef2dfa", # noqa: S106 | ||
email="[email protected]", | ||
group="group4", | ||
), | ||
"user5.1": SciCatUser( | ||
"user5.1": ScicatUser( | ||
username="user5.1", | ||
password="359a5fda99bfe5dbc42ee9b3ede77fb7", # noqa: S106 | ||
email="[email protected]", | ||
group="group5", | ||
), | ||
"user5.2": SciCatUser( | ||
"user5.2": ScicatUser( | ||
username="user5.2", | ||
password="f3ebd2e4def95db59ef95ee32ef45242", # noqa: S106 | ||
email="[email protected]", | ||
|
@@ -109,7 +117,7 @@ class SciCatAccess: | |
"""Access parameters for a local SciCat backend.""" | ||
|
||
url: str | ||
user: SciCatUser | ||
user: ScicatUser | ||
|
||
|
||
def local_access(user: str) -> SciCatAccess: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,11 @@ | |
from scitacean.model import ( | ||
Attachment, | ||
DatasetType, | ||
DownloadAttachment, | ||
UploadAttachment, | ||
UploadDerivedDataset, | ||
) | ||
from scitacean.testing.backend import config as backend_config | ||
from scitacean.testing.backend.seed import ( | ||
INITIAL_ATTACHMENTS, | ||
INITIAL_DATASETS, | ||
|
@@ -27,7 +29,7 @@ def scicat_client(client: Client) -> ScicatClient: | |
|
||
|
||
@pytest.fixture | ||
def derived_dataset(scicat_access): | ||
def derived_dataset(scicat_access: backend_config.SciCatAccess) -> UploadDerivedDataset: | ||
return UploadDerivedDataset( | ||
contactEmail="[email protected]", | ||
creationTime=parse_date("1995-11-11T11:11:11.000Z"), | ||
|
@@ -44,7 +46,7 @@ def derived_dataset(scicat_access): | |
|
||
|
||
@pytest.fixture | ||
def attachment(scicat_access): | ||
def attachment(scicat_access: backend_config.SciCatAccess) -> UploadAttachment: | ||
return UploadAttachment( | ||
caption="An attachment", | ||
thumbnail=Thumbnail(mime="image/png", data=b"9278c78a904jh"), | ||
|
@@ -53,15 +55,21 @@ def attachment(scicat_access): | |
) | ||
|
||
|
||
def compare_attachment_after_upload(uploaded, downloaded): | ||
def compare_attachment_after_upload( | ||
uploaded: UploadAttachment, downloaded: DownloadAttachment | ||
) -> None: | ||
for key, expected in uploaded: | ||
# The database populates a number of fields that are None in uploaded. | ||
# But we don't want to test those here as we don't want to test the database. | ||
if expected is not None: | ||
assert expected == dict(downloaded)[key], f"key = {key}" | ||
|
||
|
||
def test_create_attachment_for_dataset(scicat_client, attachment, derived_dataset): | ||
def test_create_attachment_for_dataset( | ||
scicat_client: ScicatClient, | ||
attachment: UploadAttachment, | ||
derived_dataset: UploadDerivedDataset, | ||
) -> None: | ||
attachment1 = deepcopy(attachment) | ||
attachment2 = deepcopy(attachment) | ||
attachment2.caption = "Another attachment" | ||
|
@@ -82,8 +90,11 @@ def test_create_attachment_for_dataset(scicat_client, attachment, derived_datase | |
|
||
|
||
def test_create_attachment_for_dataset_with_existing_id( | ||
real_client, attachment, derived_dataset, require_scicat_backend | ||
): | ||
real_client: Client, | ||
attachment: UploadAttachment, | ||
derived_dataset: UploadDerivedDataset, | ||
require_scicat_backend: None, | ||
) -> None: | ||
scicat_client = real_client.scicat | ||
|
||
dataset_id = scicat_client.create_dataset_model(derived_dataset).pid | ||
|
@@ -95,17 +106,19 @@ def test_create_attachment_for_dataset_with_existing_id( | |
|
||
|
||
def test_cannot_create_attachment_for_dataset_for_nonexistent_dataset( | ||
scicat_client, attachment | ||
): | ||
scicat_client: ScicatClient, attachment: UploadAttachment | ||
) -> None: | ||
with pytest.raises(ScicatCommError): | ||
scicat_client.create_attachment_for_dataset( | ||
attachment, dataset_id=PID(pid="nonexistent-id") | ||
) | ||
|
||
|
||
def test_create_attachment_for_dataset_for_dataset_populates_ids( | ||
scicat_client, attachment, derived_dataset | ||
): | ||
scicat_client: ScicatClient, | ||
attachment: UploadAttachment, | ||
derived_dataset: UploadDerivedDataset, | ||
) -> None: | ||
assert attachment.id is None | ||
assert attachment.datasetId is None | ||
assert attachment.sampleId is None | ||
|
@@ -123,28 +136,30 @@ def test_create_attachment_for_dataset_for_dataset_populates_ids( | |
assert finalized.proposalId is None | ||
|
||
|
||
def test_get_attachments_for_dataset(scicat_client): | ||
def test_get_attachments_for_dataset(scicat_client: ScicatClient) -> None: | ||
dset = INITIAL_DATASETS["derived"] | ||
attachments = scicat_client.get_attachments_for_dataset(dset.pid) | ||
assert attachments == INITIAL_ATTACHMENTS["derived"] | ||
|
||
|
||
def test_get_attachments_for_dataset_no_attachments(scicat_client): | ||
def test_get_attachments_for_dataset_no_attachments( | ||
scicat_client: ScicatClient, | ||
) -> None: | ||
assert INITIAL_ATTACHMENTS.get("raw") is None | ||
dset = INITIAL_DATASETS["raw"] | ||
attachments = scicat_client.get_attachments_for_dataset(dset.pid) | ||
assert attachments == [] | ||
|
||
|
||
@pytest.mark.parametrize("key", ["raw", "derived"]) | ||
def test_get_dataset_does_not_initialise_attachments(client, key): | ||
def test_get_dataset_does_not_initialise_attachments(client: Client, key: str) -> None: | ||
dset = INITIAL_DATASETS["derived"] | ||
downloaded = client.get_dataset(dset.pid) | ||
assert downloaded.attachments is None | ||
|
||
|
||
@pytest.mark.parametrize("key", ["raw", "derived"]) | ||
def test_download_attachments_for_dataset(client, key): | ||
def test_download_attachments_for_dataset(client: Client, key: str) -> None: | ||
dset = INITIAL_DATASETS[key] | ||
downloaded = client.get_dataset(dset.pid) | ||
with_attachments = client.download_attachments_for(downloaded) | ||
|
@@ -156,7 +171,7 @@ def test_download_attachments_for_dataset(client, key): | |
|
||
|
||
@pytest.mark.parametrize("key", ["raw", "derived"]) | ||
def test_get_dataset_with_attachments(client, key): | ||
def test_get_dataset_with_attachments(client: Client, key: str) -> None: | ||
dset = INITIAL_DATASETS[key] | ||
downloaded = client.get_dataset(dset.pid, attachments=True) | ||
expected = [ | ||
|
Oops, something went wrong.