mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-13 05:06:58 +03:00
Run linting with pre-commit on GitLab (#4150)
* Run linting with pre-commit on GitLab * Update tests
This commit is contained in:
parent
52bdda5bc0
commit
eeb02c2198
|
@ -232,7 +232,7 @@ def test_travis_invokes_pytest(cookies, context, use_docker, expected_test_scrip
|
||||||
("y", "docker-compose -f local.yml run django pytest"),
|
("y", "docker-compose -f local.yml run django pytest"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_gitlab_invokes_flake8_and_pytest(
|
def test_gitlab_invokes_precommit_and_pytest(
|
||||||
cookies, context, use_docker, expected_test_script
|
cookies, context, use_docker, expected_test_script
|
||||||
):
|
):
|
||||||
context.update({"ci_tool": "Gitlab", "use_docker": use_docker})
|
context.update({"ci_tool": "Gitlab", "use_docker": use_docker})
|
||||||
|
@ -246,7 +246,9 @@ def test_gitlab_invokes_flake8_and_pytest(
|
||||||
with open(f"{result.project_path}/.gitlab-ci.yml") as gitlab_yml:
|
with open(f"{result.project_path}/.gitlab-ci.yml") as gitlab_yml:
|
||||||
try:
|
try:
|
||||||
gitlab_config = yaml.safe_load(gitlab_yml)
|
gitlab_config = yaml.safe_load(gitlab_yml)
|
||||||
assert gitlab_config["flake8"]["script"] == ["flake8"]
|
assert gitlab_config["precommit"]["script"] == [
|
||||||
|
"pre-commit run --show-diff-on-failure --color=always --all-files"
|
||||||
|
]
|
||||||
assert gitlab_config["pytest"]["script"] == [expected_test_script]
|
assert gitlab_config["pytest"]["script"] == [expected_test_script]
|
||||||
except yaml.YAMLError as e:
|
except yaml.YAMLError as e:
|
||||||
pytest.fail(e)
|
pytest.fail(e)
|
||||||
|
|
|
@ -7,21 +7,26 @@ variables:
|
||||||
POSTGRES_PASSWORD: ''
|
POSTGRES_PASSWORD: ''
|
||||||
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
|
POSTGRES_DB: 'test_{{ cookiecutter.project_slug }}'
|
||||||
POSTGRES_HOST_AUTH_METHOD: trust
|
POSTGRES_HOST_AUTH_METHOD: trust
|
||||||
{% if cookiecutter.use_celery == 'y' -%}
|
{%- if cookiecutter.use_celery == 'y' %}
|
||||||
CELERY_BROKER_URL: 'redis://redis:6379/0'
|
CELERY_BROKER_URL: 'redis://redis:6379/0'
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
flake8:
|
precommit:
|
||||||
stage: lint
|
stage: lint
|
||||||
image: python:3.10-alpine
|
image: python:3.10
|
||||||
|
variables:
|
||||||
|
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
|
||||||
|
cache:
|
||||||
|
paths:
|
||||||
|
- ${PRE_COMMIT_HOME}
|
||||||
before_script:
|
before_script:
|
||||||
- pip install -q flake8
|
- pip install -q pre-commit
|
||||||
script:
|
script:
|
||||||
- flake8
|
- pre-commit run --show-diff-on-failure --color=always --all-files
|
||||||
|
|
||||||
pytest:
|
pytest:
|
||||||
stage: test
|
stage: test
|
||||||
{% if cookiecutter.use_docker == 'y' -%}
|
{%- if cookiecutter.use_docker == 'y' %}
|
||||||
image: docker/compose:1.29.2
|
image: docker/compose:1.29.2
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
@ -34,7 +39,7 @@ pytest:
|
||||||
- docker-compose -f local.yml up -d
|
- docker-compose -f local.yml up -d
|
||||||
script:
|
script:
|
||||||
- docker-compose -f local.yml run django pytest
|
- docker-compose -f local.yml run django pytest
|
||||||
{%- else -%}
|
{%- else %}
|
||||||
image: python:3.10
|
image: python:3.10
|
||||||
tags:
|
tags:
|
||||||
- python
|
- python
|
||||||
|
@ -42,11 +47,8 @@ pytest:
|
||||||
- postgres:{{ cookiecutter.postgresql_version }}
|
- postgres:{{ cookiecutter.postgresql_version }}
|
||||||
variables:
|
variables:
|
||||||
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
|
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- pip install -r requirements/local.txt
|
- pip install -r requirements/local.txt
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- pytest
|
- pytest
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user