-
Notifications
You must be signed in to change notification settings - Fork 28
/
django_test_suite_3.2.sh
executable file
·75 lines (62 loc) · 2.14 KB
/
django_test_suite_3.2.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
#!/bin/sh
# Copyright (c) 2020 Google LLC. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -x pipefail
sudo -E apt-get update -y
sudo -E apt-get install -y libmemcached-dev
# Disable buffering, so that the logs stream through.
export PYTHONUNBUFFERED=1
export DJANGO_TESTS_DIR="django_tests_dir"
mkdir -p $DJANGO_TESTS_DIR
if [ $SPANNER_EMULATOR_HOST != 0 ]
then
pip3 install .
git clone --depth 1 --single-branch --branch "django/stable/3.2.x" https://github.com/googleapis/python-spanner-django.git $DJANGO_TESTS_DIR/django3.2
fi
# Install dependencies for Django tests.
sudo -E apt-get update
sudo -E apt-get install -y libffi-dev libjpeg-dev zlib1g-devel
cd $DJANGO_TESTS_DIR/django3.2 && pip3 install -e . && pip3 install -r tests/requirements/py3.txt; cd ../../
python3 create_test_instance.py
# If no SPANNER_TEST_DB is set, generate a unique one
# so that we can have multiple tests running without
# conflicting which changes and constraints. We'll always
# cleanup the created database.
TEST_DBNAME=${SPANNER_TEST_DB:-$(python3 -c 'import os, time; print(chr(ord("a") + time.time_ns() % 26)+os.urandom(10).hex())')}
TEST_DBNAME_OTHER="$TEST_DBNAME-ot"
INSTANCE=${SPANNER_TEST_INSTANCE:-django-tests}
PROJECT=${PROJECT_ID}
SETTINGS_FILE="$TEST_DBNAME-settings"
TESTS_DIR=${DJANGO_TESTS_DIR:-django_tests}
create_settings() {
cat << ! > "$SETTINGS_FILE.py"
DATABASES = {
'default': {
'ENGINE': 'django_spanner',
'PROJECT': "$PROJECT",
'INSTANCE': "$INSTANCE",
'NAME': "$TEST_DBNAME",
},
'other': {
'ENGINE': 'django_spanner',
'PROJECT': "$PROJECT",
'INSTANCE': "$INSTANCE",
'NAME': "$TEST_DBNAME_OTHER",
},
}
SECRET_KEY = 'spanner_tests_secret_key'
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
]
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
!
}
cd $TESTS_DIR/django3.2/tests
create_settings
EXIT_STATUS=0
for DJANGO_TEST_APP in $DJANGO_TEST_APPS
do
python3 runtests.py $DJANGO_TEST_APP --verbosity=3 --noinput --settings $SETTINGS_FILE || EXIT_STATUS=$?
done
exit $EXIT_STATUS