-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathentrypoint-unit-tests.sh
More file actions
executable file
·95 lines (68 loc) · 3.2 KB
/
entrypoint-unit-tests.sh
File metadata and controls
executable file
·95 lines (68 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Run available unittests with a setup for CI/CD:
# - Fail if migrations are not created
# - Exit container after running tests to allow exit code to propagate as test result
# set -x
set -e
# set -v
. /secret-file-loader.sh
. /reach_database.sh
cd /app || exit
# Unset the database URL so that we can force the DD_TEST_DATABASE_NAME (see django "DATABASES" configuration in settings.dist.py)
unset DD_DATABASE_URL
# Unset the celery broker URL so that we can force the other DD_CELERY_BROKER settings
unset DD_CELERY_BROKER_URL
# TARGET_SETTINGS_FILE=dojo/settings/settings.py
# if [ ! -f ${TARGET_SETTINGS_FILE} ]; then
# echo "Creating settings.py"
# cp dojo/settings/settings.dist.py dojo/settings/settings.py
# fi
wait_for_database_to_be_reachable
python3 manage.py spectacular --fail-on-warn > /dev/null || {
cat <<-EOF
********************************************************************************
You made changes to the REST API without applying the correct schema annotations
These schema annotations are needed to allow for the correct generation of
the OpenAPI (v3) schema's and documentation.
Review the warnings generated by drf-spectacular and see "dojo/api_v2/views.py"
and/or "dojo/api_v2/serializers.py".
You can check for warnings locally by running
python3 manage.py spectacular > /dev/null
This will output only warnings/errors, or nothing if everything is OK.
More info at: https://drf-spectacular.readthedocs.io/en/latest/customization.html
********************************************************************************
EOF
python3 manage.py spectacular > /dev/null
exit 1
}
python3 manage.py makemigrations --no-input --check --dry-run --verbosity 3 || {
cat <<-EOF
********************************************************************************
You made changes to the models without creating a DB migration for them.
**NEVER** change existing migrations, create a new one.
If you're not familiar with migrations in Django, please read the
great documentation thoroughly:
https://docs.djangoproject.com/en/5.0/topics/migrations/
********************************************************************************
EOF
exit 1
}
python3 manage.py migrate
# --parallel fails on GitHub Actions
#python3 manage.py test unittests -v 3 --no-input --parallel
echo "Unit Tests"
echo "------------------------------------------------------------"
# Removing parallel and shuffle for now to maintain stability
python3 manage.py test unittests --keepdb --no-input --exclude-tag="non-parallel" --exclude-tag="transactional" || {
exit 1;
}
python3 manage.py test unittests --keepdb --no-input --tag="non-parallel" || {
exit 1;
}
# Running one unit tests that inherits from TransactionTestCase somehow changes the behaviour of how Django loads fixtures into the database.
# Meaning any test after this one would fail to load our dojo_testdata.json fixture. In a way this makes sense as it contains some data integrity problems.
# I tried to fix these in https://github.com/DefectDojo/django-DefectDojo/pull/13217.
# For now here we run the only TranscationTestCase at the end to avoid the problem.
python3 manage.py test unittests --keepdb --no-input --tag="transactional" || {
exit 1;
}