Skip to content

Commit

Permalink
Adapt fixtures to latest hexkit version
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Jun 17, 2024
1 parent 6ef0640 commit cb464ea
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 36 deletions.
29 changes: 10 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,13 @@

"""Setup for testing the access request service."""

import pytest
from hexkit.providers.akafka.testutils import get_kafka_fixture
from hexkit.providers.mongodb.testutils import get_mongodb_fixture

from .fixtures import JointFixture, get_joint_fixture


@pytest.fixture(autouse=True)
def reset_state(joint_fixture: JointFixture):
"""Clear joint_fixture state before tests.
This is a function-level fixture because it needs to run in each test.
"""
joint_fixture.mongodb.empty_collections()


kafka_fixture = get_kafka_fixture("session")
mongodb_fixture = get_mongodb_fixture("session")
joint_fixture = get_joint_fixture("session")
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 .fixtures import joint_fixture # noqa: F401
21 changes: 8 additions & 13 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
generate_jwk,
sign_and_serialize_token,
)
from hexkit.custom_types import PytestScope
from hexkit.providers.akafka.testutils import KafkaFixture
from hexkit.providers.mongodb.testutils import MongoDbFixture
from pytest import fixture
Expand All @@ -38,7 +37,7 @@
"AUTH_CLAIMS_STEWARD",
"fixture_auth_headers_doe",
"fixture_auth_headers_steward",
"get_joint_fixture",
"joint_fixture",
"JointFixture",
"headers_for_token",
]
Expand Down Expand Up @@ -91,8 +90,9 @@ class JointFixture(NamedTuple):
rest_client: AsyncTestClient


async def joint_fixture_function(
mongodb_fixture: MongoDbFixture, kafka_fixture: KafkaFixture
@pytest_asyncio.fixture()
async def joint_fixture(
mongodb: MongoDbFixture, kafka: KafkaFixture
) -> AsyncGenerator[JointFixture, None]:
"""A fixture that embeds all other fixtures for API-level integration testing
Expand All @@ -101,8 +101,8 @@ async def joint_fixture_function(
config = Config(
auth_key=AUTH_KEY_PAIR.export_public(), # pyright: ignore
download_access_url="http://access",
**kafka_fixture.config.model_dump(),
**mongodb_fixture.config.model_dump(),
**kafka.config.model_dump(),
**mongodb.config.model_dump(),
)
async with prepare_core(config=config) as core:
async with (
Expand All @@ -111,12 +111,7 @@ async def joint_fixture_function(
async with AsyncTestClient(app=app) as rest_client:
yield JointFixture(
config=config,
kafka=kafka_fixture,
mongodb=mongodb_fixture,
kafka=kafka,
mongodb=mongodb,
rest_client=rest_client,
)


def get_joint_fixture(scope: PytestScope = "function"):
"""Produce a joint fixture with desired scope"""
return pytest_asyncio.fixture(joint_fixture_function, scope=scope)
2 changes: 1 addition & 1 deletion tests/test_access_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from ars.adapters.outbound.http import AccessGrantsAdapter, AccessGrantsConfig

pytestmark = pytest.mark.asyncio(scope="session")
pytestmark = pytest.mark.asyncio()


DOWNLOAD_ACCESS_URL = "http://test-access:1234"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
fixture_auth_headers_steward,
)

pytestmark = pytest.mark.asyncio(scope="session")
pytestmark = pytest.mark.asyncio()

DATE_NOW = now_as_utc()
ONE_YEAR = timedelta(days=365)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_event_pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)
from ars.core.models import AccessRequest, AccessRequestStatus

pytestmark = pytest.mark.asyncio(scope="session")
pytestmark = pytest.mark.asyncio()

dummy_config = EventPubTranslatorConfig(
access_request_allowed_event_type="access_request_allowed",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from ars.ports.outbound.dao import AccessRequestDaoPort, ResourceNotFoundError
from ars.ports.outbound.event_pub import EventPublisherPort

pytestmark = pytest.mark.asyncio(scope="session")
pytestmark = pytest.mark.asyncio()

ONE_HOUR = timedelta(seconds=60 * 60)
ONE_YEAR = timedelta(days=365)
Expand Down

0 comments on commit cb464ea

Please sign in to comment.