Skip to content
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

2021.06 Cumulative update #48

Merged
Merged
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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
working_directory: ~/project
docker:
- image: circleci/python:3.8.6
- image: circleci/python:3.9.5
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASS
Expand All @@ -17,14 +17,14 @@ jobs:
AWESOME_DATABASE_URL: postgresql://postgres:awesome_password@localhost/awesome_test_db
AWESOME_CELERY_BROKER: redis://localhost:6379/1
AWESOME_CELERY_TASK_ALWAYS_EAGER: on
- image: postgres:12.4
- image: postgres:13.3
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASS
environment:
POSTGRES_DB: awesome_test_db
POSTGRES_PASSWORD: awesome_password
- image: redis:6.0.6
- image: redis:6.2.4
auth:
username: $DOCKERHUB_USER
password: $DOCKERHUB_PASS
Expand Down
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
Create python virtual environment. We recommend to use [pyenv](https://github.com/pyenv/pyenv) & [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv):

```bash
pyenv install 3.8.6
pyenv virtualenv 3.8.6 my_project
pyenv install 3.9.5
pyenv virtualenv 3.9.5 my_project
pyenv activate my_project
```

Expand All @@ -42,4 +42,44 @@ cd /path/to/directory
cookiecutter https://github.com/django-stars/backend-skeleton
```

Answer the questions.
Answer the questions in wizard.

## Steps after project setup

Install tools required to build a dependencies list:

```bash
pip install -U fabric invoke pip pip-tools
```

Compile dependencies list:

```bash
fab pip.compile
```

Install dependencies:

```bash
fab pip.sync
```

Run backing services:

```bash
fab compose.up -d
```

Copy `.env` file from example file and set your settings:

```bash
cp ./api/.env.example ./api/.env
```

Run migrations:

```bash
./api/manage.py migrate
```

Start building your awesome project!
5 changes: 3 additions & 2 deletions contrib/docker/docker-compose-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ services:
database:
environment:
POSTGRES_DB: awesome_db
image: postgres:12.1
POSTGRES_PASSWORD: awesome_password_1
image: postgres:13.3
ports:
- 127.0.0.1:5432:5432/tcp
restart: always
volumes:
- pg_data:/var/lib/postgresql/data:rw
redis:
image: redis:5.0.7
image: redis:6.2.4
ports:
- 127.0.0.1:6379:6379/tcp
restart: always
Expand Down
6 changes: 3 additions & 3 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"project_name": "awesome",
"project_slug": "{{ cookiecutter.project_name.lower()|replace(' ', '_')|replace('-', '_')|replace('.', '_')|trim() }}",
"domain_name": "example.com",
"python_version": "3.8.6",
"python_version": "3.9.5",
"database_password": "awesome_password_1",
"postgresql_version": "12.4",
"redis_version": "6.0.6"
"postgresql_version": "13.3",
"redis_version": "6.2.4"
}
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self):
"radon",
"safety",
)
self._dev_requirements_with_versions_do_not_need_to_be_pinned = ("black==19.10b0",)
self._dev_requirements_with_versions_do_not_need_to_be_pinned = ("black==21.6b0",)

@staticmethod
def _get_package_data(package): # pragma: no cover
Expand Down
18 changes: 9 additions & 9 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cookiecutter==1.7.2
coverage==5.3
docker-compose==1.27.4
invoke==1.4.1
packaging==20.4
pip-tools==5.3.1
pytest==6.1.1
pytest-cov==2.10.1
pytest-mock==3.3.1
cookiecutter==1.7.3
coverage==5.5
docker-compose==1.29.2
invoke==1.5.0
packaging==20.9
pip-tools==6.2.0
pytest==6.2.4
pytest-cov==2.12.1
pytest-mock==3.6.1
487 changes: 262 additions & 225 deletions requirements.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_project(ctx):
"AWESOME_EMAIL_BACKEND=django.core.mail.backends.dummy.EmailBackend",
"AWESOME_USE_SENTRY=off",
"AWESOME_DEBUG=off",
"AWESOME_DATABASE_URL=postgresql://postgres@localhost/awesome_test_db",
"AWESOME_DATABASE_URL=postgresql://postgres:awesome_password_1@localhost/awesome_test_db",
"AWESOME_CELERY_BROKER=redis://localhost:6379/1",
"AWESOME_CELERY_TASK_ALWAYS_EAGER=on",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generate_requirements_in_file_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_get_dev_packages(mocker):
"Pygments==<mocked>",
"Werkzeug==<mocked>",
"bandit==<mocked>",
"black==19.10b0",
"black==21.6b0",
"coverage==<mocked>",
"django-debug-toolbar==<mocked>",
"django-extensions==<mocked>",
Expand Down
5 changes: 5 additions & 0 deletions {{ cookiecutter.project_slug }}/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ jobs:
- run:
name: Wait for Postgres
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Check for uncreated migrations
command: |
. .env/bin/activate
./api/manage.py makemigrations --check --dry-run
- run:
name: Run tests
command: |
Expand Down
20 changes: 14 additions & 6 deletions {{ cookiecutter.project_slug }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.1
rev: v4.0.1
hooks:
- id: check-added-large-files
args: ['--maxkb=10000']
Expand All @@ -18,13 +18,13 @@ repos:
- id: pretty-format-json
args: ['--autofix', '--indent 2', ]
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 21.6b0
hooks:
- id: black
args: [.]
pass_filenames: false
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.4.2
rev: v5.9.1
hooks:
- id: isort
- repo: https://github.com/gvanderest/pylama-pre-commit
Expand All @@ -43,20 +43,28 @@ repos:
- id: bandit
args: ['--skip', 'B101']
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.4.1
rev: v1.9.0
hooks:
- id: python-check-blanket-noqa
- id: python-no-log-warn
- id: python-use-type-annotations
- id: rst-backticks
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.1.0
rev: v1.2.1
hooks:
- id: python-safety-dependencies-check
entry: safety
args: [check]
files: ./api/requirements-build.txt
- repo: https://github.com/codespell-project/codespell
rev: v1.16.0
rev: v2.1.0
hooks:
- id: codespell
- repo: local
hooks:
- id: migrations-check
language: system
name: Check for uncreated migrations.
entry: sh -c "./api/manage.py makemigrations --check --dry-run"
files: models/*.*\.py$
stages: [commit]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_validate_old_password_success(change_password_serializer_request, mocke
result = serializer.validate_old_password(OLD_PASSWORD)

assert result == OLD_PASSWORD
assert mocked_check_password.called_once_with(OLD_PASSWORD)
mocked_check_password.assert_called_once_with(change_password_serializer_request.user, OLD_PASSWORD)


@pytest.mark.django_db
Expand All @@ -41,7 +41,7 @@ def test_validate_new_password_success(change_password_serializer_request, mocke
result = serializer.validate_new_password(NEW_PASSWORD)

assert result == NEW_PASSWORD
assert mocked_validate_password.called_once_with(NEW_PASSWORD)
mocked_validate_password.assert_called_once_with(NEW_PASSWORD, user=change_password_serializer_request.user)


@pytest.mark.django_db
Expand All @@ -57,7 +57,7 @@ def test_validate_old_password_failure(change_password_serializer_request, mocke
serializer.validate_old_password(OLD_PASSWORD)

assert "test_validate_old_password_failure" in str(exc.value)
assert mocked_check_password.called_once_with(OLD_PASSWORD)
mocked_check_password.assert_called_once_with(change_password_serializer_request.user, OLD_PASSWORD)


@pytest.mark.django_db
Expand All @@ -73,7 +73,7 @@ def test_validate_new_password_failure(change_password_serializer_request, mocke
serializer.validate_new_password(OLD_PASSWORD)

assert "test_validate_new_password_failure" in str(exc.value)
assert mocked_validate_password.called_once_with(OLD_PASSWORD)
mocked_validate_password.assert_called_once_with(OLD_PASSWORD, user=change_password_serializer_request.user)


@pytest.mark.django_db
Expand All @@ -89,4 +89,4 @@ def test_save(user_account, mocker):
serializer.is_valid()
serializer.save()

assert mocked_change_password.called_once_with("BAR")
mocked_change_password.assert_called_once_with(None, NEW_PASSWORD)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_validate_password_success(mocker):
result = serializer.validate_password(NEW_PASSWORD)

assert result == NEW_PASSWORD
assert mocked_validate_password.called_once_with(NEW_PASSWORD)
mocked_validate_password.assert_called_once_with(NEW_PASSWORD)


def test_validate_password_failure(mocker):
Expand All @@ -29,7 +29,7 @@ def test_validate_password_failure(mocker):
with pytest.raises(ValidationError):
serializer.validate_password(NEW_PASSWORD)

assert mocked_validate_password.called_once_with(NEW_PASSWORD)
mocked_validate_password.assert_called_once_with(NEW_PASSWORD)


def test_save_success(mocker):
Expand All @@ -40,7 +40,7 @@ def test_save_success(mocker):
serializer.is_valid()
serializer.save()

assert mocked_reset_password.called_once_with(RESET_PASSWORD_SIGNATURE, NEW_PASSWORD)
mocked_reset_password.assert_called_once_with(RESET_PASSWORD_SIGNATURE, NEW_PASSWORD)


def test_save_failure(mocker):
Expand All @@ -54,4 +54,4 @@ def test_save_failure(mocker):
with pytest.raises(ValidationError):
serializer.save()

assert mocked_reset_password.called_once_with(RESET_PASSWORD_SIGNATURE, NEW_PASSWORD)
mocked_reset_password.assert_called_once_with(RESET_PASSWORD_SIGNATURE, NEW_PASSWORD)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def test_save(mocker):
serializer.is_valid()
serializer.save()

assert mocked_send_reset_password_link.called_once_with(email)
mocked_send_reset_password_link.assert_called_once_with(email)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

CELERY_TASK_ALWAYS_EAGER = env.bool("{{ cookiecutter.project_slug | upper() }}_CELERY_TASK_ALWAYS_EAGER", default=False)
CELERY_BROKER_URL = env.str("{{ cookiecutter.project_slug | upper() }}_CELERY_BROKER", default="redis://redis:6379/1")
CELERY_RESULT_BACKEND = env.str("{{ cookiecutter.project_slug | upper() }}_CELERY_RESULT_BACKEND", default="rpc://")

CELERY_ACCEPT_CONTENT = ["application/json"]
CELERY_TASK_SERIALIZER = CELERY_RESULT_SERIALIZER = "json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

USE_SENTRY = env.bool("{{ cookiecutter.project_slug | upper() }}_USE_SENTRY", default=True)
if USE_SENTRY: # pragma: no cover
SENTRY_DSN = env.str("{{ cookiecutter.project_slug | upper() }}_SENTRY_DSN")
SENTRY_ENVIRONMENT = env.str("{{ cookiecutter.project_slug | upper() }}_SENTRY_ENVIRONMENT")
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration()], environment=SENTRY_ENVIRONMENT)
sentry_kwargs = {
"dsn": env.str("{{ cookiecutter.project_slug | upper() }}_SENTRY_DSN"),
"environment": env.str("{{ cookiecutter.project_slug | upper() }}_SENTRY_ENVIRONMENT"),
"integrations": [DjangoIntegration()],
Copy link
Contributor

Choose a reason for hiding this comment

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

We may add Celery integration as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just doing it on my project. Will do it as a separate PR to skeleton.

}
sentry_sdk.init(**sentry_kwargs) # pylint: disable=abstract-class-instantiated
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def rel(*path):
"django_filters",
"drf_yasg",
# our apps
"{{ cookiecutter.project_slug }}.apps.common.apps.CommonConfig",
"{{ cookiecutter.project_slug }}.apps.accounts.apps.AccountConfig",
"{{ cookiecutter.project_slug }}.apps.common",
"{{ cookiecutter.project_slug }}.apps.accounts",
] + env.list("{{ cookiecutter.project_slug | upper() }}_DEV_INSTALLED_APPS", default=[])

MIDDLEWARE = [
Expand Down
2 changes: 1 addition & 1 deletion {{ cookiecutter.project_slug }}/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fab clean-pyc
Run tests:

```bash
fab test.run
fab test
```

Check Python formatting with [black](https://black.readthedocs.io/en/stable/):
Expand Down
11 changes: 8 additions & 3 deletions {{ cookiecutter.project_slug }}/fabric_scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,16 @@ def test_pylama(ctx):
with ctx.cd(project_path("api")):
ctx.run("pylama", pty=True, replace_env=False)


@task()
def test_pylint(ctx):
with ctx.cd(project_path("api")):
ctx.run("pylint --ignore=tests {{ cookiecutter.project_slug }}", pty=True, replace_env=False)
pylint_command_args = [
"pylint",
"--django-settings-module={{ cookiecutter.project_slug }}.settings",
"--ignore=tests",
"{{ cookiecutter.project_slug }}",
]
ctx.run(" ".join(pylint_command_args), pty=True, replace_env=False)


@task()
Expand All @@ -83,7 +88,7 @@ def test_all(ctx):


test_collection = Collection("test")
test_collection.add_task(test_run, name="run")
test_collection.add_task(test_run, name="run", default=True)
test_collection.add_task(test_all, name="all")
test_collection.add_task(test_black_check, name="black")
test_collection.add_task(test_black_apply, name="black-apply")
Expand Down