import pytest from polyfactory.factories.pydantic_factory import ModelFactory from polyfactory.pytest_plugin import register_fixture from secretsanta.domain import Group, IRepo from secretsanta.service import ( CreateGroupService, GetGroupParticipantsService, GetPairService, ) from secretsanta.settings import get_config class TestRepo(IRepo): def __init__(self): self.data = {} async def get(self, group_uuid: str) -> Group | None: return self.data.get(group_uuid) async def create(self, group: Group) -> Group: self.data[group.uuid] = group return group @register_fixture class GroupFactory(ModelFactory[Group]): __model__ = Group @classmethod def participants(cls) -> list[str]: number_of_participants = cls.__random__.randint(2, 10) return [cls.__faker__.name() for _ in range(number_of_participants)] pairs = None @pytest.fixture() def group(group_factory): return group_factory.build() @pytest.fixture def repo(): return TestRepo() @pytest.fixture() def repo_with_data(repo, group): group.pairs = group.pair(group.participants) repo.data[group.uuid] = group return repo @pytest.fixture() def config(): return get_config( s3_bucket_name="foo", s3_secret_access_key="testing", s3_access_key_id="testing", s3_region="us-east-1" ) @pytest.fixture() def create_group_service(repo, config): return CreateGroupService(repo=repo, config=config) @pytest.fixture() def get_participants_service(repo, config): return GetGroupParticipantsService(repo=repo, config=config) @pytest.fixture() def get_pair_service(repo, config): return GetPairService(repo=repo, config=config)