Minor changes to test
Some checks failed
expenses_manager/pipeline/head There was a failure building this commit
Some checks failed
expenses_manager/pipeline/head There was a failure building this commit
This commit is contained in:
parent
a35ccb2fd9
commit
de80fdf78c
21
expenses_manager/Jenkinsfile
vendored
21
expenses_manager/Jenkinsfile
vendored
@ -4,11 +4,6 @@ pipeline {
|
|||||||
agent none
|
agent none
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
DEBUG = 'True'
|
|
||||||
SECRET_KEY = 'ci-only-value-never-used-in-production'
|
|
||||||
DJANGO_SETTINGS_MODULE = 'expenses_manager.settings'
|
|
||||||
PYTHONUNBUFFERED = '1'
|
|
||||||
|
|
||||||
// Jenkins has no Docker daemon, so everything Docker-related happens on
|
// Jenkins has no Docker daemon, so everything Docker-related happens on
|
||||||
// the NAS over SSH. Absolute paths are required: the remote
|
// the NAS over SSH. Absolute paths are required: the remote
|
||||||
// non-interactive PATH does not include /usr/local/bin.
|
// non-interactive PATH does not include /usr/local/bin.
|
||||||
@ -72,6 +67,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Catches models changed without generating the migration.
|
||||||
// Catches models changed without generating the migration.
|
// Catches models changed without generating the migration.
|
||||||
stage('Check migrations') {
|
stage('Check migrations') {
|
||||||
steps {
|
steps {
|
||||||
@ -81,7 +77,9 @@ pipeline {
|
|||||||
ssh ${SSH_OPTS} ${NAS_USER}@${NAS_HOST} \
|
ssh ${SSH_OPTS} ${NAS_USER}@${NAS_HOST} \
|
||||||
"sudo ${NAS_DOCKER} run --rm \
|
"sudo ${NAS_DOCKER} run --rm \
|
||||||
-e SECRET_KEY=ci-only-value \
|
-e SECRET_KEY=ci-only-value \
|
||||||
-e DEBUG=True \
|
-e DEBUG=False \
|
||||||
|
-e ALLOWED_HOSTS=localhost,testserver \
|
||||||
|
-e DJANGO_SETTINGS_MODULE=expenses_manager.settings_test \
|
||||||
-e DB_ENGINE=sqlite3 \
|
-e DB_ENGINE=sqlite3 \
|
||||||
${IMAGE}-test:${SHA} \
|
${IMAGE}-test:${SHA} \
|
||||||
python manage.py makemigrations --check --dry-run"
|
python manage.py makemigrations --check --dry-run"
|
||||||
@ -95,14 +93,15 @@ pipeline {
|
|||||||
sshagent(credentials: ['nas-ssh']) {
|
sshagent(credentials: ['nas-ssh']) {
|
||||||
// pytest output goes to stderr so it shows up in this log,
|
// pytest output goes to stderr so it shows up in this log,
|
||||||
// while stdout carries only the JUnit XML. That avoids
|
// while stdout carries only the JUnit XML. That avoids
|
||||||
// copying a root-owned file back from the NAS, which
|
// copying a root-owned file back from the NAS.
|
||||||
// jenkins-ci could not read.
|
|
||||||
sh '''
|
sh '''
|
||||||
SHA=$(echo "${GIT_COMMIT}" | cut -c1-7)
|
SHA=$(echo "${GIT_COMMIT}" | cut -c1-7)
|
||||||
ssh ${SSH_OPTS} ${NAS_USER}@${NAS_HOST} \
|
ssh ${SSH_OPTS} ${NAS_USER}@${NAS_HOST} \
|
||||||
"sudo ${NAS_DOCKER} run --rm \
|
"sudo ${NAS_DOCKER} run --rm \
|
||||||
-e SECRET_KEY=ci-only-value \
|
-e SECRET_KEY=ci-only-value \
|
||||||
-e DEBUG=True \
|
-e DEBUG=False \
|
||||||
|
-e ALLOWED_HOSTS=localhost,testserver \
|
||||||
|
-e DJANGO_SETTINGS_MODULE=expenses_manager.settings_test \
|
||||||
-e DB_ENGINE=sqlite3 \
|
-e DB_ENGINE=sqlite3 \
|
||||||
${IMAGE}-test:${SHA} \
|
${IMAGE}-test:${SHA} \
|
||||||
sh -c 'pytest --cov --junitxml=/tmp/junit.xml >&2; \
|
sh -c 'pytest --cov --junitxml=/tmp/junit.xml >&2; \
|
||||||
@ -113,13 +112,11 @@ pipeline {
|
|||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
// allowEmptyResults: false is deliberate. A build where
|
|
||||||
// pytest died before collecting anything produces no XML,
|
|
||||||
// and that must fail rather than pass quietly.
|
|
||||||
junit allowEmptyResults: false, testResults: 'junit.xml'
|
junit allowEmptyResults: false, testResults: 'junit.xml'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Smoke test image') {
|
stage('Smoke test image') {
|
||||||
steps {
|
steps {
|
||||||
|
|||||||
11
expenses_manager/expenses_manager/settings_test.py
Normal file
11
expenses_manager/expenses_manager/settings_test.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
"""Settings for the test suite.
|
||||||
|
|
||||||
|
Inherits the production configuration so tests exercise what actually runs on
|
||||||
|
the NAS — DEBUG off, secure cookies, WhiteNoise storage — and turns off only
|
||||||
|
what makes Django's test client unusable: SECURE_SSL_REDIRECT answers every
|
||||||
|
request with a 301 before the view is ever reached.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .settings import * # noqa: F401,F403
|
||||||
|
|
||||||
|
SECURE_SSL_REDIRECT = False
|
||||||
@ -1,3 +1,3 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
DJANGO_SETTINGS_MODULE = expenses_manager.settings
|
DJANGO_SETTINGS_MODULE = expenses_manager.settings_test
|
||||||
python_files = tests.py test_*.py *_tests.py
|
python_files = tests.py test_*.py *_tests.py
|
||||||
Loading…
Reference in New Issue
Block a user