Skip to content

Commit

Permalink
Do minor test reorganization and mypy-placation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes committed Jun 5, 2024
1 parent c9ead23 commit cd83923
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 32 deletions.
2 changes: 1 addition & 1 deletion services/dcs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ The service requires the following configuration parameters:
```


- **`api_route`** *(string)*: Default: `"/ga4gh/drs/v1"`.
- **`api_route`** *(string)*: DRS API route. Default: `"/ga4gh/drs/v1"`.

## Definitions

Expand Down
1 change: 1 addition & 0 deletions services/dcs/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
},
"api_route": {
"default": "/ga4gh/drs/v1",
"description": "DRS API route",
"title": "Api Route",
"type": "string"
}
Expand Down
3 changes: 2 additions & 1 deletion services/dcs/src/dcs/adapters/inbound/fastapi_/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
from ghga_service_commons.api import ApiConfigBase, configure_app
from pydantic import Field

from dcs import __version__
from dcs.adapters.inbound.fastapi_.routes import router
Expand All @@ -28,7 +29,7 @@
class DrsApiConfig(ApiConfigBase):
"""Configuration parameters for the DRS API."""

api_route: str = "/ga4gh/drs/v1"
api_route: str = Field(default="/ga4gh/drs/v1", description="DRS API route")


def get_openapi_schema(app: FastAPI, *, config: DrsApiConfig) -> dict[str, Any]:
Expand Down
6 changes: 3 additions & 3 deletions services/dcs/src/dcs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

async def run_rest_app():
"""Run the HTTP REST API."""
config = Config() # type: ignore
config = Config()
configure_logging(config=config)

async with prepare_rest_app(config=config) as app:
Expand All @@ -37,7 +37,7 @@ async def run_rest_app():

async def consume_events(run_forever: bool = True):
"""Run an event consumer listening to the specified topic."""
config = Config() # type: ignore
config = Config()
configure_logging(config=config)

async with prepare_event_subscriber(config=config) as event_subscriber:
Expand All @@ -46,7 +46,7 @@ async def consume_events(run_forever: bool = True):

async def run_outbox_cleanup():
"""Check if outbox buckets contains files that should be cleaned up and perform clean-up."""
config = Config() # type: ignore
config = Config()
configure_logging(config=config)

async with prepare_outbox_cleaner(config=config) as cleanup_outbox:
Expand Down
37 changes: 37 additions & 0 deletions services/dcs/tests_dcs/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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.
"""Session-scoped fixture setup"""

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
file_fixture, # function-scoped
s3_container_fixture,
s3_fixture,
)

# These are function-scoped but importing them here saves imports in test
# modules and makes it so the noqa: F811 is not required
from tests_dcs.fixtures.joint import ( # noqa: F401
cleanup_fixture,
joint_fixture,
populated_fixture,
)
1 change: 0 additions & 1 deletion services/dcs/tests_dcs/fixtures/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ def get_config(
for source in sources:
sources_dict.update(**source.model_dump())

# type: ignore
return Config(config_yaml=default_config_yaml, **sources_dict)
14 changes: 0 additions & 14 deletions services/dcs/tests_dcs/fixtures/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@

__all__ = [
"cleanup_fixture",
"file_fixture",
"joint_fixture",
"JointFixture",
"mongodb_fixture",
"mongodb_container_fixture",
"s3_fixture",
"s3_container_fixture",
"kafka_fixture",
"kafka_container_fixture",
"populated_fixture",
"PopulatedFixture",
"generate_work_order_token",
Expand Down Expand Up @@ -60,19 +53,12 @@
from hexkit.providers.akafka import KafkaEventSubscriber
from hexkit.providers.akafka.testutils import (
KafkaFixture,
kafka_container_fixture,
kafka_fixture,
)
from hexkit.providers.mongodb.testutils import (
MongoDbFixture,
mongodb_container_fixture,
mongodb_fixture,
)
from hexkit.providers.s3.testutils import (
S3Fixture,
file_fixture,
s3_container_fixture,
s3_fixture,
temp_file_object,
)
from jwcrypto.jwk import JWK
Expand Down
14 changes: 7 additions & 7 deletions services/dcs/tests_dcs/test_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
from ghga_service_commons.utils.utc_dates import now_as_utc
from pytest_httpx import HTTPXMock, httpx_mock # noqa: F401

from tests_dcs.fixtures.joint import * # noqa: F403
from tests_dcs.fixtures.joint import EXAMPLE_FILE, JointFixture, PopulatedFixture
from tests_dcs.fixtures.joint import (
EXAMPLE_FILE,
JointFixture,
PopulatedFixture,
)
from tests_dcs.fixtures.mock_api.app import router
from tests_dcs.fixtures.utils import (
generate_token_signing_keys,
Expand All @@ -40,6 +43,8 @@

unintercepted_hosts: list[str] = ["localhost"]

pytestmark = pytest.mark.asyncio()


@dataclass
class StorageUnavailableFixture:
Expand Down Expand Up @@ -85,7 +90,6 @@ def non_mocked_hosts() -> list:
return unintercepted_hosts


@pytest.mark.asyncio
async def test_get_health(joint_fixture: JointFixture):
"""Test the GET /health endpoint"""
response = await joint_fixture.rest_client.get("/health")
Expand All @@ -94,7 +98,6 @@ async def test_get_health(joint_fixture: JointFixture):
assert response.json() == {"status": "OK"}


@pytest.mark.asyncio
async def test_access_non_existing(joint_fixture: JointFixture):
"""Checks that requesting access to a non-existing DRS object fails with the
expected exception.
Expand Down Expand Up @@ -136,7 +139,6 @@ async def test_access_non_existing(joint_fixture: JointFixture):
assert response.status_code == status.HTTP_404_NOT_FOUND


@pytest.mark.asyncio
async def test_deletion_config_error(
storage_unavailable_fixture: StorageUnavailableFixture,
httpx_mock: HTTPXMock, # noqa: F811
Expand All @@ -153,7 +155,6 @@ async def test_deletion_config_error(
await data_repository.delete_file(file_id=storage_unavailable_fixture.file_id)


@pytest.mark.asyncio
async def test_drs_config_error(
storage_unavailable_fixture: StorageUnavailableFixture,
httpx_mock: HTTPXMock, # noqa: F811
Expand Down Expand Up @@ -184,7 +185,6 @@ async def test_drs_config_error(
assert response.status_code == 500


@pytest.mark.asyncio
async def test_register_file_twice(populated_fixture: PopulatedFixture, caplog):
"""Assure that files cannot be registered twice"""
joint_fixture = populated_fixture.joint_fixture
Expand Down
11 changes: 6 additions & 5 deletions services/dcs/tests_dcs/test_typical_journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
from hexkit.providers.s3.testutils import FileObject
from pytest_httpx import HTTPXMock, httpx_mock # noqa: F401

from tests_dcs.fixtures.joint import * # noqa: F403
from tests_dcs.fixtures.joint import CleanupFixture, PopulatedFixture
from tests_dcs.fixtures.joint import (
CleanupFixture,
PopulatedFixture,
)
from tests_dcs.fixtures.mock_api.app import router
from tests_dcs.fixtures.utils import generate_work_order_token

unintercepted_hosts: list[str] = ["localhost"]

pytestmark = pytest.mark.asyncio()


@pytest.fixture
def non_mocked_hosts() -> list:
Expand All @@ -47,7 +51,6 @@ def non_mocked_hosts() -> list:
return unintercepted_hosts


@pytest.mark.asyncio
async def test_happy_journey(
populated_fixture: PopulatedFixture,
tmp_file: FileObject,
Expand Down Expand Up @@ -165,7 +168,6 @@ async def test_happy_journey(
assert response.status_code == status.HTTP_401_UNAUTHORIZED


@pytest.mark.asyncio
async def test_happy_deletion(
populated_fixture: PopulatedFixture,
tmp_file: FileObject,
Expand Down Expand Up @@ -213,7 +215,6 @@ async def test_happy_deletion(
)


@pytest.mark.asyncio
async def test_bucket_cleanup(cleanup_fixture: CleanupFixture):
"""Test multiple outbox bucket cleanup handling."""
data_repository = cleanup_fixture.joint.data_repository
Expand Down

0 comments on commit cd83923

Please sign in to comment.