BTHLABS-50: Safari Web extension

Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl>
Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
This commit is contained in:
2025-09-08 18:11:36 +00:00
committed by Tomek Wójcik
parent ffecf780ee
commit b6d02dbe78
184 changed files with 7536 additions and 163 deletions

View File

@@ -0,0 +1,2 @@
from .access_token import AccessTokenFactory # noqa: F401,F403
from .account import AccountFactory # noqa: F401,F403

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import uuid
import factory
from hotpocket_backend.apps.accounts.models import AccessToken
def AccessTokenMetaFactory() -> dict:
return {
'platform': 'MacIntel',
'version': '1987.10.03',
}
class AccessTokenFactory(factory.django.DjangoModelFactory):
account_uuid = None
key = factory.LazyFunction(lambda: str(uuid.uuid4()))
origin = factory.LazyFunction(
lambda: f'safari-web-extension//{uuid.uuid4()}',
)
meta = factory.LazyFunction(AccessTokenMetaFactory)
class Meta:
model = AccessToken

View File

@@ -0,0 +1,2 @@
from .access_token import * # noqa: F401,F403
from .account import * # noqa: F401,F403

View File

@@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
# type: ignore
from __future__ import annotations
from django.utils.timezone import now
import pytest
from hotpocket_soa.dto.accounts import AccessTokenOut
@pytest.fixture
def access_token_factory(request: pytest.FixtureRequest):
default_account = request.getfixturevalue('account')
def factory(account=None, **kwargs):
from hotpocket_backend_testing.factories.accounts import (
AccessTokenFactory,
)
return AccessTokenFactory(
account_uuid=(
account.pk
if account is not None
else default_account.pk
),
**kwargs,
)
return factory
@pytest.fixture
def access_token(access_token_factory):
return access_token_factory()
@pytest.fixture
def access_token_out(access_token):
return AccessTokenOut.model_validate(access_token, from_attributes=True)
@pytest.fixture
def deleted_access_token(access_token_factory):
return access_token_factory(deleted_at=now())
@pytest.fixture
def deleted_access_token_out(deleted_access_token):
return AccessTokenOut.model_validate(deleted_access_token, from_attributes=True)
@pytest.fixture
def other_access_token(access_token_factory):
return access_token_factory()
@pytest.fixture
def other_access_token_out(other_access_token):
return AccessTokenOut.model_validate(other_access_token, from_attributes=True)
@pytest.fixture
def inactive_account_access_token(access_token_factory, inactive_account):
return access_token_factory(account=inactive_account)
@pytest.fixture
def inactive_account_access_token_out(access_token):
return AccessTokenOut.model_validate(
inactive_account_access_token, from_attributes=True,
)
@pytest.fixture
def other_account_access_token(access_token_factory, other_account):
return access_token_factory(account=other_account)
@pytest.fixture
def other_account_access_token_out(other_account_access_token):
return AccessTokenOut.model_validate(
other_account_access_token, from_attributes=True,
)
@pytest.fixture
def browsable_access_tokens(access_token,
other_access_token,
other_account_access_token,
):
return [
access_token,
other_access_token,
]
@pytest.fixture
def browsable_access_token_outs(browsable_access_tokens):
return [
AccessTokenOut.model_validate(obj, from_attributes=True)
for obj
in browsable_access_tokens
]
@pytest.fixture
def paginatable_access_tokens(access_token_factory):
result = [
access_token_factory()
for _ in range(0, 12)
]
return result[::-1]
@pytest.fixture
def paginatable_access_token_outs(paginatable_access_tokens):
return [
AccessTokenOut.model_validate(obj, from_attributes=True)
for obj
in paginatable_access_tokens
]

View File

@@ -0,0 +1,2 @@
from .access_tokens import AccessTokensTestingService # noqa: F401
from .accounts import AccountsTestingService # noqa: F401

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import typing
import uuid
from hotpocket_backend.apps.accounts.models import AccessToken
class AccessTokensTestingService:
def assert_created(self,
*,
key: str,
account_uuid: uuid.UUID,
origin: str,
meta: dict,
):
access_token = AccessToken.objects.get(key=key)
assert access_token.account_uuid == account_uuid
assert access_token.origin == origin
assert access_token.meta == meta
assert access_token.created_at is not None
assert access_token.updated_at is not None
def assert_deleted(self, *, pk: uuid.UUID, reference: typing.Any = None):
association = AccessToken.objects.get(pk=pk)
assert association.deleted_at is not None
if reference is not None:
assert association.updated_at > reference.updated_at
def assert_not_deleted(self, *, pk: uuid.UUID, reference: typing.Any = None):
association = AccessToken.objects.get(pk=pk)
assert association.deleted_at is None
if reference is not None:
assert association.updated_at == reference.updated_at