"""Integration tests for AnnotationRepository.""" from uuid import UUID import pytest from data_store.repositories.annotation_repository import AnnotationRepository from data_store.dto import ( Annotation, ) def test_get_annotation( annotation_in_minio: tuple[UUID, Annotation], annotation_repository: AnnotationRepository, ) -> None: """Test retrieving an annotation from AnnotationRepository.""" # Arrange job_id, expected_annotation = annotation_in_minio # Act retrieved_annotation = annotation_repository.get(job_id) # Assert assert retrieved_annotation is not None assert isinstance(retrieved_annotation, Annotation) assert retrieved_annotation == expected_annotation def test_put_annotation( annotation_repository: AnnotationRepository, annotation: Annotation, job_id_list: list[UUID], ) -> None: """Test storing an annotation in AnnotationRepository.""" # Arrange job_id = job_id_list[0] assert annotation_repository.get(job_id) is None # Act annotation_repository.put(annotation, job_id) # Assert received_annotation = annotation_repository.get(job_id) assert received_annotation is not None assert isinstance(received_annotation, Annotation) assert received_annotation == annotation def test_delete_annotation( annotation_in_minio: tuple[UUID, Annotation], annotation_repository: AnnotationRepository, ) -> None: """Test deleting an annotation from AnnotationRepository.""" # Arrange job_id, _ = annotation_in_minio assert annotation_repository.get(job_id) is not None # Act annotation_repository.delete(job_id) # Assert assert annotation_repository.get(job_id) is None def test_list_all_annotations( annotation_in_minio: tuple[UUID, Annotation], annotation_repository: AnnotationRepository, ) -> None: """Test listing all annotations in AnnotationRepository.""" # Arrange job_id, _ = annotation_in_minio # Act annotation_ids = annotation_repository.list_all() # Assert assert isinstance(annotation_ids, list) assert all(isinstance(i, UUID) for i in annotation_ids) assert job_id in annotation_ids def test_list_all_annotations_empty( annotation_repository: AnnotationRepository, ) -> None: """Test listing all annotations in an empty AnnotationRepository.""" # Act annotation_ids = annotation_repository.list_all() # Assert assert isinstance(annotation_ids, list) assert len(annotation_ids) == 0 # Allows local debugging by running file as script if __name__ == "__main__": pytest.main(["-s", "-v", __file__])