You've already forked hotpocket
BTHLABS-58: Share Extension in Apple Apps
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
from .access_token import AccessTokenFactory # noqa: F401,F403
|
||||
from .account import AccountFactory # noqa: F401,F403
|
||||
from .auth_key import AuthKeyFactory # noqa: F401,F403
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
import factory
|
||||
|
||||
from hotpocket_backend.apps.accounts.models import AuthKey
|
||||
|
||||
|
||||
class AuthKeyFactory(factory.django.DjangoModelFactory):
|
||||
account_uuid = None
|
||||
key = factory.LazyFunction(lambda: str(uuid.uuid4()))
|
||||
consumed_at = None
|
||||
|
||||
class Meta:
|
||||
model = AuthKey
|
||||
@@ -1,3 +1,4 @@
|
||||
from .access_token import * # noqa: F401,F403
|
||||
from .account import * # noqa: F401,F403
|
||||
from .apps import * # noqa: F401,F403
|
||||
from .auth_key import * # noqa: F401,F403
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# type: ignore
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
|
||||
from django.utils.timezone import get_current_timezone, now
|
||||
import pytest
|
||||
|
||||
from hotpocket_soa.dto.accounts import AuthKeyOut
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_key_factory(request: pytest.FixtureRequest):
|
||||
default_account = request.getfixturevalue('account')
|
||||
|
||||
def factory(account=None, **kwargs):
|
||||
from hotpocket_backend_testing.factories.accounts import AuthKeyFactory
|
||||
|
||||
return AuthKeyFactory(
|
||||
account_uuid=(
|
||||
account.pk
|
||||
if account is not None
|
||||
else default_account.pk
|
||||
),
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_key(auth_key_factory):
|
||||
return auth_key_factory()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def auth_key_out(auth_key):
|
||||
return AuthKeyOut.model_validate(auth_key, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deleted_auth_key(auth_key_factory):
|
||||
return auth_key_factory(deleted_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deleted_auth_key_out(deleted_auth_key):
|
||||
return AuthKeyOut.model_validate(deleted_auth_key, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def expired_auth_key(auth_key_factory):
|
||||
result = auth_key_factory()
|
||||
result.created_at = datetime.datetime(
|
||||
1987, 10, 3, 8, 0, 0, tzinfo=get_current_timezone(),
|
||||
)
|
||||
result.save()
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def expired_auth_key_out(expired_auth_key):
|
||||
return AuthKeyOut.model_validate(expired_auth_key, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def consumed_auth_key(auth_key_factory):
|
||||
return auth_key_factory(consumed_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def consumed_auth_key_out(consumed_auth_key):
|
||||
return AuthKeyOut.model_validate(consumed_auth_key, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_auth_key(auth_key_factory):
|
||||
return auth_key_factory()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_auth_key_out(other_auth_key):
|
||||
return AuthKeyOut.model_validate(other_auth_key, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inactive_account_auth_key(auth_key_factory, inactive_account):
|
||||
return auth_key_factory(account=inactive_account)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inactive_account_auth_key_out(auth_key):
|
||||
return AuthKeyOut.model_validate(
|
||||
inactive_account_auth_key, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_auth_key(auth_key_factory, other_account):
|
||||
return auth_key_factory(account=other_account)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_auth_key_out(other_account_auth_key):
|
||||
return AuthKeyOut.model_validate(
|
||||
other_account_auth_key, from_attributes=True,
|
||||
)
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import csv
|
||||
import datetime
|
||||
import io
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -86,3 +87,23 @@ def pocket_csv_content(pocket_import_created_save_spec,
|
||||
csv_f.seek(0)
|
||||
|
||||
yield csv_f.getvalue()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def extension_auth_source_extension():
|
||||
return 'HotPocketExtension'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def extension_auth_source_desktop():
|
||||
return 'HotPocketDesktop'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def extension_auth_source_mobile():
|
||||
return 'HotPocketMobile'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def extension_auth_session_token():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from .access_tokens import AccessTokensTestingService # noqa: F401
|
||||
from .accounts import AccountsTestingService # noqa: F401
|
||||
from .auth_key import AuthKeysTestingService # noqa: F401
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from hotpocket_backend.apps.accounts.models import AuthKey
|
||||
|
||||
|
||||
class AuthKeysTestingService:
|
||||
def assert_created(self,
|
||||
*,
|
||||
key: str,
|
||||
account_uuid: uuid.UUID,
|
||||
):
|
||||
auth_key = AuthKey.objects.get(key=key)
|
||||
assert auth_key.account_uuid == account_uuid
|
||||
|
||||
assert auth_key.created_at is not None
|
||||
assert auth_key.updated_at is not None
|
||||
Reference in New Issue
Block a user