parent
5395a56480
commit
8656fc7903
23 changed files with 261 additions and 51 deletions
@ -0,0 +1,19 @@ |
||||
[pytest] |
||||
DJANGO_SETTINGS_MODULE = src.dokumentor.settings.testing |
||||
norecursedirs = env/* docs/* misc/* static/* mysql/* |
||||
|
||||
|
||||
addopts = --flake8 -vv -s |
||||
|
||||
python_files = |
||||
test_*.py |
||||
|
||||
flake8-max-line-length = 99 |
||||
|
||||
# E731 - do not assign a lambda expression, use a def |
||||
# F405 - name may be undefined, or defined from star imports: module |
||||
flake8-ignore = |
||||
*.py E731 F405 |
||||
**/conf/** ALL |
||||
**/migrations/** ALL |
||||
**/templates/** ALL |
||||
@ -1 +0,0 @@ |
||||
# -*- coding: utf-8 -*- |
||||
@ -0,0 +1,26 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import logging |
||||
import dj_database_url |
||||
|
||||
from src.dokumentor.settings.common import * # noqa |
||||
|
||||
DEBUG = True |
||||
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG # noqa |
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' |
||||
PASSWORD_HASHERS = ('django.contrib.auth.hashers.MD5PasswordHasher', ) |
||||
|
||||
DATABASES = { |
||||
'default': dj_database_url.parse(e.get('TEST_DB')), |
||||
} |
||||
|
||||
|
||||
CELERY_TASK_ALWAYS_EAGER = True |
||||
|
||||
# Disable cache during testing |
||||
CACHE_DISABLED = True |
||||
|
||||
LOGGING = {} |
||||
LOCAL_APPS_LOGGERS = {} |
||||
# Disable all logging calls with levels less severe than or equal to CRITICAL |
||||
logging.disable(logging.CRITICAL) |
||||
@ -0,0 +1,76 @@ |
||||
import pytz |
||||
|
||||
import factory |
||||
import factory.fuzzy |
||||
|
||||
from django.contrib.auth import get_user_model |
||||
|
||||
from myauth.models import ConfirmEmail |
||||
from customer.models import UserProfile |
||||
from functools import partial |
||||
|
||||
USER_PASSWORD = 'test' |
||||
|
||||
Faker = partial(factory.Faker, locale='ru_RU') |
||||
|
||||
|
||||
class ProfileFactory(factory.django.DjangoModelFactory): |
||||
profile_type = factory.Iterator([1, 2]) |
||||
boss_surname = Faker('last_name') |
||||
boss_name = Faker('first_name') |
||||
boss_midname = Faker('middle_name') |
||||
inn = factory.Faker('isbn10') |
||||
ogrn = factory.Faker('isbn10') |
||||
okpo = factory.Faker('isbn10') |
||||
glavbuh_surname = Faker('last_name') |
||||
glavbuh_name = Faker('first_name') |
||||
glavbuh_midname = Faker('middle_name') |
||||
address = Faker('address') |
||||
jur_address = Faker('address') |
||||
real_address = Faker('address') |
||||
phone = Faker('phone_number') |
||||
fax = Faker('phone_number') |
||||
email = Faker('email') |
||||
site = Faker('url') |
||||
svid_gos_reg = factory.Faker('isbn10') |
||||
ip_reg_date = factory.Faker('date') |
||||
name = Faker('company') |
||||
full_name = f'{Faker("company_prefix")} {Faker("company")}' |
||||
kpp = factory.Faker('ean8') |
||||
boss_title = Faker('job') |
||||
na_osnovanii = factory.fuzzy.FuzzyChoice(['устава', 'положения']) |
||||
active = True |
||||
confirmed = True |
||||
user_session_key = Faker('sha1') |
||||
|
||||
class Meta: |
||||
model = UserProfile |
||||
|
||||
|
||||
class UserFactory(factory.django.DjangoModelFactory): |
||||
|
||||
first_name = Faker('first_name') |
||||
last_name = Faker('last_name') |
||||
username = Faker('user_name') |
||||
email = Faker('email') |
||||
password = factory.PostGenerationMethodCall('set_password', USER_PASSWORD) |
||||
is_active = True |
||||
is_staff = False |
||||
date_joined = Faker( |
||||
'past_datetime', |
||||
start_date='-30d', |
||||
tzinfo=pytz.UTC |
||||
) |
||||
profile = factory.SubFactory(ProfileFactory) |
||||
|
||||
class Meta: |
||||
model = get_user_model() |
||||
django_get_or_create = ('username',) |
||||
|
||||
|
||||
class ConfirmEmailFactory(factory.django.DjangoModelFactory): |
||||
user = factory.SubFactory(UserFactory) |
||||
is_confirmed = True |
||||
|
||||
class Meta: |
||||
model = ConfirmEmail |
||||
@ -0,0 +1,4 @@ |
||||
# -*- coding: utf-8 -*- |
||||
pytest_plugins = [ |
||||
'src.tests.fixtures.models' |
||||
] |
||||
@ -0,0 +1,13 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import pytest |
||||
from factories.models import UserFactory, ConfirmEmail |
||||
|
||||
|
||||
@pytest.fixture |
||||
def user(): |
||||
return UserFactory() |
||||
|
||||
|
||||
@pytest.fixture |
||||
def confirm_email(): |
||||
return ConfirmEmail() |
||||
@ -0,0 +1,61 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import pytest |
||||
from django.utils import timezone |
||||
from myauth.models import DokUser, ConfirmEmail |
||||
|
||||
from customer.models import UserProfile |
||||
from customer.tasks import delete_not_activated_users |
||||
|
||||
|
||||
@pytest.mark.django_db |
||||
def test_delete_not_activated_users_more_than_five_day(user): |
||||
user.is_active = False |
||||
profile = user.profile |
||||
profile.active = False |
||||
profile.confirmed = False |
||||
profile.created_at = timezone.now() - timezone.timedelta(days=15) |
||||
profile.save() |
||||
user.save() |
||||
ConfirmEmail.objects.get_or_create(user=user) |
||||
|
||||
delete_not_activated_users() |
||||
|
||||
assert DokUser.objects.count() == 0 |
||||
assert UserProfile.objects.count() == 0 |
||||
assert ConfirmEmail.objects.count() == 0 |
||||
|
||||
|
||||
@pytest.mark.django_db |
||||
def test_delete_not_activated_users_equal_five_day(user): |
||||
user.is_active = False |
||||
profile = user.profile |
||||
profile.active = False |
||||
profile.confirmed = False |
||||
profile.created_at = timezone.now() - timezone.timedelta(days=5) |
||||
profile.save() |
||||
user.save() |
||||
ConfirmEmail.objects.get_or_create(user=user) |
||||
|
||||
delete_not_activated_users() |
||||
|
||||
assert DokUser.objects.count() == 0 |
||||
assert UserProfile.objects.count() == 0 |
||||
assert ConfirmEmail.objects.count() == 0 |
||||
|
||||
|
||||
@pytest.mark.django_db |
||||
def test_delete_not_activated_users_less_five_day(user): |
||||
user.is_active = False |
||||
profile = user.profile |
||||
profile.active = False |
||||
profile.confirmed = False |
||||
profile.created_at = timezone.now() - timezone.timedelta(days=4) |
||||
profile.save() |
||||
user.save() |
||||
ConfirmEmail.objects.get_or_create(user=user) |
||||
|
||||
delete_not_activated_users() |
||||
|
||||
assert DokUser.objects.count() == 1 |
||||
assert UserProfile.objects.count() == 1 |
||||
assert ConfirmEmail.objects.count() == 1 |
||||
Loading…
Reference in new issue