18
18
exit 1
19
19
fi
20
20
21
- echo " downloading metabase jar ..."
22
- wget https://downloads.metabase.com/v$MB_VERSION /metabase.jar
23
- echo " starting metabase jar locally ..."
21
+ # downloading metabase jar
22
+ wget -q https://downloads.metabase.com/v$MB_VERSION /metabase.jar
23
+
24
+ # starting metabase jar locally
24
25
java -jar metabase.jar > logs 2>&1 &
25
26
26
- echo " waiting 60 seconds for the initialization to complete ... "
27
+ # waiting 60 seconds for the initialization to complete
27
28
sleep 60
28
29
29
30
# checking whether the metabase initialization has completed. If not, wait another 60 seconds
@@ -51,128 +52,122 @@ then
51
52
exit 1
52
53
fi
53
54
54
- ls -l
55
- cp tests/data/test_db.sqlite plugins
56
55
57
- # echo "getting the seup token ..."
58
- # setup_token=$(curl -X GET http://localhost:3000/api/session/properties | perl -pe 's/.*"setup-token":"(.*?)".*/\1/')
59
- # echo "initial setup and getting session_id ..."
60
- # 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/')
61
- # echo $session_id
62
-
63
- # echo "creaing base collections which will be used during the test ..."
64
- # 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
65
- # 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
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: 4
67
-
68
- # echo "downloading the test_db (SQLite)" # for editing the SQLite db: https://sqliteviewer.flowsoft7.com/
69
- # wget -P plugins/ https://github.com/vvaezian/metabase_api_python/raw/master/tests/data/test_db.sqlite
70
-
71
- # echo "Connecting to test_db ..."
72
- # 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
73
-
74
- # # echo "creating base cards which will be used during the test ..."
75
- # json='{
76
- # "name": "test_card",
77
- # "display": "table",
78
- # "dataset_query": {
79
- # "database": 2,
80
- # "query": { "source-table": 9 },
81
- # "type": "query"
82
- # },
83
- # "visualization_settings": {},
84
- # "collection_id": 2
85
- # }'
86
- # echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
87
-
88
- # json='{
89
- # "name":"test_card_2",
90
- # "dataset_query":{
91
- # "type":"native",
92
- # "native":{
93
- # "query":"select *\nfrom test_table\nwhere 1 = 1 \n[[ and {{test_filter}} ]]\n",
94
- # "template-tags":{
95
- # "test_filter":{
96
- # "name":"test_filter",
97
- # "display-name":"Test filter",
98
- # "type":"dimension",
99
- # "dimension":["field",72,null],
100
- # "widget-type":"string/=",
101
- # "default":null,
102
- # "id":"810912da-ead5-c87e-de32-6dc5723b9067"
103
- # }
104
- # }
105
- # }
106
- # ,"database":2
107
- # },
108
- # "display":"table",
109
- # "visualization_settings":{},
110
- # "parameters":[{
111
- # "type":"string/=",
112
- # "target":["dimension",["template-tag","test_filter"]],
113
- # "name":"Test filter",
114
- # "slug":"test_filter",
115
- # "default":null,
116
- # "id":"810912da-ead5-c87e-de32-6dc5723b9067"
117
- # }],
118
- # "collection_id":2
119
- # }'
120
- # echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
121
-
122
- # json='{
123
- # "name":"test_card_3",
124
- # "dataset_query":{
125
- # "type":"query",
126
- # "query":{
127
- # "source-table":9,
128
- # "filter":["=",["field",72,null],"row1 cell1","row3 cell1"]},
129
- # "database":2
130
- # },
131
- # "display":"table",
132
- # "visualization_settings":{},
133
- # "collection_id":2
134
- # }'
135
- # echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
136
-
137
- # json='{
138
- # "name":"test_card_4",
139
- # "dataset":false,
140
- # "dataset_query":{
141
- # "database":2,
142
- # "query":{
143
- # "source-table":9,
144
- # "aggregation":[["avg",["field",73,null]]],
145
- # "breakout":[["field",72,null]],
146
- # "order-by":[["desc",["aggregation",0,null]]]
147
- # },
148
- # "type":"query"
149
- # },
150
- # "display":"bar",
151
- # "visualization_settings":{"table.pivot":false,"graph.dimensions":["col1"],"graph.metrics":["avg"]},
152
- # "collection_id":2
153
- # }'
154
- # echo "$json" | curl -X POST http://localhost:3000/api/card -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
155
-
156
- # # create a test dashboard
157
- # 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"}'
158
-
159
- # # add the test_card to the dashboard
160
- # curl -X POST http://localhost:3000/api/dashboard/1/cards -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"cardId":1}'
161
- # json='{
162
- # "cards":[{
163
- # "card_id":1,
164
- # "row":0,
165
- # "col":0,
166
- # "size_x":4,
167
- # "size_y":5,
168
- # "series":[],
169
- # "visualization_settings":{},
170
- # "parameter_mappings":[]
171
- # }]
172
- # }'
173
- # echo "$json" | curl -X PUT http://localhost:3000/api/dashboard/1/cards -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d @-
174
-
175
- # # diable friendly table and field names
176
- # curl -X PUT http://localhost:3000/api/setting/humanization-strategy -H "Content-Type: application/json" -H "X-Metabase-Session:$session_id" -d '{"value":"none"}'
177
-
178
- # #session_id='69afe488-8037-47ec-b437-c6136d6d32c8'
56
+ # getting the seup token
57
+ setup_token=$( curl -X GET http://localhost:3000/api/session/properties | perl -pe ' s/.*"setup-token":"(.*?)".*/\1/' )
58
+ # initial setup and getting the session_id
59
+ 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/' )
60
+ echo $session_id
61
+
62
+ # copying the SQLite test db to metabase plugins directory (for editing the SQLite db you can use: https://sqliteviewer.flowsoft7.com/)
63
+ cp tests/data/test_db.sqlite plugins
64
+ # adding test_db to Metabase as a new database
65
+ 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
66
+
67
+ # creaing base collections which will be used during the test
68
+ 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
69
+ 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
70
+ 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
71
+
72
+ # creating base cards which will be used during the test
73
+ json=' {
74
+ "name": "test_card",
75
+ "display": "table",
76
+ "dataset_query": {
77
+ "database": 2,
78
+ "query": { "source-table": 9 },
79
+ "type": "query"
80
+ },
81
+ "visualization_settings": {},
82
+ "collection_id": 2
83
+ }'
84
+ echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
85
+
86
+ json=' {
87
+ "name":"test_card_2",
88
+ "dataset_query":{
89
+ "type":"native",
90
+ "native":{
91
+ "query":"select *\nfrom test_table\nwhere 1 = 1 \n[[ and {{test_filter}} ]]\n",
92
+ "template-tags":{
93
+ "test_filter":{
94
+ "name":"test_filter",
95
+ "display-name":"Test filter",
96
+ "type":"dimension",
97
+ "dimension":["field",72,null],
98
+ "widget-type":"string/=",
99
+ "default":null,
100
+ "id":"810912da-ead5-c87e-de32-6dc5723b9067"
101
+ }
102
+ }
103
+ }
104
+ ,"database":2
105
+ },
106
+ "display":"table",
107
+ "visualization_settings":{},
108
+ "parameters":[{
109
+ "type":"string/=",
110
+ "target":["dimension",["template-tag","test_filter"]],
111
+ "name":"Test filter",
112
+ "slug":"test_filter",
113
+ "default":null,
114
+ "id":"810912da-ead5-c87e-de32-6dc5723b9067"
115
+ }],
116
+ "collection_id":2
117
+ }'
118
+ echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
119
+
120
+ json=' {
121
+ "name":"test_card_3",
122
+ "dataset_query":{
123
+ "type":"query",
124
+ "query":{
125
+ "source-table":9,
126
+ "filter":["=",["field",72,null],"row1 cell1","row3 cell1"]},
127
+ "database":2
128
+ },
129
+ "display":"table",
130
+ "visualization_settings":{},
131
+ "collection_id":2
132
+ }'
133
+ echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
134
+
135
+ json=' {
136
+ "name":"test_card_4",
137
+ "dataset":false,
138
+ "dataset_query":{
139
+ "database":2,
140
+ "query":{
141
+ "source-table":9,
142
+ "aggregation":[["avg",["field",73,null]]],
143
+ "breakout":[["field",72,null]],
144
+ "order-by":[["desc",["aggregation",0,null]]]
145
+ },
146
+ "type":"query"
147
+ },
148
+ "display":"bar",
149
+ "visualization_settings":{"table.pivot":false,"graph.dimensions":["col1"],"graph.metrics":["avg"]},
150
+ "collection_id":2
151
+ }'
152
+ echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
153
+
154
+ # create a test dashboard
155
+ 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"}'
156
+ # add the test_card to the dashboard
157
+ curl -X POST http://localhost:3000/api/dashboard/1/cards -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d ' {"cardId":1}'
158
+ json=' {
159
+ "cards":[{
160
+ "card_id":1,
161
+ "row":0,
162
+ "col":0,
163
+ "size_x":4,
164
+ "size_y":5,
165
+ "series":[],
166
+ "visualization_settings":{},
167
+ "parameter_mappings":[]
168
+ }]
169
+ }'
170
+ echo " $json " | curl -X PUT http://localhost:3000/api/dashboard/1/cards -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
171
+
172
+ # diable friendly table and field names
173
+ curl -X PUT http://localhost:3000/api/setting/humanization-strategy -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d ' {"value":"none"}'
0 commit comments