From 4d2c906881fcfb45253121a830776ae1e67398bc Mon Sep 17 00:00:00 2001 From: Andrew Wilson Date: Wed, 17 Jul 2024 17:27:53 +1200 Subject: [PATCH] WIP: fix broken tests --- src/mytardis_client/mt_dataclasses.py | 4 +- src/mytardis_client/response_data.py | 73 ++++++++++---------- src/overseers/overseer.py | 3 +- tests/fixtures/fixtures_ingestion_classes.py | 3 +- tests/fixtures/fixtures_mytardis_client.py | 3 +- tests/test_mytardis_client_rest_factory.py | 8 +-- tests/test_overseers.py | 2 +- 7 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/mytardis_client/mt_dataclasses.py b/src/mytardis_client/mt_dataclasses.py index 234169a0..9b5a3778 100644 --- a/src/mytardis_client/mt_dataclasses.py +++ b/src/mytardis_client/mt_dataclasses.py @@ -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 @@ -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] diff --git a/src/mytardis_client/response_data.py b/src/mytardis_client/response_data.py index ac3c00ad..1ed99374 100644 --- a/src/mytardis_client/response_data.py +++ b/src/mytardis_client/response_data.py @@ -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 diff --git a/src/overseers/overseer.py b/src/overseers/overseer.py index e5b96a64..127a4b3d 100644 --- a/src/overseers/overseer.py +++ b/src/overseers/overseer.py @@ -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__) diff --git a/tests/fixtures/fixtures_ingestion_classes.py b/tests/fixtures/fixtures_ingestion_classes.py index ada32459..23efa594 100644 --- a/tests/fixtures/fixtures_ingestion_classes.py +++ b/tests/fixtures/fixtures_ingestion_classes.py @@ -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 diff --git a/tests/fixtures/fixtures_mytardis_client.py b/tests/fixtures/fixtures_mytardis_client.py index b952d068..3baed684 100644 --- a/tests/fixtures/fixtures_mytardis_client.py +++ b/tests/fixtures/fixtures_mytardis_client.py @@ -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 diff --git a/tests/test_mytardis_client_rest_factory.py b/tests/test_mytardis_client_rest_factory.py index ae3e4772..55d4a1e8 100644 --- a/tests/test_mytardis_client_rest_factory.py +++ b/tests/test_mytardis_client_rest_factory.py @@ -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 @@ -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 diff --git a/tests/test_overseers.py b/tests/test_overseers.py index 533c179c..34a421ab 100644 --- a/tests/test_overseers.py +++ b/tests/test_overseers.py @@ -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()