forked from rero/rero-ils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests.sh
executable file
·189 lines (173 loc) · 5.13 KB
/
run-tests.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# COLORS for messages
NC='\033[0m' # Default color
INFO_COLOR='\033[1;97;44m' # Bold + white + blue background
SUCCESS_COLOR='\033[1;97;42m' # Bold + white + green background
ERROR_COLOR='\033[1;97;41m' # Bold + white + red background
PROGRAM=`basename $0`
SCRIPT_PATH=$(dirname "$0")
# MESSAGES
msg() {
echo -e "${1}" 1>&2
}
# Display a colored message
# More info: https://misc.flogisoft.com/bash/tip_colors_and_formatting
# $1: choosen color
# $2: title
# $3: the message
colored_msg() {
msg "${1}[${2}]: ${3}${NC}"
}
info_msg() {
colored_msg "${INFO_COLOR}" "INFO" "${1}"
}
error_msg() {
colored_msg "${ERROR_COLOR}" "ERROR" "${1}"
}
error_msg+exit() {
error_msg "${1}" && exit 1
}
success_msg() {
colored_msg "${SUCCESS_COLOR}" "SUCCESS" "${1}"
}
success_msg+exit() {
colored_msg "${SUCCESS_COLOR}" "SUCCESS" "${1}" && exit 0
}
# Displays program name
msg "PROGRAM: ${PROGRAM}"
# Poetry is a mandatory condition to launch this program!
if [[ -z "${VIRTUAL_ENV}" ]]; then
error_msg+exit "Error - Launch this script via poetry command:\n\tpoetry run ${PROGRAM}"
fi
function pretests () {
info_msg "Check vulnerabilities:"
# +============================+===========+==========================+==========+
# | package | installed | affected | ID |
# +============================+===========+==========================+==========+
# | wtforms | 2.3.3 | <3.0.0a1 | 42852 |
# | werkzeug | 1.0.1 | <2.0.2 | 42050 |
# | sqlalchemy-utils | 0.35.0 | >=0.27.0 | 42194 |
# | flask-security | 3.0.0 | >0 | 44501 |
# | flask-caching | 1.10.1 | <=1.10.1 | 40459 |
# | celery | 5.1.2 | <5.2.0 | 42498 |
# | celery | 5.1.2 | <5.2.2 | 43738 |
# +============================+===========+==========================+==========+
safety check -i 42852 -i 42050 -i 42194 -i 40459 -i 42498 -i 43738 -i 44501
info_msg "Check json:"
invenio reroils utils check_json tests/data rero_ils/modules data
info_msg "Check license:"
invenio reroils utils check_license check_license_config.yml
info_msg "Test pydocstyle:"
pydocstyle rero_ils tests docs
info_msg "Test isort:"
isort --check-only --diff "${SCRIPT_PATH}"
info_msg "Test useless imports:"
autoflake -c -r --remove-all-unused-imports --ignore-init-module-imports . &> /dev/null || {
autoflake --remove-all-unused-imports -r --ignore-init-module-imports .
exit 1
}
# info_msg "Check-manifest:"
# TODO: check if this is required when rero-ils will be published
# check-manifest --ignore ".travis-*,docs/_build*"
info_msg "Sphinx-build:"
sphinx-build -qnNW docs docs/_build/html
}
function tests () {
info_msg "Tests All:"
export PYTEST_ADDOPTS="--color=yes"
poetry run tests
}
function tests_api () {
info_msg "Tests API:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest ./tests/api
}
function tests_e2e () {
info_msg "Tests E2E:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest ./tests/e2e
}
function tests_scheduler () {
info_msg "Tests Scheduler:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest ./tests/scheduler
}
function tests_ui () {
info_msg "Tests UI:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest ./tests/ui
}
function tests_unit () {
info_msg "Tests Unit:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest ./tests/unit
}
function tests_external () {
info_msg "Tests External:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest tests/api/test_external_services.py
}
function tests_other () {
info_msg "Tests Other:"
export PYTEST_ADDOPTS="--color=yes"
poetry run pytest ./tests/conftest.py ./tests/test_version.py ./tests/utils.py
}
if [ $# -eq 0 ]
then
set -e
pretests
tests
fi
if [ "$1" = "other" ]
then
set -e
pretests
tests_other
fi
if [ "$1" = "api" ]
then
set -e
tests_api
fi
if [ "$1" = "e2e" ]
then
set -e
tests_e2e
fi
if [ "$1" = "scheduler" ]
then
set -e
tests_scheduler
fi
if [ "$1" = "ui" ]
then
set -e
tests_ui
fi
if [ "$1" = "unit" ]
then
set -e
tests_unit
fi
if [ "$1" = "external" ]
then
set -e
tests_external
fi
success_msg+exit "Perfect ${PROGRAM} external! See you soon…"