Skip to content

Commit 6912c48

Browse files
committed
local test
1 parent 437a49a commit 6912c48

3 files changed

Lines changed: 251 additions & 116 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@ jobs:
3939
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
4040
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4141
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
42+
- name: Initial Setup before running tests
43+
run: |
44+
./tests/initial_setup.sh -v 0.45.2.1
4245
- name: Test with pytest
43-
env:
44-
LOGIN_DOMAIN : ${{ secrets.LOGIN_DOMAIN }}
45-
LOGIN_USERNAME : ${{ secrets.LOGIN_USERNAME }}
46-
LOGIN_PASSWORD : ${{ secrets.LOGIN_PASSWORD }}
4746
run: |
4847
pytest
4948
- name: Generate Report
50-
env:
51-
LOGIN_DOMAIN : ${{ secrets.LOGIN_DOMAIN }}
52-
LOGIN_USERNAME : ${{ secrets.LOGIN_USERNAME }}
53-
LOGIN_PASSWORD : ${{ secrets.LOGIN_PASSWORD }}
5449
run: |
5550
pip install coverage
5651
coverage run -m unittest

tests/initial_setup.sh

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# This file does some initial setup so we can run tests on a local Metabase:
2+
# - Downloads the Metabase jar file
3+
# - Runs it
4+
# - Creates an admin user (email: abc.xyz@gmail.com, password: xzy12345) and does the initial setup of Metabase
5+
# - Creates some collections/cards/dashboards which will be used when running the tests
6+
7+
8+
while getopts 'v:' flag; do
9+
case "${flag}" in
10+
v) MB_VERSION="${OPTARG}" ;;
11+
*) echo 'Accepted flags: -v'
12+
exit 1 ;;
13+
esac
14+
done
15+
16+
if [[ $MB_VERSION = '' ]]
17+
then
18+
echo 'Please provide the Metabase version using -v flag.'
19+
exit 1
20+
fi
21+
22+
echo https://downloads.metabase.com/v$MB_VERSION/metabase.jar
23+
pwd
24+
ls -l
25+
#cp tests/data/test_db.sqlite plugins
26+
27+
# wget https://downloads.metabase.com/v$MB_VERSION/metabase.jar
28+
# echo "starting metabase jar locally ..."
29+
# java -jar metabase.jar > logs 2>&1 &
30+
31+
# echo "waiting 60 seconds for the initialization to complete ..."
32+
# sleep 60
33+
34+
# success='False'
35+
# grep -q "Metabase Initialization COMPLETE" logs
36+
# if [[ $? -eq 0 ]]
37+
# then
38+
# echo 'success!'
39+
# success='True'
40+
# else
41+
# echo "Waiting an extra 60 seconds for the initialization to complete"
42+
# sleep 60
43+
# grep -q "Metabase Initialization COMPLETE" logs
44+
# if [[ $? -eq 0 ]]
45+
# then
46+
# echo 'success!'
47+
# success='True'
48+
# else
49+
# echo 'failure!'
50+
# fi
51+
# fi
52+
53+
# if [[ $success = 'False' ]]
54+
# then
55+
# exit 1
56+
# fi
57+
58+
# echo "getting the seup token ..."
59+
# setup_token=$(curl -X GET http://localhost:3000/api/session/properties | perl -pe 's/.*"setup-token":"(.*?)".*/\1/')
60+
# echo "initial setup and getting session_id ..."
61+
# session_id=$(curl -X POST -H "Content-Type: application/json" -d '{ "token": "'$setup_token'", "user": {"first_name": "abc", "last_name": "xyz", "email": "abc.xyz@gmail.com", "password": "xzy12345"},"prefs": {"allow_tracking": true, "site_name": "test_site"}}' http://localhost:3000/api/setup | perl -pe 's/^.......(.*)..$/\1/')
62+
# echo $session_id
63+
64+
# echo "creaing base collections which will be used during the test ..."
65+
# curl -X POST -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"name":"test_collection", "color":"#509EE3"}' http://localhost:3000/api/collection # id of the created collection is 2 because id 1 is reserved for the personal collection of admin
66+
# curl -X POST -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"name":"test_collection_dup", "parent_id":2, "color":"#509EE3"}' http://localhost:3000/api/collection # collection_id: 3
67+
# curl -X POST -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"name":"test_collection_dup", "parent_id":2, "color":"#509EE3"}' http://localhost:3000/api/collection # collection_id: 4
68+
69+
# echo "downloading the test_db (SQLite)" # for editing the SQLite db: https://sqliteviewer.flowsoft7.com/
70+
# wget -P plugins/ https://github.com/vvaezian/metabase_api_python/raw/master/tests/data/test_db.sqlite
71+
72+
# echo "Connecting to test_db ..."
73+
# curl -X POST -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"engine":"sqlite","name":"test_db","details":{"db":"plugins/test_db.sqlite","advanced-options":false},"is_full_sync":true}' http://localhost:3000/api/database # id of the created db connection is 2 because 1 is used for sample database
74+
75+
# # echo "creating base cards which will be used during the test ..."
76+
# json='{
77+
# "name": "test_card",
78+
# "display": "table",
79+
# "dataset_query": {
80+
# "database": 2,
81+
# "query": { "source-table": 9 },
82+
# "type": "query"
83+
# },
84+
# "visualization_settings": {},
85+
# "collection_id": 2
86+
# }'
87+
# echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
88+
89+
# json='{
90+
# "name":"test_card_2",
91+
# "dataset_query":{
92+
# "type":"native",
93+
# "native":{
94+
# "query":"select *\nfrom test_table\nwhere 1 = 1 \n[[ and {{test_filter}} ]]\n",
95+
# "template-tags":{
96+
# "test_filter":{
97+
# "name":"test_filter",
98+
# "display-name":"Test filter",
99+
# "type":"dimension",
100+
# "dimension":["field",72,null],
101+
# "widget-type":"string/=",
102+
# "default":null,
103+
# "id":"810912da-ead5-c87e-de32-6dc5723b9067"
104+
# }
105+
# }
106+
# }
107+
# ,"database":2
108+
# },
109+
# "display":"table",
110+
# "visualization_settings":{},
111+
# "parameters":[{
112+
# "type":"string/=",
113+
# "target":["dimension",["template-tag","test_filter"]],
114+
# "name":"Test filter",
115+
# "slug":"test_filter",
116+
# "default":null,
117+
# "id":"810912da-ead5-c87e-de32-6dc5723b9067"
118+
# }],
119+
# "collection_id":2
120+
# }'
121+
# echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
122+
123+
# json='{
124+
# "name":"test_card_3",
125+
# "dataset_query":{
126+
# "type":"query",
127+
# "query":{
128+
# "source-table":9,
129+
# "filter":["=",["field",72,null],"row1 cell1","row3 cell1"]},
130+
# "database":2
131+
# },
132+
# "display":"table",
133+
# "visualization_settings":{},
134+
# "collection_id":2
135+
# }'
136+
# echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
137+
138+
# json='{
139+
# "name":"test_card_4",
140+
# "dataset":false,
141+
# "dataset_query":{
142+
# "database":2,
143+
# "query":{
144+
# "source-table":9,
145+
# "aggregation":[["avg",["field",73,null]]],
146+
# "breakout":[["field",72,null]],
147+
# "order-by":[["desc",["aggregation",0,null]]]
148+
# },
149+
# "type":"query"
150+
# },
151+
# "display":"bar",
152+
# "visualization_settings":{"table.pivot":false,"graph.dimensions":["col1"],"graph.metrics":["avg"]},
153+
# "collection_id":2
154+
# }'
155+
# echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
156+
157+
# # create a test dashboard
158+
# curl -X POST http://localhost:3000/api/dashboard -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"collection_id":2,"name":"test_dashboard"}'
159+
160+
# # add the test_card to the dashboard
161+
# curl -X POST http://localhost:3000/api/dashboard/1/cards -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"cardId":1}'
162+
# json='{
163+
# "cards":[{
164+
# "card_id":1,
165+
# "row":0,
166+
# "col":0,
167+
# "size_x":4,
168+
# "size_y":5,
169+
# "series":[],
170+
# "visualization_settings":{},
171+
# "parameter_mappings":[]
172+
# }]
173+
# }'
174+
# echo "$json" | curl -X PUT http://localhost:3000/api/dashboard/1/cards -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
175+
176+
# # diable friendly table and field names
177+
# curl -X PUT http://localhost:3000/api/setting/humanization-strategy -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"value":"none"}'
178+
179+
##session_id='69afe488-8037-47ec-b437-c6136d6d32c8'

0 commit comments

Comments
 (0)