-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun-tests.sh
executable file
·169 lines (124 loc) · 3.82 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
#!/bin/bash
set -e
set -v
set -x
cd "$(dirname "$0")"
export BUILDER_VENV=.venv
export TEST_VENV=.venv-tests
export SERVER_VENV=.venv-server
export PYTHON_VERSION=${PYTHON_VERSION:-python3}
export PIP_EXTRA_INDEX_URL=https://gitlab.cesnet.cz/api/v4/projects/1408/packages/pypi/simple
export UV_EXTRA_INDEX_URL=https://gitlab.cesnet.cz/api/v4/projects/1408/packages/pypi/simple
OAREPO_VERSION=${OAREPO_VERSION:-12}
initialize_server_venv() {
if [ -d $SERVER_VENV ] ; then
rm -rf $SERVER_VENV
fi
$PYTHON_VERSION -m venv $SERVER_VENV
source $SERVER_VENV/bin/activate
$SERVER_VENV/bin/pip install -U setuptools pip wheel nrp-devtools
$SERVER_VENV/bin/nrp-devtools proxy 120 &
$SERVER_VENV/bin/pip install "oarepo[tests, rdm]==${OAREPO_VERSION}.*"
#--index-url "http://127.0.0.1:4549/simple" --extra-index-url https://pypi.org/simple
$SERVER_VENV/bin/pip install -e complex-model
#--index-url "http://127.0.0.1:4549/simple" --extra-index-url https://pypi.org/simple
}
initialize_builder_venv() {
if test -d $BUILDER_VENV ; then
rm -rf $BUILDER_VENV
fi
$PYTHON_VERSION -m venv $BUILDER_VENV
. $BUILDER_VENV/bin/activate
$BUILDER_VENV/bin/pip install -U setuptools pip wheel
$BUILDER_VENV/bin/pip install -e '.[tests]'
}
initialize_client_test_venv() {
if test -d $TEST_VENV ; then
rm -rf $TEST_VENV
fi
$PYTHON_VERSION -m venv $TEST_VENV
$TEST_VENV/bin/pip install -U setuptools pip wheel
$TEST_VENV/bin/pip install requests PyYAML pytest
}
run_builder_tests() {
pytest tests
}
create_server() {
if test -d complex-model ; then
rm -rf complex-model
fi
$BUILDER_VENV/bin/oarepo-compile-model ./tests/complex-model.yaml --output-directory complex-model -vvv
}
start_server() {
(
initialize_server_venv
source $SERVER_VENV/bin/activate
if [ ! -d $SERVER_VENV/var/instance ] ; then
mkdir -p $SERVER_VENV/var/instance
fi
cat <<EOF >$SERVER_VENV/var/instance/invenio.cfg
RECORDS_REFRESOLVER_CLS="invenio_records.resolver.InvenioRefResolver"
RECORDS_REFRESOLVER_STORE="invenio_jsonschemas.proxies.current_refresolver_store"
RATELIMIT_AUTHENTICATED_USER="200 per second"
FILES_REST_DEFAULT_STORAGE_CLASS="L"
FILES_REST_STORAGE_CLASS_LIST = {
"L": "Local",
"F": "Fetch",
"R": "Remote",
}
BABEL_DEFAULT_LOCALE = "en"
BABEL_DEFAULT_TIMEZONE = "Europe/Prague"
I18N_LANGUAGES = [
("cs", "Czech"),
]
RATELIMIT_GUEST_USER = "5000 per hour;500 per minute"
RATELIMIT_AUTHENTICATED_USER = "200000 per hour;2000 per minute"
EOF
invenio db destroy --yes-i-know || true
invenio db create
invenio index destroy --yes-i-know || true
invenio index init --force
invenio files location create --default default ./simple-server/files
invenio users create -a -c [email protected] --password testtest
invenio tokens create -n test -u [email protected] >.token
(
export FLASK_DEBUG=1
invenio run --cert tests/certs/test.crt --key tests/certs/test.key 2>&1 &
echo "$!" >.invenio.pid
) | tee tmp.error.log &
echo "Waiting for server to start"
sleep 5
)
}
stop_server() {
$SERVER_VENV/bin/invenio db destroy --yes-i-know || true
$SERVER_VENV/bin/invenio index destroy --yes-i-know || true
set +e
if [ -f .invenio.pid ] ; then
kill "$(cat .invenio.pid)" || true
sleep 2
kill -9 "$(cat .invenio.pid)" || true
rm .invenio.pid || true
fi
}
#
# entrypoint here
#
initialize_builder_venv
run_builder_tests
create_server
if [ "$1" == "--create" ] ; then
exit 0
fi
# start server and schedule cleanup
start_server
trap stop_server EXIT
initialize_client_test_venv
if [ "$1" == "--server" ] ; then
echo "Running at https://127.0.0.1:5000/api/complex-model/. Press enter to stop the server"
read -r
exit 0
fi
cat complex-model/data/sample_data.yaml
$TEST_VENV/bin/pytest tests-model
echo "All tests succeeded"