Skip to content

Commit 1fa72df

Browse files
eriksfalejandrox1
authored andcommitted
Add tenants tests (#23)
Add tenants-init and tenants-list tests
1 parent 4ec8af5 commit 1fa72df

File tree

6 files changed

+337
-7
lines changed

6 files changed

+337
-7
lines changed

.gitignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Python
2-
*.pyc
3-
4-
# test data
5-
tests/*.log
6-
tests/agave_mock_server/*.egg-info
1+
# Python
2+
*.pyc
3+
4+
# test data
5+
tests/*.log
6+
tests/agave_mock_server/*.egg-info

tests/agave_mock_server/agave_mock_server/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .filesmedia_endpoints import AgaveFilesMedia
66
from .fileslistings_endpoints import AgaveFilesListings
77
from .postits_endpoints import AgavePostits
8+
from .tenants_endpoints import AgaveTenants
89

910
app = Flask(__name__)
1011
app.config["JSONIFY_PRETTYPRINT_REGULAR"] = True
@@ -13,13 +14,14 @@
1314
api.add_resource(AgaveApps, "/apps/v2")
1415
api.add_resource(AgaveClients, "/clients/v2/",
1516
"/clients/v2/<string:client_name>")
16-
api.add_resource(AgaveFilesMedia,
17+
api.add_resource(AgaveFilesMedia,
1718
"/files/v2/media/system/<string:system_id>/<string:file_path>",
1819
"/files/v2/media/system/<string:system_id>//<string:file_path>")
1920
api.add_resource(AgaveFilesListings,
2021
"/files/v2/listings/system/<string:system_id>/<string:file_path>",
2122
"/files/v2/listings/system/<string:system_id>//<string:file_path>")
2223
api.add_resource(AgavePostits, "/postits/v2/")
24+
api.add_resource(AgaveTenants, "/tenants")
2325

2426
if __name__ == "__main__":
2527
app.run(host="0.0.0.0", ssl_context="adhoc")
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
[
2+
{
3+
"id": "6601411570898817-b0b0b0bb0b-0001-016",
4+
"name": "3dem Tenant",
5+
"baseUrl": "https://api.3dem.org/",
6+
"code": "3dem",
7+
"contact": [
8+
{
9+
"name": "James Carson",
10+
"email": "jcarson@tacc.utexas.edu",
11+
"url": "",
12+
"type": "admin",
13+
"primary": true
14+
}
15+
],
16+
"_links": {
17+
"self": {
18+
"href": "https://docker.example.com/tenants/v2/3dem"
19+
},
20+
"publickey": {
21+
"href": "https://api.3dem.org/apim/v2/publickey"
22+
}
23+
}
24+
},
25+
{
26+
"id": "4201449684007961-b0b0b0bb0b-0001-016",
27+
"name": "Agave Public Tenant",
28+
"baseUrl": "https://public.agaveapi.co/",
29+
"code": "agave.prod",
30+
"contact": [
31+
{
32+
"name": "Rion Dooley",
33+
"email": "dooley@tacc.utexas.edu",
34+
"url": "",
35+
"type": "admin",
36+
"primary": true
37+
}
38+
],
39+
"_links": {
40+
"self": {
41+
"href": "https://docker.example.com/tenants/v2/agave.prod"
42+
},
43+
"publickey": {
44+
"href": "https://public.agaveapi.co/apim/v2/publickey"
45+
}
46+
}
47+
},
48+
{
49+
"id": "0001411570898826-b0b0b0bb0b-0001-016",
50+
"name": "Araport",
51+
"baseUrl": "https://api.araport.org/",
52+
"code": "araport.org",
53+
"contact": [
54+
{
55+
"name": "Matt Vaughn",
56+
"email": "vaughn@tacc.utexas.edu",
57+
"url": "",
58+
"type": "admin",
59+
"primary": true
60+
}
61+
],
62+
"_links": {
63+
"self": {
64+
"href": "https://docker.example.com/tenants/v2/araport.org"
65+
},
66+
"publickey": {
67+
"href": "https://api.araport.org/apim/v2/publickey"
68+
}
69+
}
70+
},
71+
{
72+
"id": "3201449684007961-b0b0b0bb0b-0001-016",
73+
"name": "DesignSafe",
74+
"baseUrl": "https://agave.designsafe-ci.org/",
75+
"code": "designsafe",
76+
"contact": [
77+
{
78+
"name": "Josue Coronel",
79+
"email": "jcoronel@tacc.utexas.edu",
80+
"url": "",
81+
"type": "admin",
82+
"primary": true
83+
}
84+
],
85+
"_links": {
86+
"self": {
87+
"href": "https://docker.example.com/tenants/v2/designsafe"
88+
},
89+
"publickey": {
90+
"href": "https://agave.designsafe-ci.org/apim/v2/publickey"
91+
}
92+
}
93+
},
94+
{
95+
"id": "0001411570898781-b0b0b0bb0b-0001-016",
96+
"name": "CyVerse Science APIs",
97+
"baseUrl": "https://agave.iplantc.org/",
98+
"code": "iplantc.org",
99+
"contact": [
100+
{
101+
"name": "Matt Vaughn",
102+
"email": "vaughn@tacc.utexas.edu",
103+
"url": "",
104+
"type": "admin",
105+
"primary": true
106+
}
107+
],
108+
"_links": {
109+
"self": {
110+
"href": "https://docker.example.com/tenants/v2/iplantc.org"
111+
},
112+
"publickey": {
113+
"href": "https://agave.iplantc.org/apim/v2/publickey"
114+
}
115+
}
116+
},
117+
{
118+
"id": "0001411570898837-b0b0b0bb0b-0001-016",
119+
"name": "iReceptor",
120+
"baseUrl": "https://irec.tenants.prod.tacc.cloud/",
121+
"code": "irec",
122+
"contact": [
123+
{
124+
"name": "Brian Corrie",
125+
"email": "bcorrie@sfu.ca",
126+
"url": "",
127+
"type": "admin",
128+
"primary": true
129+
}
130+
],
131+
"_links": {
132+
"self": {
133+
"href": "https://docker.example.com/tenants/v2/irec"
134+
},
135+
"publickey": {
136+
"href": "https://irec.tenants.prod.tacc.cloud/apim/v2/publickey"
137+
}
138+
}
139+
},
140+
{
141+
"id": "0001411570898817-b0b0b0bb0b-0001-016",
142+
"name": "SD2E Tenant",
143+
"baseUrl": "https://api.sd2e.org/",
144+
"code": "sd2e",
145+
"contact": [
146+
{
147+
"name": "Matt Vaughn",
148+
"email": "vaughn@tacc.utexas.edu",
149+
"url": "",
150+
"type": "admin",
151+
"primary": true
152+
}
153+
],
154+
"_links": {
155+
"self": {
156+
"href": "https://docker.example.com/tenants/v2/sd2e"
157+
},
158+
"publickey": {
159+
"href": "https://api.sd2e.org/apim/v2/publickey"
160+
}
161+
}
162+
},
163+
{
164+
"id": "5603147879475572250-242ac113-0001-016",
165+
"name": "Science Gateways Community Institute",
166+
"baseUrl": "https://sgci.tacc.cloud/",
167+
"code": "sgci",
168+
"contact": [
169+
{
170+
"name": "Maytal Dahan",
171+
"email": "catalog@sciencegateways.org",
172+
"url": "",
173+
"type": "admin",
174+
"primary": true
175+
}
176+
],
177+
"_links": {
178+
"self": {
179+
"href": "https://docker.example.com/tenants/v2/sgci"
180+
},
181+
"publickey": {
182+
"href": "https://sgci.tacc.cloud/apim/v2/publickey"
183+
}
184+
}
185+
},
186+
{
187+
"id": "0001423978050162-b0b0b0bb0b-0001-016",
188+
"name": "TACC",
189+
"baseUrl": "https://api.tacc.utexas.edu/",
190+
"code": "tacc.prod",
191+
"contact": [
192+
{
193+
"name": "Joe Stubbs",
194+
"email": "jstubbs@tacc.utexas.edu",
195+
"url": "",
196+
"type": "admin",
197+
"primary": true
198+
}
199+
],
200+
"_links": {
201+
"self": {
202+
"href": "https://docker.example.com/tenants/v2/tacc.prod"
203+
},
204+
"publickey": {
205+
"href": "https://api.tacc.utexas.edu/apim/v2/publickey"
206+
}
207+
}
208+
},
209+
{
210+
"id": "0001411570898793-b0b0b0bb0b-0001-016",
211+
"name": "VDJ Server",
212+
"baseUrl": "https://vdj-agave-api.tacc.utexas.edu/",
213+
"code": "vdjserver.org",
214+
"contact": [
215+
{
216+
"name": "John Fonner",
217+
"email": "jfonner@tacc.utexas.edu",
218+
"url": "",
219+
"type": "admin",
220+
"primary": true
221+
}
222+
],
223+
"_links": {
224+
"self": {
225+
"href": "https://docker.example.com/tenants/v2/vdjserver.org"
226+
},
227+
"publickey": {
228+
"href": "https://vdj-agave-api.tacc.utexas.edu/apim/v2/publickey"
229+
}
230+
}
231+
}
232+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
tenants_endpoints.py
3+
4+
CLI integration tests for "tenants-*" cli commands.
5+
"""
6+
from flask import jsonify, request
7+
from flask_restful import Resource
8+
from .response_templates import response_template_to_json
9+
10+
11+
# Sample response for "apps-list" cli command.
12+
tenants_list_response = response_template_to_json("tenants-list.json")
13+
14+
15+
class AgaveTenants(Resource):
16+
""" Test tenants-* cli commands
17+
"""
18+
19+
def get(self):
20+
""" Test tenants-list utility
21+
22+
This test emulates the Agave API endpoint "/tenants/" for GET
23+
requests. To test it:
24+
25+
curl -sk 'https://localhost:5000/tenants?pretty=True'
26+
"""
27+
pretty_print = request.args.get("pretty", "")
28+
return jsonify(tenants_list_response)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bats
2+
3+
setup() {
4+
export AGAVE_CACHE_DIR=".tenants_init_cache_dir"
5+
}
6+
7+
teardown() {
8+
unset AGAVE_CACHE_DIR
9+
}
10+
11+
@test "Check that 'tenants-init' will error out if API is unavailable" {
12+
export AGAVE_TENANTS_API_BASEURL="https://site.is.down"
13+
run tenants-init -t sd2e
14+
[ $status = 1 ]
15+
unset AGAVE_TENANTS_API_BASEURL
16+
}
17+
18+
@test "Check that 'tenants-init' will set tenant to 'sd2e' and create current cache file" {
19+
run tenants-init -t sd2e
20+
[ $status = 0 ]
21+
[ -e "${AGAVE_CACHE_DIR}/current" ]
22+
tenant=$(jq .tenantid ${AGAVE_CACHE_DIR}/current | tr -d '"')
23+
[ "$tenant" == "sd2e" ]
24+
}
25+
26+
@test "Check that 'tenants-init -b' will set tenant to 'iplantc.org' and create backup cache file" {
27+
run tenants-init -t iplantc.org -b
28+
[ $status = 0 ]
29+
[ -e "${AGAVE_CACHE_DIR}/current" ]
30+
tenant=$(jq .tenantid ${AGAVE_CACHE_DIR}/current | tr -d '"')
31+
[ -e "${AGAVE_CACHE_DIR}/backup" ]
32+
backup=$(jq .tenantid ${AGAVE_CACHE_DIR}/backup | tr -d '"')
33+
[ "$tenant" == "iplantc.org" ]
34+
[ "$backup" == "sd2e" ]
35+
}
36+
37+
@test "Check that 'tenants-init -s' will set tenant to 'sd2e' and backup to 'iplantc.org'" {
38+
run tenants-init -s
39+
[ $status = 1 ]
40+
tenant=$(jq .tenantid ${AGAVE_CACHE_DIR}/current | tr -d '"')
41+
backup=$(jq .tenantid ${AGAVE_CACHE_DIR}/backup | tr -d '"')
42+
[ "$tenant" == "sd2e" ]
43+
[ "$backup" == "iplantc.org" ]
44+
}
45+
46+
@test "Check that 'tenants-init -r' will set tenant to 'iplantc.org' and delete backup cache file" {
47+
run tenants-init -r
48+
[ $status = 1 ]
49+
[ -e "${AGAVE_CACHE_DIR}/current" ]
50+
tenant=$(jq .tenantid ${AGAVE_CACHE_DIR}/current | tr -d '"')
51+
[ "$tenant" == "iplantc.org" ]
52+
[ ! -e "${AGAVE_CACHE_DIR}/backup" ]
53+
rm -rf ${AGAVE_CACHE_DIR}
54+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bats
2+
3+
@test "Check that 'tenants-list' will list available tenants" {
4+
run tenants-list
5+
[ $status = 0 ]
6+
[ "${lines[0]}" = "3dem" ]
7+
}
8+
9+
@test "Check that 'tenants-list' will error out if API is unavailable" {
10+
export AGAVE_TENANTS_API_BASEURL="https://site.is.down"
11+
run tenants-list
12+
[ $status = 1 ]
13+
unset AGAVE_TENANTS_API_BASEURL
14+
}

0 commit comments

Comments
 (0)