Skip to content

Commit

Permalink
Добавил factory boy
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrNazarov committed Dec 20, 2023
1 parent ef7d6c6 commit c56c702
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 12 deletions.
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ repos:
- flake8-isort
- flake8-django

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.0
hooks:
- id: mypy
exclude: migrations/|config/|.*settings(\.py|/)?
additional_dependencies:
- django-stubs
- django-environ
- django-phonenumber-field[phonenumbers]
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.6.0
# hooks:
# - id: mypy
# exclude: migrations/|config/|.*settings(\.py|/)?
# additional_dependencies:
# - django-stubs
# - django-environ
# - django-phonenumber-field[phonenumbers]

- repo: local
hooks:
Expand Down
2 changes: 2 additions & 0 deletions adaptive_hockey_federation/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
NAME_MAX_LENGTH = 256
EMAIL_MAX_LENGTH = 256
QUERY_SET_LENGTH = 15
TEST_USERS_AMOUNT = 3
DB_MESSAGE = 'Данные успешно добавлены!'

ROLE_AGENT = 'agent'
ROLE_MODERATOR = 'moderator'
Expand Down
27 changes: 25 additions & 2 deletions adaptive_hockey_federation/core/management/commands/fill-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
from django.conf import settings
from django.core.management.base import BaseCommand

from adaptive_hockey_federation.core.constants import (
DB_MESSAGE,
ROLE_ADMIN,
ROLE_AGENT,
ROLE_MODERATOR,
TEST_USERS_AMOUNT,
)
from adaptive_hockey_federation.users.factories import UserFactory

ROLES = [ROLE_AGENT, ROLE_MODERATOR, ROLE_ADMIN]


class Command(BaseCommand):
help = "Запуск парсера офисных документов."
help = "Запуск парсера офисных документов, и создание тестовых юзеров."

def handle(self, *args, **options):
def run_parser(self):
"""Запуск парсера офисных документов."""
run_parser = subprocess.getoutput(
f'poetry run parser -r -p {settings.RESOURSES_ROOT}'
)
Expand All @@ -18,3 +30,14 @@ def handle(self, *args, **options):
) as file:
print(run_parser)
file.write(run_parser)

def create_test_users(self):
"""Cоздание тестовых юзеров."""
for role in ROLES:
UserFactory.create_batch(TEST_USERS_AMOUNT, role=role)

def handle(self, *args, **options):
"""Запись данных в БД."""
self.run_parser()
self.create_test_users()
self.stdout.write(self.style.SUCCESS(DB_MESSAGE))
18 changes: 18 additions & 0 deletions adaptive_hockey_federation/users/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import factory
from django.contrib.auth import get_user_model
from factory.django import DjangoModelFactory

User = get_user_model()


class UserFactory(DjangoModelFactory):
"""Фабрика создания тестовых юзеров"""
class Meta:
model = User

first_name = factory.Faker('first_name')
last_name = factory.Faker('last_name')
patronymic = factory.Faker('first_name')
email = factory.Faker('email')
phone = factory.Faker('phone_number')
password = '123456789'
69 changes: 68 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ django-environ = "^0.11.2"
isort = "^5.12.0"
pre-commit = "3.5.0"
django-extensions = "^3.2.3"
factory-boy = "^3.3.0"

[tool.poetry.group.test.dependencies]
flake8 = "^6.1.0"
Expand Down
4 changes: 4 additions & 0 deletions requirements/develop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ django-extensions==3.2.3 ; python_version >= "3.11" and python_version < "4.0"
django-phonenumber-field[phonenumbers]==7.2.0 ; python_version >= "3.11" and python_version < "4.0"
django==4.2.8 ; python_version >= "3.11" and python_version < "4.0"
et-xmlfile==1.1.0 ; python_version >= "3.11" and python_version < "4.0"
factory-boy==3.3.0 ; python_version >= "3.11" and python_version < "4.0"
faker==21.0.0 ; python_version >= "3.11" and python_version < "4.0"
filelock==3.13.1 ; python_version >= "3.11" and python_version < "4.0"
gunicorn==21.2.0 ; python_version >= "3.11" and python_version < "4.0"
identify==2.5.33 ; python_version >= "3.11" and python_version < "4.0"
Expand All @@ -25,8 +27,10 @@ pluggy==1.3.0 ; python_version >= "3.11" and python_version < "4.0"
pre-commit==3.5.0 ; python_version >= "3.11" and python_version < "4.0"
pytest-django==4.7.0 ; python_version >= "3.11" and python_version < "4.0"
pytest==7.4.3 ; python_version >= "3.11" and python_version < "4.0"
python-dateutil==2.8.2 ; python_version >= "3.11" and python_version < "4.0"
pyyaml==6.0.1 ; python_version >= "3.11" and python_version < "4.0"
setuptools==69.0.2 ; python_version >= "3.11" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.11" and python_version < "4.0"
sqlparse==0.4.4 ; python_version >= "3.11" and python_version < "4.0"
types-openpyxl==3.1.0.32 ; python_version >= "3.11" and python_version < "4.0"
typing-extensions==4.9.0 ; python_version >= "3.11" and python_version < "4.0"
Expand Down

0 comments on commit c56c702

Please sign in to comment.