-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoe-test.sh
executable file
·181 lines (169 loc) · 5 KB
/
oe-test.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
#!/usr/bin/env bash
set -eu
set -o pipefail
if [[ "${DEBUG:-}" = "1" ]]; then
set -x
fi
PORT=7969
: "${DB:=test}"
ROOT=~/devel/odoo
FS=~/Library/Application\ Support/Odoo/filestore
GR=$(git rev-parse --show-toplevel)
pushd "${GR}" >/dev/null
AD=
LOGLEVEL=ERROR
LOGFILE=
KEEP=N
TEST_ENABLED="--test-enable"
BR=$(git symbolic-ref --short HEAD || echo "?")
RUN=N
IGNORED_MODULES="l10n_|hw_|test_module|theme_|auth_ldap|pos_blackbox_be"
ALLMODS=$(fd '__openerp|manifest__.py' . -e py -x basename '{//}' | grep -vE "$IGNORED_MODULES" | tr '\n' ,)
ALLALLMODS=$(fd '__openerp|manifest__.py' . -e py -x basename '{//}'| tr '\n' ,)
opt=
while getopts 'hnNkKrseEtTwvl:' opt; do
case "$opt" in
h)
echo "Usage:"
echo " $0 (-h | --help)"
echo " $0 [-k [-n | -N]] [-e | -E] [-w | -v] [-r | -s] [-l <logfile>] [<MODS> [<ODOO_OPTIONS>...]]"
echo ""
echo "Options:"
echo " -n, -N do not execute test. Only install module (without demo data if -N). aka dry-run."
echo " -k keep existing \`test\` database"
echo " -e, -E include Enterprise in addon-path (trust branches if -E)"
echo " -t, -T include Themes in addon-path (trust branches if -T)"
echo " -w log all warnings"
echo " -v log info"
echo " -r run odoo after db creation"
echo " -s run odoo shell after db creation"
echo " -l <logfile>"
exit 0
;;
n)
TEST_ENABLED=
;;
N)
TEST_ENABLED="--without-demo=1"
;;
k)
KEEP=u
;;
K)
KEEP=i
;;
r)
RUN=Y
;;
s)
RUN=S
;;
e | E)
pushd "${ROOT}/enterprise" >/dev/null
if [[ "$opt" == "e" ]]; then
EBR=$(git symbolic-ref --short HEAD)
if [[ "$EBR" != "$BR" ]]; then
echo "Enterprise branch ($EBR) is different that current one ($BR)" >&2
exit 1
fi
fi
AD=${AD}${PWD},
ALLMODS=${ALLMODS},$(fd '__openerp|manifest__.py' . -e py -x basename '{//}' | grep -vE "$IGNORED_MODULES" | tr '\n' ,)
ALLALLMODS=${ALLALLMODS},$(fd '__openerp|manifest__.py' . -e py -x basename '{//}'| tr '\n' ,)
popd >/dev/null
;;
t | T)
pushd "${ROOT}/themes" >/dev/null
if [[ "$opt" == "t" ]]; then
TBR=$(git symbolic-ref --short HEAD)
if [[ "$TBR" != "$BR" ]]; then
echo "Themes branch ($TBR) is different that current one ($BR)" >&2
exit 1
fi
fi
AD=${AD}${PWD},
ALLALLMODS=${ALLALLMODS},$(fd '__openerp|manifest__.py' . -e py -x basename '{//}'| tr '\n' ,)
popd >/dev/null
;;
w)
LOGLEVEL=WARN
;;
v)
LOGLEVEL=INFO
;;
l)
LOGFILE="$OPTARG"
;;
?) exit 1
;;
*);;
esac
done
shift $((OPTIND - 1))
MODS="${1:-base}"
if [[ "$MODS" == "all" ]]; then
MODS=$ALLMODS
elif [[ "$MODS" == "test" ]]; then
MODS=$(echo -n "$ALLMODS" | tr ' ,' '\n' | grep -E '^test_' | tr '\n' ,)
else
# validate MODS agains $ALLALLMODS
UNK=$(echo "$ALLALLMODS" "$ALLALLMODS" "$MODS" | tr ' ,' '\n' | sort | uniq -u | tr '\n' ' ')
if [[ -n "$UNK" ]]; then
echo "Unknow modules: $UNK" >&2
exit 1
fi
fi
shift || true
D=odoo
if [[ -f openerp/__init__.py ]]; then
D=openerp
fi
B=odoo-bin
if [[ -f openerp-server ]]; then
B=openerp-server
fi
LOGHANDLERS="
--log-handler=:${LOGLEVEL} \
--log-handler=${D}.modules.loading:WARN --log-handler=${D}.modules.graph:CRITICAL \
--log-handler=${D}.modules.module:INFO --log-handler=${D}.modules.registry:INFO \
--log-handler=${D}.tests.common:INFO \
"
if [[ "$KEEP" == "N" ]]; then
IU="-i"
set -x
dropdb --if-exists "$DB"
rm -rf "${FS:?}/${DB}"
createdb "$DB"
{ set +x; } 2>/dev/null
_L10N=$(echo -n "$MODS" | awk -vRS=, -vFS=_ '/^l10n_/{print $2}' | sort | uniq | tr '\n' ' ')
declare -a L10N=($_L10N)
if test "${#L10N[@]}" -gt 0; then
set -x
./$B --addons-path="${AD}./addons" \
--db-filter="^${DB}\$" --pidfile=/tmp/odoo.pid --stop-after-init \
--xmlrpc-port=${PORT} \
${LOGHANDLERS} \
--logfile="${LOGFILE}" -i base -d "$DB"
psql -d "$DB" -c "UPDATE res_partner SET country_id = (SELECT id FROM res_country WHERE lower(code)='${L10N[0]}')"
{ set +x; } 2>/dev/null
unset L10N[0]
set -x
fi
else
IU="-$KEEP" # yuck
# TODO determine $IU automatically depending of module(s) state
set -x
fi
./$B --addons-path="${AD}./addons" \
--db-filter="^${DB}\$" --pidfile=/tmp/odoo.pid --stop-after-init \
${TEST_ENABLED} \
--xmlrpc-port=${PORT} \
${LOGHANDLERS} \
--logfile="${LOGFILE}" $IU "${MODS}" -d "$DB" "$@"
if [[ "$RUN" != "N" ]]; then
COMMAND=
if [[ "$RUN" == "S" ]]; then COMMAND=shell; fi;
./$B --addons-path="${AD}./addons" $COMMAND \
--db-filter="^${DB}\$" --pidfile=/tmp/odoo.pid \
--logfile="${LOGFILE}" -d "$DB" "$@"
fi