-
Notifications
You must be signed in to change notification settings - Fork 0
Some reorganize and clean up #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
|
||
| 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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А, все, увидел, круто =) |
||
| """Random data provider.""" | ||
| return Field(locale=Locale.EN) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', [ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
|
@@ -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, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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