You've already forked hotpocket
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
from .accounts import * # noqa F401
|
||||
from .core import * # noqa: F401,F403
|
||||
from .saves import * # noqa: F401,F403
|
||||
from .ui import * # noqa: F401,F403
|
||||
@@ -0,0 +1,48 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# type: ignore
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def account_password():
|
||||
return 'thisisntright'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def account():
|
||||
from hotpocket_backend_testing.factories.accounts import AccountFactory
|
||||
return AccountFactory()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def federated_account():
|
||||
from hotpocket_backend.apps.accounts.models import Account
|
||||
from hotpocket_backend_testing.factories.accounts import AccountFactory
|
||||
|
||||
result: Account = AccountFactory()
|
||||
result.set_unusable_password()
|
||||
result.save()
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def account_with_password(account, account_password):
|
||||
account.set_password(account_password)
|
||||
account.save()
|
||||
|
||||
return account
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inactive_account():
|
||||
from hotpocket_backend_testing.factories.accounts import AccountFactory
|
||||
return AccountFactory(is_active=False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account():
|
||||
from hotpocket_backend_testing.factories.accounts import AccountFactory
|
||||
return AccountFactory()
|
||||
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# type: ignore
|
||||
from __future__ import annotations
|
||||
|
||||
from django.test import Client
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def authenticated_client(client: Client, account) -> Client:
|
||||
client.force_login(account)
|
||||
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def federated_account_client(client: Client, federated_account) -> Client:
|
||||
client.force_login(federated_account)
|
||||
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def account_with_password_client(client: Client, account_with_password):
|
||||
client.force_login(account_with_password)
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inactive_account_client(client: Client, inactive_account) -> Client:
|
||||
client.force_login(inactive_account)
|
||||
|
||||
return client
|
||||
@@ -0,0 +1,2 @@
|
||||
from .association import * # noqa: F401,F403
|
||||
from .save import * # noqa: F401,F403
|
||||
@@ -0,0 +1,165 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from django.utils.timezone import now
|
||||
import pytest
|
||||
|
||||
from hotpocket_soa.dto.associations import AssociationWithTargetOut
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def association_factory(request: pytest.FixtureRequest):
|
||||
default_account = request.getfixturevalue('account')
|
||||
default_target = request.getfixturevalue('save')
|
||||
|
||||
def factory(account=None, target=None, **kwargs):
|
||||
from hotpocket_backend_testing.factories.saves import AssociationFactory
|
||||
|
||||
return AssociationFactory(
|
||||
account_uuid=(
|
||||
account.pk
|
||||
if account is not None
|
||||
else default_account.pk
|
||||
),
|
||||
target=target or default_target,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def association(association_factory):
|
||||
return association_factory()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def association_out(association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deleted_association(association_factory):
|
||||
return association_factory(deleted_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deleted_association_out(deleted_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
deleted_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def archived_association(association_factory):
|
||||
return association_factory(archived_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def archived_association_out(archived_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
archived_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def starred_association(association_factory):
|
||||
return association_factory(starred_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def starred_association_out(starred_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
starred_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_association(association_factory, other_account):
|
||||
return association_factory(account=other_account)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_association_out(other_account_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
other_account_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_deleted_association(association_factory, other_account):
|
||||
return association_factory(account=other_account, deleted_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_deleted_association_out(other_account_deleted_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
other_account_deleted_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_archived_association(association_factory, other_account):
|
||||
return association_factory(account=other_account, archived_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_archived_association_out(other_account_archived_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
other_account_archived_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_starred_association(association_factory, other_account):
|
||||
return association_factory(account=other_account, starred_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_starred_association_out(other_account_starred_association):
|
||||
return AssociationWithTargetOut.model_validate(
|
||||
other_account_starred_association, from_attributes=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def browsable_associations(association,
|
||||
deleted_association,
|
||||
archived_association,
|
||||
starred_association,
|
||||
other_account_association,
|
||||
):
|
||||
return [
|
||||
association,
|
||||
starred_association,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def browsable_association_outs(browsable_associations):
|
||||
return [
|
||||
AssociationWithTargetOut.model_validate(obj, from_attributes=True)
|
||||
for obj
|
||||
in browsable_associations
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def paginatable_associations(association_factory):
|
||||
result = [
|
||||
association_factory()
|
||||
for _ in range(0, 14)
|
||||
]
|
||||
|
||||
return result[::-1]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def paginatable_association_outs(paginatable_associations):
|
||||
return [
|
||||
AssociationWithTargetOut.model_validate(obj, from_attributes=True)
|
||||
for obj
|
||||
in paginatable_associations
|
||||
]
|
||||
@@ -0,0 +1,105 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from django.utils.timezone import now
|
||||
import pytest
|
||||
|
||||
from hotpocket_soa.dto.saves import SaveOut
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save_url_factory():
|
||||
def factory():
|
||||
return f'https://{uuid.uuid4()}.local/'
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save_url(save_url_factory):
|
||||
return save_url_factory()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save_factory(request: pytest.FixtureRequest):
|
||||
default_account = request.getfixturevalue('account')
|
||||
default_url = request.getfixturevalue('save_url')
|
||||
|
||||
def factory(account=None, **kwargs):
|
||||
from hotpocket_backend_testing.factories.saves import SaveFactory
|
||||
|
||||
if 'url' not in kwargs:
|
||||
kwargs['url'] = default_url
|
||||
|
||||
return SaveFactory(
|
||||
account_uuid=(
|
||||
account.pk
|
||||
if account is not None
|
||||
else default_account.pk
|
||||
),
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
return factory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save(save_factory):
|
||||
return save_factory()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save_out(save):
|
||||
return SaveOut.model_validate(save, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_save(save_factory, save_url_factory):
|
||||
return save_factory(url=save_url_factory())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_save_out(other_save):
|
||||
return SaveOut.model_validate(other_save, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def processed_save(save_factory, save_url_factory):
|
||||
return save_factory(url=save_url_factory(), last_processed_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def processed_save_out(processed_save):
|
||||
return SaveOut.model_validate(processed_save, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def netloc_banned_save(save_factory, save_url_factory):
|
||||
return save_factory(url=save_url_factory(), is_netloc_banned=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def netloc_banned_save_out(netloc_banned_save):
|
||||
return SaveOut.model_validate(netloc_banned_save, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deleted_save(save_factory, save_url_factory):
|
||||
return save_factory(url=save_url_factory(), deleted_at=now())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def deleted_save_out(deleted_save):
|
||||
return SaveOut.model_validate(deleted_save, from_attributes=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_save(save_factory, other_account, save_url_factory):
|
||||
return save_factory(account=other_account, url=save_url_factory())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def other_account_save_out(other_account_save):
|
||||
return SaveOut.model_validate(other_account_save, from_attributes=True)
|
||||
@@ -0,0 +1,88 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# type: ignore
|
||||
from __future__ import annotations
|
||||
|
||||
import csv
|
||||
import datetime
|
||||
import io
|
||||
|
||||
import pytest
|
||||
|
||||
from hotpocket_backend_testing.dto.ui import PocketImportSaveSpec
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pocket_import_created_save_spec():
|
||||
return PocketImportSaveSpec.model_validate({
|
||||
'title': 'Ziomek',
|
||||
'url': 'https://www.ziomek.dog/',
|
||||
'time_added': datetime.datetime(
|
||||
1985, 12, 12, 8, 0, 0, 0, tzinfo=datetime.UTC,
|
||||
),
|
||||
'tags': '',
|
||||
'status': 'unread',
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pocket_import_reused_save_spec(save_out):
|
||||
return PocketImportSaveSpec.model_validate({
|
||||
'title': save_out.title,
|
||||
'url': save_out.url,
|
||||
'time_added': datetime.datetime(
|
||||
1987, 10, 3, 8, 0, 0, 0, tzinfo=datetime.UTC,
|
||||
),
|
||||
'tags': '',
|
||||
'status': 'unread',
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pocket_import_other_account_save_spec(other_account_save_out):
|
||||
return PocketImportSaveSpec.model_validate({
|
||||
'title': other_account_save_out.title,
|
||||
'url': other_account_save_out.url,
|
||||
'time_added': datetime.datetime(
|
||||
2019, 12, 6, 8, 0, 0, 0, tzinfo=datetime.UTC,
|
||||
),
|
||||
'tags': '',
|
||||
'status': 'unread',
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pocket_import_banned_netloc_save_spec():
|
||||
return PocketImportSaveSpec.model_validate({
|
||||
'title': 'Nyan Cat! [Official]',
|
||||
'url': 'https://www.youtube.com/watch?v=2yJgwwDcgV8',
|
||||
'time_added': datetime.datetime(
|
||||
2021, 9, 17, 8, 0, 0, 0, tzinfo=datetime.UTC,
|
||||
),
|
||||
'tags': '',
|
||||
'status': 'unread',
|
||||
})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pocket_csv_content(pocket_import_created_save_spec,
|
||||
pocket_import_reused_save_spec,
|
||||
pocket_import_other_account_save_spec,
|
||||
pocket_import_banned_netloc_save_spec,
|
||||
):
|
||||
with io.StringIO() as csv_f:
|
||||
field_names = [
|
||||
'title', 'url', 'time_added', 'tags', 'status',
|
||||
]
|
||||
|
||||
writer = csv.DictWriter(csv_f, field_names, dialect=csv.excel)
|
||||
writer.writeheader()
|
||||
writer.writerows([
|
||||
pocket_import_created_save_spec.dict(),
|
||||
pocket_import_reused_save_spec.dict(),
|
||||
pocket_import_other_account_save_spec.dict(),
|
||||
pocket_import_banned_netloc_save_spec.dict(),
|
||||
])
|
||||
|
||||
csv_f.seek(0)
|
||||
|
||||
yield csv_f.getvalue()
|
||||
Reference in New Issue
Block a user