Skip to content

Commit

Permalink
WIP: fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-uoa committed Jul 17, 2024
1 parent d4bc105 commit 4d2c906
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/mytardis_client/mt_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class IngestedDataset(MyTardisResource):
class IngestedDatafile(MyTardisResource):
"""Metadata associated with a datafile that has been ingested into MyTardis."""

created_time: ISODateTime
created_time: Optional[ISODateTime]
# "datafile": null,
dataset: URI
deleted: bool
Expand All @@ -273,7 +273,7 @@ class IngestedDatafile(MyTardisResource):
identifiers: Optional[list[str]]
md5sum: MD5Sum
mimetype: str
modification_time: ISODateTime
modification_time: Optional[ISODateTime]
# "parameter_sets": []
public_access: bool
replicas: list[Replica]
Expand Down
73 changes: 36 additions & 37 deletions src/mytardis_client/response_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,39 @@

from src.mytardis_client.objects import MyTardisObject


class MyTardisIntrospection(BaseModel):
"""MyTardis introspection data.
NOTE: this class relies on data from the MyTardis introspection API and therefore
can't be instantiated without a request to the specific MyTardis instance.
"""

model_config = ConfigDict(use_enum_values=False)

data_classification_enabled: Optional[bool]
identifiers_enabled: bool
objects_with_ids: list[MyTardisObject] = Field(
validation_alias="identified_objects"
)
objects_with_profiles: list[MyTardisObject] = Field(
validation_alias="profiled_objects"
)
old_acls: bool = Field(validation_alias="experiment_only_acls")
projects_enabled: bool
profiles_enabled: bool

@model_validator(mode="after")
def validate_consistency(self) -> Self:
"""Check that the introspection data is consistent."""

if not self.identifiers_enabled and len(self.objects_with_ids) > 0:
raise ValueError(
"Identifiers are disabled in MyTardis but it reports identifiable types"
)

if not self.profiles_enabled and len(self.objects_with_profiles) > 0:
raise ValueError(
"Profiles are disabled in MyTardis but it reports profiled types"
)

return self
# class MyTardisIntrospection(BaseModel):
# """MyTardis introspection data.

# NOTE: this class relies on data from the MyTardis introspection API and therefore
# can't be instantiated without a request to the specific MyTardis instance.
# """

# model_config = ConfigDict(use_enum_values=False)

# data_classification_enabled: Optional[bool]
# identifiers_enabled: bool
# objects_with_ids: list[MyTardisObject] = Field(
# validation_alias="identified_objects"
# )
# objects_with_profiles: list[MyTardisObject] = Field(
# validation_alias="profiled_objects"
# )
# old_acls: bool = Field(validation_alias="experiment_only_acls")
# projects_enabled: bool
# profiles_enabled: bool

# @model_validator(mode="after")
# def validate_consistency(self) -> Self:
# """Check that the introspection data is consistent."""

# if not self.identifiers_enabled and len(self.objects_with_ids) > 0:
# raise ValueError(
# "Identifiers are disabled in MyTardis but it reports identifiable types"
# )

# if not self.profiles_enabled and len(self.objects_with_profiles) > 0:
# raise ValueError(
# "Profiles are disabled in MyTardis but it reports profiled types"
# )

# return self
3 changes: 2 additions & 1 deletion src/overseers/overseer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from src.mytardis_client.mt_dataclasses import MyTardisIntrospection
from src.mytardis_client.mt_rest import Ingested, MyTardisRESTFactory
from src.mytardis_client.objects import MyTardisObject, get_type_info
from src.mytardis_client.response_data import MyTardisIntrospection

# from src.mytardis_client.response_data import MyTardisIntrospection
from src.utils.types.singleton import Singleton

logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/fixtures_ingestion_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from src.ingestion_factory import IngestionFactory
from src.mytardis_client.mt_dataclasses import MyTardisIntrospection
from src.mytardis_client.mt_rest import MyTardisRESTFactory
from src.mytardis_client.response_data import MyTardisIntrospection

# from src.mytardis_client.response_data import MyTardisIntrospection
from src.overseers.overseer import Overseer
from src.smelters.smelter import Smelter
from tests.fixtures.mock_rest_factory import MockMtRest
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/fixtures_mytardis_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from pytest import fixture

from src.mytardis_client.response_data import MyTardisIntrospection
# from src.mytardis_client.response_data import MyTardisIntrospection
from src.mytardis_client.mt_dataclasses import MyTardisIntrospection


@fixture
Expand Down
8 changes: 4 additions & 4 deletions tests/test_mytardis_client_rest_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def test_mytardis_client_rest_get_multi(
assert datafiles[1].resource_uri == URI("/api/v1/dataset_file/1/")
assert datafiles[2].resource_uri == URI("/api/v1/dataset_file/2/")

assert datafiles[0].obj.filename == "test_filename_0.txt"
assert datafiles[1].obj.filename == "test_filename_1.txt"
assert datafiles[2].obj.filename == "test_filename_2.txt"
assert datafiles[0].filename == "test_filename_0.txt"
assert datafiles[1].filename == "test_filename_1.txt"
assert datafiles[2].filename == "test_filename_2.txt"

assert isinstance(meta, GetResponseMeta)
assert meta.total_count == 30
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_mytardis_client_rest_get_all(

for i in range(30):
assert datafiles[i].resource_uri == URI(f"/api/v1/dataset_file/{i}/")
assert datafiles[i].obj.filename == f"test_filename_{i}.txt"
assert datafiles[i].filename == f"test_filename_{i}.txt"

assert total_count == 30

Expand Down
2 changes: 1 addition & 1 deletion tests/test_overseers.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_get_mytardis_setup_too_many_objects(
status=200,
)

with pytest.raises(ValueError):
with pytest.raises(RuntimeError):
_ = overseer.fetch_mytardis_setup()

Overseer.clear()

0 comments on commit 4d2c906

Please sign in to comment.