From c56c702ab0f6cc3ababe0b036127136680e56731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=82=D1=80=20=D0=9D=D0=B0=D0=B7=D0=B0=D1=80?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Wed, 20 Dec 2023 21:18:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20fa?= =?UTF-8?q?ctory=20boy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 18 ++--- adaptive_hockey_federation/core/constants.py | 2 + .../core/management/commands/fill-db.py | 27 +++++++- adaptive_hockey_federation/users/factories.py | 18 +++++ poetry.lock | 69 ++++++++++++++++++- pyproject.toml | 1 + requirements/develop.txt | 4 ++ 7 files changed, 127 insertions(+), 12 deletions(-) create mode 100644 adaptive_hockey_federation/users/factories.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55b13fc4..af2198ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/adaptive_hockey_federation/core/constants.py b/adaptive_hockey_federation/core/constants.py index 03dd0722..840485f4 100644 --- a/adaptive_hockey_federation/core/constants.py +++ b/adaptive_hockey_federation/core/constants.py @@ -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' diff --git a/adaptive_hockey_federation/core/management/commands/fill-db.py b/adaptive_hockey_federation/core/management/commands/fill-db.py index 092b38d7..d1710300 100644 --- a/adaptive_hockey_federation/core/management/commands/fill-db.py +++ b/adaptive_hockey_federation/core/management/commands/fill-db.py @@ -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}' ) @@ -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)) diff --git a/adaptive_hockey_federation/users/factories.py b/adaptive_hockey_federation/users/factories.py new file mode 100644 index 00000000..0f7f56cf --- /dev/null +++ b/adaptive_hockey_federation/users/factories.py @@ -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' diff --git a/poetry.lock b/poetry.lock index 74474dc5..ca82e550 100644 --- a/poetry.lock +++ b/poetry.lock @@ -302,6 +302,38 @@ files = [ {file = "et_xmlfile-1.1.0.tar.gz", hash = "sha256:8eb9e2bc2f8c97e37a2dc85a09ecdcdec9d8a396530a6d5a33b30b9a92da0c5c"}, ] +[[package]] +name = "factory-boy" +version = "3.3.0" +description = "A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby." +optional = false +python-versions = ">=3.7" +files = [ + {file = "factory_boy-3.3.0-py2.py3-none-any.whl", hash = "sha256:a2cdbdb63228177aa4f1c52f4b6d83fab2b8623bf602c7dedd7eb83c0f69c04c"}, + {file = "factory_boy-3.3.0.tar.gz", hash = "sha256:bc76d97d1a65bbd9842a6d722882098eb549ec8ee1081f9fb2e8ff29f0c300f1"}, +] + +[package.dependencies] +Faker = ">=0.7.0" + +[package.extras] +dev = ["Django", "Pillow", "SQLAlchemy", "coverage", "flake8", "isort", "mongoengine", "sqlalchemy-utils", "tox", "wheel (>=0.32.0)", "zest.releaser[recommended]"] +doc = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-spelling"] + +[[package]] +name = "faker" +version = "21.0.0" +description = "Faker is a Python package that generates fake data for you." +optional = false +python-versions = ">=3.8" +files = [ + {file = "Faker-21.0.0-py3-none-any.whl", hash = "sha256:ff61cca42547795bee8a11319792a8fee6d0f0cd191e831f7f3050c5851fcd8a"}, + {file = "Faker-21.0.0.tar.gz", hash = "sha256:2d8a350e952225a145307d7461881c44a1c9320e90fbe8bd903d5947f133f3ec"}, +] + +[package.dependencies] +python-dateutil = ">=2.4" + [[package]] name = "filelock" version = "3.13.1" @@ -831,6 +863,20 @@ pytest = ">=7.0.0" docs = ["sphinx", "sphinx-rtd-theme"] testing = ["Django", "django-configurations (>=2.0)"] +[[package]] +name = "python-dateutil" +version = "2.8.2" +description = "Extensions to the standard Python datetime module" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +files = [ + {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"}, + {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"}, +] + +[package.dependencies] +six = ">=1.5" + [[package]] name = "python-docx" version = "1.1.0" @@ -858,6 +904,7 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -865,8 +912,15 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, + {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, + {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, + {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -883,6 +937,7 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -890,6 +945,7 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -932,6 +988,17 @@ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +[[package]] +name = "six" +version = "1.16.0" +description = "Python 2 and 3 compatibility utilities" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + [[package]] name = "sqlparse" version = "0.4.4" @@ -1121,4 +1188,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "a4cf39f0df23459975d07dabbd5f677040103f3ce971823cd8dfd84d770a2a02" +content-hash = "f3f5c6cdc6d7634b6dc4c3f2d6931e48ea36bfbb899cc852fa2c6a18e61beebd" diff --git a/pyproject.toml b/pyproject.toml index 8f02fcb4..ad133afa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/requirements/develop.txt b/requirements/develop.txt index b68d59e9..683927a3 100644 --- a/requirements/develop.txt +++ b/requirements/develop.txt @@ -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" @@ -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"