Skip to content

Commit b1e4087

Browse files
committed
Created tests for check_username
Also added admin header to currentFiles and statistics. moved in file
1 parent ba4f13a commit b1e4087

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

src/server/test_api.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ def test_client_dns():
7070
# Simple API tests ################################################
7171

7272

73-
def test_currentFiles():
74-
"""360 view Current Files list"""
75-
response = requests.get(SERVER_URL + "/api/listCurrentFiles")
76-
assert response.status_code == 200
77-
78-
79-
def test_statistics():
80-
"""360 view Statistics"""
81-
response = requests.get(SERVER_URL + "/api/statistics")
82-
assert response.status_code == 200
83-
8473

8574
def test_usertest():
8675
"""Verify liveness test works"""
@@ -181,6 +170,36 @@ def test_admingetusers(state: State):
181170
userlist = response.json()
182171
assert len(userlist) > 1
183172

173+
def test_check_usernames(state: State):
174+
"""Verify logged-in base_admin can test usernames, gets correct result - existing user """
175+
# Build auth string value including token from state
176+
b_string = 'Bearer ' + state.state['base_admin']
177+
178+
assert len(b_string) > 24
179+
180+
auth_hdr = {'Authorization' : b_string}
181+
182+
data = {"username":"base_admin"}
183+
response = requests.post(SERVER_URL + "/api/admin/user/check_name", headers=auth_hdr, json=data)
184+
assert response.status_code == 200
185+
186+
is_user = response.json()
187+
assert is_user == 1
188+
189+
def test_check_badusernames(state: State):
190+
"""Verify logged-in base_admin can test usernames, gets correct result - nonexistant user """
191+
# Build auth string value including token from state
192+
b_string = 'Bearer ' + state.state['base_admin']
193+
assert len(b_string) > 24
194+
auth_hdr = {'Authorization' : b_string}
195+
196+
data = {"username":"got_no_username_like_this"}
197+
response = requests.post(SERVER_URL + "/api/admin/user/check_name", headers=auth_hdr, json=data)
198+
assert response.status_code == 200
199+
200+
is_user = response.json()
201+
assert is_user == 0
202+
184203

185204
def test_usergetusers(state: State):
186205
"""Verify logged-in base_user *cannot* use JWT to get user list """
@@ -192,3 +211,25 @@ def test_usergetusers(state: State):
192211
auth_hdr = {'Authorization' : b_string}
193212
response = requests.get(SERVER_URL + "/api/admin/user/get_users", headers=auth_hdr)
194213
assert response.status_code == 403
214+
215+
216+
def test_currentFiles(state: State):
217+
"""360 view Current Files list"""
218+
219+
b_string = 'Bearer ' + state.state['base_admin']
220+
assert len(b_string) > 24
221+
auth_hdr = {'Authorization' : b_string}
222+
223+
response = requests.get(SERVER_URL + "/api/listCurrentFiles", headers=auth_hdr)
224+
assert response.status_code == 200
225+
226+
227+
def test_statistics(state: State):
228+
"""360 view Statistics"""
229+
230+
b_string = 'Bearer ' + state.state['base_admin']
231+
assert len(b_string) > 24
232+
auth_hdr = {'Authorization' : b_string}
233+
234+
response = requests.get(SERVER_URL + "/api/statistics", headers=auth_hdr)
235+
assert response.status_code == 200

0 commit comments

Comments
 (0)