Skip to content

Commit

Permalink
Update UCS tests and remove second S3 fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Jun 3, 2024
1 parent d681e78 commit 35c63dd
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 358 deletions.
3 changes: 2 additions & 1 deletion services/ucs/src/ucs/adapters/inbound/event_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ async def _consume_validated(
*,
payload: JsonObject,
type_: Ascii,
topic: Ascii, # pylint: disable=unused-argument
topic: Ascii,
key: Ascii,
) -> None:
"""Consume events from the topics of interest."""
if type_ == self._config.file_metadata_event_type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.

"""REST API-specific data models (not used by core package)"""

from pydantic import ConfigDict

try: # workaround for https://github.com/pydantic/pydantic/issues/5821
Expand Down
1 change: 0 additions & 1 deletion services/ucs/src/ucs/ports/inbound/file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

"""Interfaces for the main upload handling logic of this service."""


from abc import ABC, abstractmethod
from collections.abc import Iterable, Sequence

Expand Down
32 changes: 32 additions & 0 deletions services/ucs/tests_ucs/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Set up session-scope fixtures for tests."""

from hexkit.providers.akafka.testutils import ( # noqa: F401
kafka_container_fixture,
kafka_fixture,
)
from hexkit.providers.mongodb.testutils import ( # noqa: F401
mongodb_container_fixture,
mongodb_fixture,
)
from hexkit.providers.s3.testutils import ( # noqa: F401
s3_container_fixture,
s3_fixture,
)

from tests_ucs.fixtures.joint import get_joint_fixture

joint_fixture = get_joint_fixture()
2 changes: 1 addition & 1 deletion services/ucs/tests_ucs/fixtures/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_config(
for source in sources:
sources_dict.update(**source.model_dump())

return Config(config_yaml=default_config_yaml, **sources_dict) # type: ignore
return Config(config_yaml=default_config_yaml, **sources_dict)


DEFAULT_CONFIG = get_config()
2 changes: 1 addition & 1 deletion services/ucs/tests_ucs/fixtures/example_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class UploadDetails:
submission_metadata=FILE_TO_REGISTER_1,
)
UPLOAD_DETAILS_2 = UploadDetails(
storage_alias=STORAGE_ALIASES[1],
storage_alias=STORAGE_ALIASES[0],
file_metadata=EXAMPLE_FILE_2,
upload_attempt=EXAMPLE_UPLOAD_2,
submission_metadata=FILE_TO_REGISTER_2,
Expand Down
63 changes: 15 additions & 48 deletions services/ucs/tests_ucs/fixtures/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@

"""Join the functionality of all fixtures for API-level integration testing."""

__all__ = [
"joint_fixture",
"JointFixture",
"mongodb_fixture",
"kafka_fixture",
"s3_fixture",
"second_s3_fixture",
]
__all__ = ["JointFixture", "get_joint_fixture"]

from collections.abc import AsyncGenerator
from dataclasses import dataclass
Expand All @@ -35,9 +28,9 @@
S3ObjectStoragesConfig,
)
from hexkit.providers.akafka import KafkaEventSubscriber
from hexkit.providers.akafka.testutils import KafkaFixture, get_kafka_fixture
from hexkit.providers.mongodb.testutils import MongoDbFixture, get_mongodb_fixture
from hexkit.providers.s3.testutils import S3Fixture, get_s3_fixture
from hexkit.providers.akafka.testutils import KafkaFixture
from hexkit.providers.mongodb.testutils import MongoDbFixture
from hexkit.providers.s3.testutils import S3Fixture
from pytest_asyncio.plugin import _ScopeName
from ucs.adapters.outbound.dao import DaoCollectionTranslator
from ucs.config import Config
Expand Down Expand Up @@ -69,53 +62,35 @@ class JointFixture:
mongodb: MongoDbFixture
kafka: KafkaFixture
s3: S3Fixture
second_s3: S3Fixture
bucket_id: str
inbox_inspector: StorageInspectorPort

async def reset_state(self):
"""Completely reset fixture states"""
await self.s3.empty_buckets()
await self.second_s3.empty_buckets()
self.mongodb.empty_collections()
self.kafka.clear_topics()


async def joint_fixture_function(
mongodb_fixture: MongoDbFixture,
kafka_fixture: KafkaFixture,
s3_fixture: S3Fixture,
second_s3_fixture: S3Fixture,
mongodb: MongoDbFixture,
kafka: KafkaFixture,
s3: S3Fixture,
) -> AsyncGenerator[JointFixture, None]:
"""A fixture that embeds all other fixtures for API-level integration testing.
**Do not call directly** Instead, use get_joint_fixture().
"""
bucket_id = "test-inbox"

node_config = S3ObjectStorageNodeConfig(
bucket=bucket_id, credentials=s3_fixture.config
)
second_node_config = S3ObjectStorageNodeConfig(
bucket=bucket_id, credentials=second_s3_fixture.config
)
node_config = S3ObjectStorageNodeConfig(bucket=bucket_id, credentials=s3.config)
object_storages_config = S3ObjectStoragesConfig(
object_storages={
STORAGE_ALIASES[0]: node_config,
STORAGE_ALIASES[1]: second_node_config,
}
)

# merge configs from different sources with the default one:
config = get_config(
sources=[mongodb_fixture.config, kafka_fixture.config, object_storages_config]
)
config = get_config(sources=[mongodb.config, kafka.config, object_storages_config])

daos = await DaoCollectionTranslator.construct(provider=mongodb_fixture.dao_factory)
await s3_fixture.populate_buckets([bucket_id])
await second_s3_fixture.populate_buckets([bucket_id])
daos = await DaoCollectionTranslator.construct(provider=mongodb.dao_factory)
await s3.populate_buckets([bucket_id])

# create a DI container instance:translators
# Assemble joint fixture with config injection
async with (
prepare_core(config=config) as (
upload_service,
Expand All @@ -139,10 +114,9 @@ async def joint_fixture_function(
file_metadata_service=file_metadata_service,
rest_client=rest_client,
event_subscriber=event_subscriber,
mongodb=mongodb_fixture,
kafka=kafka_fixture,
s3=s3_fixture,
second_s3=second_s3_fixture,
mongodb=mongodb,
kafka=kafka,
s3=s3,
bucket_id=bucket_id,
inbox_inspector=inbox_inspector,
)
Expand All @@ -151,10 +125,3 @@ async def joint_fixture_function(
def get_joint_fixture(scope: _ScopeName = "function"):
"""Produce a joint fixture with desired scope"""
return pytest_asyncio.fixture(joint_fixture_function, scope=scope)


joint_fixture = get_joint_fixture()
mongodb_fixture = get_mongodb_fixture()
kafka_fixture = get_kafka_fixture()
s3_fixture = get_s3_fixture()
second_s3_fixture = get_s3_fixture()
42 changes: 0 additions & 42 deletions services/ucs/tests_ucs/fixtures/module_scope_fixtures.py

This file was deleted.

Loading

0 comments on commit 35c63dd

Please sign in to comment.