Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,60 @@ omit =
server/settings/components/logging.py


[mypy]
# Mypy configuration:
# https://mypy.readthedocs.io/en/latest/config_file.html
enable_error_code =
truthy-bool,
truthy-iterable,
redundant-expr,
unused-awaitable,
ignore-without-code,
possibly-undefined,
redundant-self,

extra_checks = true

disable_error_code =
literal-required,

enable_incomplete_feature =
Unpack,

allow_redefinition = false
check_untyped_defs = true
disallow_untyped_decorators = true
disallow_any_explicit = false
disallow_any_generics = true
disallow_untyped_calls = true
disallow_incomplete_defs = true
explicit_package_bases = true
ignore_errors = false
ignore_missing_imports = true
implicit_reexport = false
local_partial_types = true
strict_optional = true
strict_equality = true
no_implicit_optional = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unreachable = true
warn_no_return = true

plugins =
mypy_django_plugin.main,
pydantic.mypy

[mypy-server.apps.*.migrations.*]
# Django migrations should not produce any errors (they are tested anyway):
ignore_errors = true

[mypy.plugins.django-stubs]
# Docs: https://github.com/typeddjango/django-stubs
django_settings_module = server.settings
strict_settings = false

[doc8]
# doc8 configuration:
# https://github.com/pycqa/doc8
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
pytest_plugins = [
# Should be the first custom one:
'plugins.django_settings',

# TODO: add your own plugins here!
'plugins.identity.user',
'plugins.service_functions',
]
Empty file removed tests/plugins/__init__.py
Empty file.
Empty file removed tests/plugins/identity/__init__.py
Empty file.
8 changes: 0 additions & 8 deletions tests/plugins/identity/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ def factory(**fields: Unpack[RegistrationData]) -> RegistrationData:
return factory


@pytest.fixture()
def user_registration_data(
registration_data_factory: RegistrationDataFactory,
) -> RegistrationData:
"""Create instance of ordinary user (not staff or admin)."""
return registration_data_factory()


@final
class LoginData(TypedDict, total=False):
"""Represent the login data that is required to authenticate a user."""
Expand Down
33 changes: 33 additions & 0 deletions tests/plugins/service_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random

import pytest
from mimesis.locales import Locale
from mimesis.schema import Field

random_seed = 42


def pytest_configure(config: pytest.Config) -> None:
"""Create or restore random value to be used as seed during tests."""
seed_value = config.getoption('randomly_seed')
default_seed = random.Random().getrandbits(random_seed)
Copy link

@balancy balancy Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не очень логично называть переменную, которую ты используешь в качестве размерности сгенерированного случайного числа, random_seed, т.к. seed у тебя вычисляется дальше. Можно было назвать как-нибудь типа random_seed_length


if seed_value == 'last':
seed = config.cache.get( # type: ignore[union-attr]
'randomly_seed',
default_seed,
)
elif seed_value == 'default':
seed = default_seed
else:
seed = seed_value

config.cache.set('randomly_seed', seed) # type: ignore[union-attr]

config.option.randomly_seed = seed


@pytest.fixture(scope='session')
def field() -> Field:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А, все, увидел, круто =)

"""Random data provider."""
return Field(locale=Locale.EN)
13 changes: 12 additions & 1 deletion tests/test_apps/test_identity/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
from django.test import Client
from django.urls import reverse

from tests.plugins.identity.user import (
from plugins.identity.user import (
RegistrationData,
RegistrationDataFactory,
UserAssertion,
UserDataExtractor,
)


@pytest.fixture()
def registration_data(
registration_data_factory: RegistrationDataFactory,
) -> RegistrationData:
"""Create instance of ordinary user (not staff or admin)."""
return registration_data_factory()


@pytest.mark.parametrize('page', [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

советуют физические пути к url заменять на конструкции reverse('identity:login"), т.к. лучше привизываться к именам, а не к hardcoded путям. Так тесты становятся менее хрупкими

'/identity/login',
'/identity/registration',
])
@pytest.mark.django_db()
def test_identity_pages_unauthenticated(client: Client, page: str) -> None:
"""Test accessibility of identity pages for unauthenticated users."""
response = client.get(page)
Expand All @@ -33,6 +43,7 @@ def test_pictures_pages_unauthenticated(client: Client, page: str) -> None:
assert response.url == '/identity/login?next={0}'.format(page)


@pytest.mark.django_db()
def test_valid_registration(
client: Client,
registration_data: RegistrationData,
Expand Down