31
31
SERVER_URL = "http://server:5000"
32
32
IS_LOCAL = False
33
33
34
+
35
+ try :
36
+ from secrets_dict import SHELTERLUV_SECRET_TOKEN
37
+ except ImportError :
38
+ SHELTERLUV_SECRET_TOKEN = os .getenv ("SHELTERLUV_SECRET_TOKEN" )
39
+ finally :
40
+ SL_Token = True if SHELTERLUV_SECRET_TOKEN else False
41
+
42
+
34
43
### DNS lookup tests ##############################
35
44
36
45
def test_bad_dns ():
@@ -138,11 +147,6 @@ def test_inact_userblocked(state: State):
138
147
response = requests .post (SERVER_URL + "/api/user/login" , json = data )
139
148
assert response .status_code == 401
140
149
141
-
142
-
143
-
144
-
145
-
146
150
### Admin-level tests ######################################
147
151
148
152
def test_adminlogin (state : State ):
@@ -261,4 +265,109 @@ def test_statistics(state: State):
261
265
auth_hdr = {'Authorization' : b_string }
262
266
263
267
response = requests .get (SERVER_URL + "/api/statistics" , headers = auth_hdr )
264
- assert response .status_code == 200
268
+ assert response .status_code == 200
269
+
270
+
271
+ ### Shelterluv API tests ######################################
272
+
273
+ @pytest .mark .skipif (SL_Token , reason = "Not run when SL_Token Present" )
274
+ def test_user_get_person_animal_events (state : State ):
275
+ """ Test that the api returns mock data if the Shelterluv Token
276
+ is missing from secrets
277
+ """
278
+
279
+ # Build auth string value including token from state
280
+ b_string = 'Bearer ' + state .state ['base_user' ]
281
+
282
+ assert len (b_string ) > 24
283
+
284
+ auth_hdr = {'Authorization' : b_string }
285
+ url = SERVER_URL + "/api/person/12345/animal/12345/events"
286
+
287
+ try :
288
+ response = requests .get (url , headers = auth_hdr )
289
+ except Exception as err :
290
+ print (err )
291
+ else :
292
+ assert response .status_code == 200
293
+ from api .fake_data import sl_mock_data
294
+ assert response .json () == sl_mock_data ("events" )
295
+
296
+
297
+ @pytest .mark .skipif (SL_Token , reason = "Not run when SL_Token Present" )
298
+ def test_user_get_animals (state : State ):
299
+ """ Test that the api returns mock data if the Shelterluv Token
300
+ is missing from secrets
301
+ """
302
+
303
+ # Build auth string value including token from state
304
+ b_string = 'Bearer ' + state .state ['base_user' ]
305
+
306
+ assert len (b_string ) > 24
307
+
308
+ auth_hdr = {'Authorization' : b_string }
309
+ url = SERVER_URL + "/api/person/12345/animals"
310
+
311
+ try :
312
+ response = requests .get (url , headers = auth_hdr )
313
+ except Exception as err :
314
+ print (err )
315
+ else :
316
+ assert response .status_code == 200
317
+ from api .fake_data import sl_mock_data
318
+ assert response .json () == sl_mock_data ("animals" )
319
+
320
+
321
+ @pytest .mark .skipif (not SL_Token , reason = "Run when SL_Token Present" )
322
+ def test_user_get_animals_sl_token (state : State ):
323
+ """ Test to confirm api does not return mock values if the Shelterluv Token
324
+ is present in the secrets_dict file.
325
+ Note this works on the assumption the SL token is not valid, and returns
326
+ a default empty value
327
+
328
+ >> This is tricky - if SL token is correct and person_id is valid, could get animal records returned.
329
+
330
+ """
331
+
332
+ # Build auth string value including token from state
333
+ b_string = 'Bearer ' + state .state ['base_user' ]
334
+
335
+ assert len (b_string ) > 24
336
+
337
+ auth_hdr = {'Authorization' : b_string }
338
+ url = SERVER_URL + "/api/person/12345/animals"
339
+
340
+ try :
341
+ response = requests .get (url , headers = auth_hdr )
342
+ except Exception as err :
343
+ print (err )
344
+ pytest .fail ('test_user_get_animals_sl_token - Request failed' , pytrace = False )
345
+ else :
346
+ assert response .status_code == 200
347
+ assert response .json () == {'person_details' : {}, 'animal_details' : {}}
348
+
349
+
350
+ @pytest .mark .skipif (not SL_Token , reason = "Run when SL_Token Present" )
351
+ def test_user_get_person_animal_events_sl_token (state : State ):
352
+ """ Test to confirm api does not return mock values if the Shelterluv Token
353
+ is present in the secrets_dict file.
354
+ Note this works on the assumption the SL token is not valid, and returns
355
+ a default empty value
356
+ """
357
+
358
+ # Build auth string value including token from state
359
+ b_string = 'Bearer ' + state .state ['base_user' ]
360
+
361
+ assert len (b_string ) > 24
362
+
363
+ auth_hdr = {'Authorization' : b_string }
364
+ url = SERVER_URL + "/api/person/12345/animal/12345/events"
365
+
366
+ try :
367
+ response = requests .get (url , headers = auth_hdr )
368
+ except Exception as err :
369
+ print (err )
370
+ pytest .fail ('test_user_get_person_animal_events_sl_token - Request failed' , pytrace = False )
371
+ else :
372
+ assert response .status_code == 200
373
+ assert response .json () == {}
0 commit comments