|
1 | 1 | import pytest, socket, requests, os
|
2 | 2 |
|
3 |
| -from secrets import BASEUSER_PW, BASEADMIN_PW |
| 3 | + |
| 4 | +try: |
| 5 | + from secrets import BASEUSER_PW, BASEADMIN_PW |
| 6 | +except KeyError: |
| 7 | + BASEUSER_PW = os.environ['BASEUSER_PW'] |
| 8 | + BASEADMIN_PW = os.environ['BASEADMIN_PW'] |
| 9 | + |
4 | 10 |
|
5 | 11 | jwt_token = ''
|
6 | 12 |
|
7 | 13 | #
|
8 |
| -# Run 'pytest' from the command line |
| 14 | +# Run 'pytest' from the command line (-v gives helpful details) |
9 | 15 | #
|
10 | 16 | # Running pytest can result in six different exit codes:
|
11 | 17 | # 0 - All tests were collected and passed successfully
|
@@ -68,20 +74,6 @@ def test_client_dns():
|
68 | 74 | assert len(gai) > 0
|
69 | 75 |
|
70 | 76 | # Simple API tests ################################################
|
71 |
| - |
72 |
| - |
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 |
| - |
84 |
| - |
85 | 77 | def test_usertest():
|
86 | 78 | """Verify liveness test works"""
|
87 | 79 | response = requests.get(SERVER_URL + "/api/user/test")
|
@@ -147,6 +139,10 @@ def test_inact_userblocked(state: State):
|
147 | 139 | assert response.status_code == 401
|
148 | 140 |
|
149 | 141 |
|
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
150 | 146 | ### Admin-level tests ######################################
|
151 | 147 |
|
152 | 148 | def test_adminlogin(state: State):
|
@@ -182,6 +178,28 @@ def test_admingetusers(state: State):
|
182 | 178 | assert len(userlist) > 1
|
183 | 179 |
|
184 | 180 |
|
| 181 | +def test_admin_currentFiles(state: State): |
| 182 | + """Verify admin user can get Current Files list""" |
| 183 | + |
| 184 | + b_string = 'Bearer ' + state.state['base_admin'] |
| 185 | + assert len(b_string) > 24 |
| 186 | + auth_hdr = {'Authorization' : b_string} |
| 187 | + |
| 188 | + response = requests.get(SERVER_URL + "/api/listCurrentFiles", headers=auth_hdr) |
| 189 | + assert response.status_code == 200 |
| 190 | + |
| 191 | + |
| 192 | +def test_admin_statistics(state: State): |
| 193 | + """360 view Statistics""" |
| 194 | + |
| 195 | + b_string = 'Bearer ' + state.state['base_admin'] |
| 196 | + assert len(b_string) > 24 |
| 197 | + auth_hdr = {'Authorization' : b_string} |
| 198 | + |
| 199 | + response = requests.get(SERVER_URL + "/api/statistics", headers=auth_hdr) |
| 200 | + assert response.status_code == 200 |
| 201 | + |
| 202 | + |
185 | 203 | def test_usergetusers(state: State):
|
186 | 204 | """Verify logged-in base_user *cannot* use JWT to get user list """
|
187 | 205 | # Build auth string value including token from state
|
|
0 commit comments