mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-22 09:36:52 +03:00
pytest.parametrized test for generating CI
* Removed celerybeat start's postgres_ready() for new PR for closer inspection and further review. Travis and GitLab CI reflect changes
This commit is contained in:
parent
25cd8ea72b
commit
d2285d9e2d
|
@ -170,8 +170,12 @@ def test_black_passes(cookies, context_override):
|
|||
pytest.fail(e.stdout.decode())
|
||||
|
||||
|
||||
def test_travis_invokes_pytest(cookies, context):
|
||||
context.update({"ci_tool": "Travis"})
|
||||
@pytest.mark.parametrize(
|
||||
["use_docker", "expected_test_script"],
|
||||
[("n", "pytest"), ("y", "docker-compose -f local.yml run django pytest"),],
|
||||
)
|
||||
def test_travis_invokes_pytest(cookies, context, use_docker, expected_test_script):
|
||||
context.update({"ci_tool": "Travis", "use_docker": use_docker})
|
||||
result = cookies.bake(extra_context=context)
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
@ -183,19 +187,19 @@ def test_travis_invokes_pytest(cookies, context):
|
|||
try:
|
||||
yml = yaml.load(travis_yml, Loader=yaml.FullLoader)["jobs"]["include"]
|
||||
assert yml[0]["script"] == ["flake8"]
|
||||
|
||||
if context.get("use_docker") == "y":
|
||||
assert yml[1]["script"] == [
|
||||
"docker-compose -f local.yml run django pytest"
|
||||
]
|
||||
else:
|
||||
assert yml[1]["script"] == ["pytest"]
|
||||
assert yml[1]["script"] == [expected_test_script]
|
||||
except yaml.YAMLError as e:
|
||||
pytest.fail(e)
|
||||
pytest.fail(str(e))
|
||||
|
||||
|
||||
def test_gitlab_invokes_flake8_and_pytest(cookies, context):
|
||||
context.update({"ci_tool": "Gitlab"})
|
||||
@pytest.mark.parametrize(
|
||||
["use_docker", "expected_test_script"],
|
||||
[("n", "pytest"), ("y", "docker-compose -f local.yml run django pytest"),],
|
||||
)
|
||||
def test_gitlab_invokes_flake8_and_pytest(
|
||||
cookies, context, use_docker, expected_test_script
|
||||
):
|
||||
context.update({"ci_tool": "Gitlab", "use_docker": use_docker})
|
||||
result = cookies.bake(extra_context=context)
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
@ -207,7 +211,7 @@ def test_gitlab_invokes_flake8_and_pytest(cookies, context):
|
|||
try:
|
||||
gitlab_config = yaml.load(gitlab_yml, Loader=yaml.FullLoader)
|
||||
assert gitlab_config["flake8"]["script"] == ["flake8"]
|
||||
assert gitlab_config["pytest"]["script"] == ["pytest"]
|
||||
assert gitlab_config["pytest"]["script"] == [expected_test_script]
|
||||
except yaml.YAMLError as e:
|
||||
pytest.fail(e)
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ pytest:
|
|||
- docker
|
||||
before_script:
|
||||
- docker-compose -f local.yml build
|
||||
# Ensure celerybeat does not crash due to non-existent tables
|
||||
- docker-compose -f local.yml run --rm django python manage.py migrate
|
||||
- docker-compose -f local.yml up -d
|
||||
script:
|
||||
- docker-compose -f local.yml run django pytest
|
||||
|
|
|
@ -20,6 +20,8 @@ jobs:
|
|||
- docker-compose -v
|
||||
- docker -v
|
||||
- docker-compose -f local.yml build
|
||||
# Ensure celerybeat does not crash due to non-existent tables
|
||||
- docker-compose -f local.yml run --rm django python manage.py migrate
|
||||
- docker-compose -f local.yml up -d
|
||||
script:
|
||||
- "docker-compose -f local.yml run django pytest"
|
||||
|
|
|
@ -5,41 +5,4 @@ set -o nounset
|
|||
|
||||
|
||||
rm -f './celerybeat.pid'
|
||||
|
||||
postgres_ready() {
|
||||
python << END
|
||||
import sys
|
||||
import psycopg2
|
||||
try:
|
||||
conn = psycopg2.connect(
|
||||
dbname="${POSTGRES_DB}",
|
||||
user="${POSTGRES_USER}",
|
||||
password="${POSTGRES_PASSWORD}",
|
||||
host="${POSTGRES_HOST}",
|
||||
port="${POSTGRES_PORT}",
|
||||
)
|
||||
# Check if table exists yet.
|
||||
# If not, wait for docker-compose up to migrate all tables.
|
||||
cur = conn.cursor()
|
||||
cur.execute(
|
||||
"select exists(select * from information_schema.tables where table_name=%s)",
|
||||
('django_celery_beat_periodictask',)
|
||||
)
|
||||
if cur.fetchone()[0] == 1:
|
||||
cur.close()
|
||||
sys.exit(0)
|
||||
else:
|
||||
cur.close()
|
||||
sys.exit(-1)
|
||||
except psycopg2.OperationalError:
|
||||
sys.exit(-1)
|
||||
|
||||
END
|
||||
}
|
||||
until postgres_ready; do
|
||||
>&2 echo 'Waiting for celerybeat models to be migrated...'
|
||||
sleep 1
|
||||
done
|
||||
>&2 echo 'PostgreSQL is ready'
|
||||
|
||||
celery -A config.celery_app beat -l INFO
|
||||
|
|
|
@ -4,41 +4,5 @@ set -o errexit
|
|||
set -o pipefail
|
||||
set -o nounset
|
||||
|
||||
postgres_ready() {
|
||||
python << END
|
||||
import sys
|
||||
import psycopg2
|
||||
try:
|
||||
conn = psycopg2.connect(
|
||||
dbname="${POSTGRES_DB}",
|
||||
user="${POSTGRES_USER}",
|
||||
password="${POSTGRES_PASSWORD}",
|
||||
host="${POSTGRES_HOST}",
|
||||
port="${POSTGRES_PORT}",
|
||||
)
|
||||
# Check if table exists yet.
|
||||
# If not, wait for docker-compose up to migrate all tables.
|
||||
cur = conn.cursor()
|
||||
cur.execute(
|
||||
"select exists(select * from information_schema.tables where table_name=%s)",
|
||||
('django_celery_beat_periodictask',)
|
||||
)
|
||||
if cur.fetchone()[0] == 1:
|
||||
cur.close()
|
||||
sys.exit(0)
|
||||
else:
|
||||
cur.close()
|
||||
sys.exit(-1)
|
||||
except psycopg2.OperationalError:
|
||||
sys.exit(-1)
|
||||
|
||||
sys.exit(0)
|
||||
END
|
||||
}
|
||||
until postgres_ready; do
|
||||
>&2 echo 'Waiting for celerybeat models to be migrated...'
|
||||
sleep 1
|
||||
done
|
||||
>&2 echo 'PostgreSQL is ready'
|
||||
|
||||
celery -A config.celery_app beat -l INFO
|
||||
|
|
Loading…
Reference in New Issue
Block a user