-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
1223 lines (979 loc) · 41.1 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import time
import json
import os
from pprint import pformat
from tornado.httpclient import HTTPClientError
from tornado.simple_httpclient import HTTPTimeoutError
import test.data
from test import (
grids,
sms_gateway,
device_management,
workforce_management,
partners_solutions
)
LOAD_ENV_VARS = True
EXTRACT_DATA_FROM_SDK_RESPONSE = True
CLIENT_TYPE_SYNC = "Sync"
CLIENT_TYPE_ASYNC = "Async"
# region Service Names and respective Ops
# region SCGrids
SERVICE_ID_GRIDS = grids.SERVICE_ID
GRIDS_OP_GET_ZONE_INFO = grids.OP_READ_ZONE
GRIDS_OP_GET_BUILDING_INFO = grids.OP_READ_BUILDING
GRIDS_OP_GET_PROPERTY_INFO = grids.OP_READ_PROPERTY
# endregion
# region SCDeviceManagement
SERVICE_ID_DEVICE_MANAGEMENT = device_management.SERVICE_ID
DEVICE_MANAGEMENT_OP_REALSENSE_MIGRATED = device_management.OP_REALSENSE_MIGRATED
DEVICE_MANAGEMENT_OP_GET_DEVICE_SLOTS = device_management.OP_GET_DEVICE_SLOTS
# endregion
# region SCWorkforceManagement
SERVICE_ID_WORKFORCE_MANAGEMENT = workforce_management.SERVICE_ID
WORKFORCE_MGMT_OP_ASSIGN_INCIDENT = workforce_management.OP_ASSIGN_INCIDENT
WORKFORCE_MGMT_OP_FIND_AVAILABILITY = workforce_management.OP_FIND_AVAILABILITY
WORKFORCE_MGMT_OP_CREATE_INCIDENT_NO_ASSIGNEE = workforce_management.OP_CREATE_INCIDENT_NO_ASSIGNEE
WORKFORCE_MGMT_OP_GET_INCIDENT_SETTINGS = workforce_management.OP_GET_INCIDENT_SETTINGS
# endregion
# region SCSMSGateway
SERVICE_ID_SMS_GATEWAY = sms_gateway.SERVICE_ID
SMS_GATEWAY_OP_PUBLISH_SMS = sms_gateway.OP_PUBLISH_SMS
# endregion
# region SCPartnersSolutions
SERVICE_ID_PARTNERS_SOLUTIONS = partners_solutions.SERVICE_ID
OPS = partners_solutions.OPS
# endregion
# endregion
# region Tests inside these functions have been included in the respective Service test function
def test_get_property_info(
org: str = None, pid: str = None, prop_id: str = None, test_client=CLIENT_TYPE_ASYNC
):
print("Starting test for a function in Grids service..")
if org is None:
org = os.environ["TEST_ORG"]
if pid is None:
pid = os.environ["TEST_PID"]
if prop_id is None:
prop_id = os.environ["TEST_PROP_ID"]
from SDK.SCGridsServices.API import SCGrids
print("SCGrids imported from respective service directory.")
grids = SCGrids()
print("SCGrids instantiated.")
read_prop_resp = grids.readProperty(org, pid, prop_id, test_client)
print("Read property request complete. Response is:")
print(read_prop_resp)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = read_prop_resp
print("Obtained response")
else:
status_code = read_prop_resp.status_code
print(f"Status code in this response is: {status_code}")
response_content = read_prop_resp.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content["data"]
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
def test_get_building_info(
org: str = None, pid: str = None, test_client=CLIENT_TYPE_ASYNC
):
print("Starting test for get_building_info...")
if org is None:
org = os.environ["TEST_ORG"]
if pid is None:
pid = os.environ["TEST_PID"]
from SDK.SCGridsServices.API import SCGrids
print("SCGrids imported from respective service directory.")
grids = SCGrids()
print("SCGrids instantiated.")
read_building_resp = grids.readBuilding(org, pid, test_client)
print("Read building request complete. Response is:")
print(read_building_resp)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = read_building_resp
print("Obtained response")
else:
status_code = read_building_resp.status_code
print(f"Status code in this response is: {status_code}")
response_content = read_building_resp.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content["data"]
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
def test_get_zone_info(
org: str = None, pid: str = None, zone_id: str = None, test_client=CLIENT_TYPE_ASYNC
):
print("Starting test for Get Zone Info...")
if org is None:
org = os.environ["TEST_ORG"]
if pid is None:
pid = os.environ["TEST_PID"]
if zone_id is None:
zone_id = os.environ["TEST_ZONE_ID"]
from SDK.SCGridsServices.API import SCGrids
print("SCGrids imported from respective service directory.")
grids = SCGrids()
print("SCGrids instantiated.")
request_body = {"InsID": zone_id}
read_zone_resp = grids.read_zone(org, pid, json.dumps(request_body), test_client)
print("Read zone request complete. Response is:")
print(read_zone_resp)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = read_zone_resp
print("Obtained response")
else:
status_code = read_zone_resp.status_code
print(f"Status code in this response is: {status_code}")
response_content = read_zone_resp.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content["data"]
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
def test_create_incident_without_assignee(
org: str = None,
pid: str = None,
prop_id: str = None,
zone_id: str = None,
test_client=CLIENT_TYPE_ASYNC,
):
print("Starting test for Create Incident No Assignee...")
if org is None:
org = os.environ["TEST_ORG"]
if pid is None:
pid = os.environ["TEST_PID"]
if prop_id is None:
prop_id = os.environ["TEST_PROP_ID"]
if zone_id is None:
zone_id = os.environ["TEST_ZONE_ID"]
from SDK.SCWorkforceManagementServices.API import SCWorkforcemanagement
print("SCWorkforcemanagement imported from respective service directory.")
scworkforcemanagement = SCWorkforcemanagement()
print("SCWorkforcemanagement instantiated.")
test_zone_details = {
"zone_id": zone_id,
"zone_category_id": f"Test Cat ID for ZoneID: {zone_id}",
"zone_name": f"Test Name for ZoneID: {zone_id}",
}
request_body = {"Incident": _create_data_for_incident(test_zone_details)}
create_incident_resp = scworkforcemanagement.createIncidentWithoutAssignee(
org, prop_id, pid, json.dumps(request_body), test_client
)
print("Create incident request complete. Response is:")
print(create_incident_resp)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = create_incident_resp
print("Obtained response")
else:
status_code = create_incident_resp.status_code
print(f"Status code in this response is: {status_code}")
response_content = create_incident_resp.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content["data"]
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
def test_find_availability_for_incident(
org: str = None,
pid: str = None,
prop_id: str = None,
zone_id: str = None,
test_client=CLIENT_TYPE_ASYNC,
return_mock: bool = True,
):
print("Starting test to Find availability for Incident...")
if org is None:
org = os.environ["TEST_ORG"]
if pid is None:
pid = os.environ["TEST_PID"]
if prop_id is None:
prop_id = os.environ["TEST_PROP_ID"]
if zone_id is None:
zone_id = os.environ["TEST_ZONE_ID"]
from SDK.SCWorkforceManagementServices.API import SCWorkforcemanagement
print("SCWorkforcemanagement imported from respective service directory.")
scworkforcemanagement = SCWorkforcemanagement()
print("SCWorkforcemanagement instantiated.")
if return_mock is True:
response_content = WORKFORCE_FIND_AVAILABILITY_RESPONSE_2
else:
curr_unix_time = int(time.time())
end_unix_time = (
curr_unix_time + 900
) # Adding 15 minutes to current for due time.
request_body = {"EndTime": end_unix_time, "ZoneID": [zone_id]}
response = scworkforcemanagement.find_availability_for_incident(
org, prop_id, pid, json.dumps(request_body), test_client
)
print("Find availability request complete. Response is:")
print(response)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = response
print("Obtained response")
else:
status_code = response.status_code
print(f"Status code in this response is: {status_code}")
response_content = response.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content["data"]
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
def test_assign_incident(test_client=CLIENT_TYPE_ASYNC, return_mock: bool = True):
print('Starting test to Assign Incident...')
if return_mock is True:
response_content = WORKFORCE_ASSIGN_INCIDENT_RESPONSE
else:
org = os.environ['TEST_ORG']
pid = os.environ['TEST_PID']
prop_id = os.environ['TEST_PROP_ID']
zone_id = os.environ['TEST_ZONE_ID']
from SDK.SCWorkforceManagementServices.API import SCWorkforcemanagement
print('SCWorkforcemanagement imported from respective service directory.')
scworkforcemanagement = SCWorkforcemanagement()
print('SCWorkforcemanagement instantiated.')
seat_id = os.environ['TEST_SEAT_ID']
shift_id = os.environ['TEST_SHIFT_ID']
incident_id = os.environ['TEST_INCIDENT_ID']
zone_id_for_assign_incident = '8a6ef71079e54af2884563e93c4ad800'
request_body = {
"SeatId": seat_id,
"ShiftID": shift_id,
"zoneId": zone_id_for_assign_incident,
"IncidentID": incident_id
}
response = scworkforcemanagement.assign_shift_to_incident(org, prop_id, pid, json.dumps(request_body),
test_client)
print('Find availability request complete. Response is:')
print(response)
print(f'{test_client} client was used for this request. Response will be parsed accordingly.')
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = response
print('Obtained response')
else:
status_code = response.status_code
print(f'Status code in this response is: {status_code}')
response_content = response.json()
print('Obtained .json() from response.')
# endregion
print('Type of response content is:')
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = 'Error in HTTP Request by sc-python-sdk'
_err_text = response_content.message
_status_code = response_content.code
return_text = f'{_status_text}: code: {_status_code}| message: {_err_text}'
print(return_text)
return
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content['data']
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
# endregion
def _create_data_for_incident(zone_details: dict):
test_task_details = {"Name": "Test Task in Incident", "Comments": "No Comments"}
zone_cat_id = zone_details["zone_category_id"]
zone_name = zone_details["zone_name"]
zone_id = zone_details["zone_id"]
curr_unix_time = int(time.time())
end_unix_time = curr_unix_time + 900
test_source_type = "Test Type"
incident_data = {
"Start": curr_unix_time,
"End": end_unix_time,
"Name": "Test Incident",
"Priority": "H",
"By": test_source_type,
"Subject": "Test Incident Subject",
"AutoAssigned": True,
"Tasks": [test_task_details],
"ZoneCatId": zone_cat_id,
"Zone": zone_id,
"ZoneName": zone_name,
}
return incident_data
def load_env_vars(load_from_dotenv_file: bool = False, dotenv_filepath: str = None):
from dotenv import load_dotenv
if load_from_dotenv_file is True:
print("Loading variables from standard environment file into environment...")
if dotenv_filepath is None:
root_dir = os.path.dirname(os.path.abspath(__file__))
print(f"Root directory is:")
print(root_dir)
filepath = f"{root_dir}/env-dev.env"
print("env file path is:")
print(filepath)
else:
raise Exception("Currently not loading vars from dotenv file (TODO later)")
load_dotenv(filepath)
print("Loaded vars from above .env file in current environment.")
else:
print('Setting env vars manually.')
os.environ['TEST_ORG'] = 'TestOrgId'
os.environ['TEST_PID'] = 'TestPID'
os.environ['SC_DEVICE_MANAGEMENT_HOST'] = ''
os.environ['SC_DEVICE_MANAGEMENT_HTTP_PROTOCOL'] = ''
os.environ['SC_DEVICE_MANAGEMENT_PORT'] = ''
def run_test(service: str, op: str, org: str = None, prop_id: str = None, pid: str = None, return_mock: bool = True):
if LOAD_ENV_VARS is True:
load_env_vars(load_from_dotenv_file=True)
if org is None:
org = os.environ['TEST_ORG']
if pid is None:
pid = os.environ['TEST_PID']
if prop_id is None:
prop_id = os.environ['TEST_PROP_ID']
client = CLIENT_TYPE_ASYNC
if service == device_management.SERVICE_ID:
test_device_management_api(op, org, prop_id, pid, client, return_mock)
elif service == grids.SERVICE_ID:
test_grids_api(op, org, prop_id, pid, client, return_mock)
elif service == workforce_management.SERVICE_ID:
test_workforce_apis(op, org, prop_id, pid, client, return_mock)
elif service == sms_gateway.SERVICE_ID:
test_sms_gateway_apis(op, org, prop_id, pid, client, return_mock)
elif service == partners_solutions.SERVICE_ID:
test_partners_solutions_op(op, org, prop_id, client, return_mock)
else:
raise Exception('Test Requests for service not yet added')
TEST_DEVICE_ALIAS_ID = 'TestDeviceAlias'
TEST_CLIENT = CLIENT_TYPE_ASYNC
TEST_READ_ZONE_RESPONSE = {
"status": 200,
"message": "Success",
"data": {
"OrgId": "OCBC",
"PropId": "f63385a2b32d4c0d9da70e1cd1e18f9d",
"PID": "90005c6aa28c44228b75904ee4fbb05d",
"LID": "8a243ff483424602b0d3c7f3016336e2",
"InsID": "f7ae7d1adc054586bd4753388c243efc",
"BeaconID": "N.A.",
"ZoneCategoryID": "MEETING_ROOMS",
"Name": "Executive Meeting Room",
"Area": 200,
"FloorType": "Carpet",
"Status": "Active",
"OperatingHours": {
"0": [{"End": "0000", "Start": "0000"}],
"1": [{"End": "1700", "Start": "0900"}],
"2": [{"End": "2000", "Start": "0900"}],
"3": [{"End": "1700", "Start": "0800"}],
"4": [{"End": "1700", "Start": "0900"}],
"5": [{"End": "1700", "Start": "1700"}],
"6": [{"End": "1800", "Start": "0700"}],
},
"IsBuildingOperatingHours": True,
},
}
TEST_READ_BUILDING_RESPONSE = {
"status": 200,
"message": "Success",
"data": {},
}
TEST_READ_PROPERTY_RESPONSE = {
"status": 200,
"message": "Success",
"data": {},
}
TEST_INCIDENT_RECORD = {
"ATTR": "attr#90005c6aa28c44228b75904ee4fbb05d#8a6ef71079e54af2884563e93c4ad800#1621387048000",
"AutoAssigned": 1,
"By": "FD",
"Delayed": 0,
"End": 1621387948,
"ID": "90005c6aa28c44228b75904ee4fbb05d",
"Name": "User Feedback",
"NS": "TS",
"Priority": "H",
"PropID": "f63385a2b32d4c0d9da70e1cd1e18f9d",
"SeatId": "tbp",
"ShiftId": "tbp",
"SRN": "srn:sctasks:OCBC:::f63385a2b32d4c0d9da70e1cd1e18f9d/90005c6aa28c44228b75904ee4fbb05d:TS:INCIDENT/1621387048000",
"Start": 1621387048,
"Status": "NOT_ASSIGNED",
"Subject": "Information",
"taskCount": 1,
"TaskId": "1621387048000",
"Tasks": [
{
"Comments": "No Toilet Paper, No Soap",
"Done": 0,
"Name": "User Feedback",
"T": 0,
}
],
"Type": "INCIDENT",
"Zone": "8a6ef71079e54af2884563e93c4ad800",
"ZoneCatId": "MEETING_ROOMS",
"ZoneName": "Meeting Room",
}
# region Find availability for incident Sample Response
# Test Response. Includes 2 Seat IDs. Seat 1 has Shift without task assigned,
# Seat 2 has task assigned, but shows 2 objects TODO: (why?)
# is it because it may have 2 tasks assigned to the same Shift?
# Datetime: 18 May 2021, 10:05 AM SGT
WORKFORCE_FIND_AVAILABILITY_RESPONSE_2 = {
"message": "Available entries for given Zone",
"data": {
"Seat1": [
{
"ShiftID": "6bdbe62e-4ab1-4750-8318-503a10175fb4",
"ZoneName": None,
"SameZone": False,
"Status": "PUBLISHED",
"StartTime": 1621306800,
"ZoneID": None,
}
],
"Seat2": [
{
"ShiftID": "6e2991d7-7405-4ab3-9f45-4c96575be064",
"ZoneName": "Meeting Room",
"SameZone": True,
"Status": "PUBLISHED",
"StartTime": 1621299600,
"ZoneID": "ZoneId1",
},
{
"ShiftID": "6e2991d7-7405-4ab3-9f45-4c96575be064",
"ZoneName": "Meeting Room",
"SameZone": True,
"Status": "PUBLISHED",
"StartTime": 1621317600,
"ZoneID": "ZoneId1",
},
],
},
"code": "SUCCESS",
}
# endregion
# region Assign Incident sample success response (forged manually)
# Created on 01 June 2021, 2:03 SGT
WORKFORCE_ASSIGN_INCIDENT_RESPONSE = {
"message": "Incident has been successfully assigned to <seat_id>",
"code": "SUCCESS"
}
# endregion
# region Sample response for Device Management
MOCK_RESPONSE_DEVICE_MGMT_REAL_SENSE_MIGRATED = {
'ID': 'TestPID',
'Migrated': False
}
MOCK_RESPONSE_DEVICE_MGMT_GET_DEVICE_SLOTS = {
'Slots': [
{'ATTR': 'attr#devices#info#ID',
'Alias': 'TestAliasId',
'Commissioned': 0,
'Conn': 'BLE',
'CreatedBy': 'smartclean',
'CreatedOn': 1635494680,
'DeviceNotAssociated': 0,
'Devid': '55954A2B11',
'Display': 'Paper Towel',
'FirmwareVersion': '2',
'ID': 'SCDevices#ID',
'LID': '7911afb00468475da10ae8a57bdfe80b',
'NS': 'DEVICE_INFO_GENERAL',
'Org': 'LHN',
'PID': 'TestPID',
'Params': {'DeviceParams': {'MAX': 110, 'OFFSET': 5}},
'ParamsNotConfigured': 1,
'ParamsOnDeviceNotConfigured': 0,
'PartnerId': 'SMARTCLEAN',
'PropId': 'TestPropId',
'ProviderOrg': 'SMARTCLEAN',
'RequiresHealthCheck': 1,
'RequiresOnDeviceConfiguration': 0,
'RequiresParamsConfiguration': 1,
'SRN': 'null',
'TZ': 'Asia/Singapore',
'Type': 'SMARTCLEAN#DevType',
'Unhealthy': 0,
'UpdatedBy': 'smartclean',
'UpdatedOn': 1635496487,
'ZoneId': 'ZoneID'}
],
'code': 'SUCCESS',
'message': 'Successfully fetched given slots'
}
# endregion
MOCK_RESPONSE_SEND_SMS = {
"code": "SUCCESS",
"message": "Successfully sent SMS to phone numbers"
}
# region Test desired Op in desired Service
def test_device_management_api(op: str, org: str, prop_id: str, pid: str, client: str, return_mock: bool = True):
# Supply args to mocker to update the mock data
if return_mock is True:
response_mocker = test.data.SCDeviceManagement(client)
_create_mock_resp = response_mocker.create_response_for_op(op)
mock_response = _create_mock_resp['response']
mock_response_status = _create_mock_resp['text']
if mock_response is None:
raise Exception(f'Failed to create mock response ({mock_response_status})')
response_content = mock_response
else:
from SDK.SCDeviceManagement.API import SCDeviceManagement
print("SCDevicemanagement imported from respective service directory.")
scdevicemanagement = SCDeviceManagement()
print("SCDeviceManagement instantiated.")
test_client = TEST_CLIENT
if op == 'realSenseMigrated':
response = scdevicemanagement.realSenseMigrated(
org, pid, prop_id, test_client)
print(f'{op} request complete. Response is:')
print(response)
else:
request_body = {
"Alias": ['cdf4ecd4fba24eb9834d65bdf6cff36f']
}
response = scdevicemanagement.getDeviceSlots(
org, pid, prop_id, json.dumps(request_body), test_client
)
print("getDeviceSlots request. Response is:")
print(response)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = response
print("Obtained response")
else:
status_code = response.status_code
print(f"Status code in this response is: {status_code}")
response_content = response.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
# Example of error response:
# Error in HTTP Request by sc-python-sdk: code: 400| message: Bad Request
print("Keys in Response content is:")
print(list(response_content.keys()))
print('Response content is:')
print(pformat(response_content))
def test_grids_api(op: str, org: str, prop_id: str, pid: str, client: str, return_mock: bool = True):
# SUpply args to mocker to update the mock data
if return_mock is True:
response_mocker = test.data.SCGrids(client)
_create_mock_resp = response_mocker.create_response_for_op(op)
mock_response = _create_mock_resp['response']
mock_response_status = _create_mock_resp['text']
if mock_response is None:
raise Exception(f'Failed to create mock response ({mock_response_status})')
response_content = mock_response
else:
from SDK.SCGridsServices.API import SCGrids
print('SCGrids imported from respective service directory.')
grids = SCGrids()
print('SCGrids instantiated.')
test_client = TEST_CLIENT
if op == GRIDS_OP_GET_ZONE_INFO:
zone_id = os.environ["TEST_ZONE_ID"]
request_body = {"InsID": zone_id}
response = grids.read_zone(org, pid, prop_id, json.dumps(request_body), test_client)
print(f'{op} request complete. Response is:')
print(response)
elif op == GRIDS_OP_GET_PROPERTY_INFO:
response = grids.readProperty(org, pid, prop_id, test_client)
else:
response = grids.readBuilding(org, pid, prop_id, test_client)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = response
print("Obtained response")
else:
status_code = response.status_code
print(f"Status code in this response is: {status_code}")
response_content = response.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
# Example of error response:
# Error in HTTP Request by sc-python-sdk: code: 400| message: Bad Request
print("Keys in Response content is:")
print(list(response_content.keys()))
if EXTRACT_DATA_FROM_SDK_RESPONSE is True:
desired_data = response_content["data"]
print('Extracted "data" from response. Data is:')
print(pformat(desired_data))
def test_workforce_apis(op: str, org: str, prop_id: str, pid: str, client: str, return_mock: bool = True):
if org is None:
org = os.environ["TEST_ORG"]
if pid is None:
pid = os.environ["TEST_PID"]
if client is None:
client = CLIENT_TYPE_ASYNC
if return_mock is True:
response_mocker = test.data.SCWorkforceManagement(client)
_create_mock_resp = response_mocker.create_response_for_op(op)
mock_response = _create_mock_resp['response']
mock_response_status = _create_mock_resp['text']
if mock_response is None:
raise Exception(f'Failed to create mock response ({mock_response_status})')
response_content = mock_response
else:
from SDK.SCWorkforceManagementServices.API import SCWorkforcemanagement
print("SCWorkforcemanagement imported from respective service directory.")
scworkforcemanagement = SCWorkforcemanagement()
print("SCWorkforcemanagement instantiated.")
test_client = TEST_CLIENT
zone_id = os.environ["TEST_ZONE_ID"]
if op == WORKFORCE_MGMT_OP_FIND_AVAILABILITY:
curr_unix_time = int(time.time())
end_unix_time = (
curr_unix_time + 900
) # Adding 15 minutes to current for due time.
request_body = {
"EndTime": end_unix_time,
"ZoneID": [zone_id]
}
response = scworkforcemanagement.find_availability_for_incident(
org, pid, prop_id, json.dumps(request_body), test_client
)
print(f'{op} request complete. Response is:')
print(response)
elif op == WORKFORCE_MGMT_OP_CREATE_INCIDENT_NO_ASSIGNEE:
test_zone_details = {
"zone_id": zone_id,
"zone_category_id": f"Test Cat ID for ZoneID: {zone_id}",
"zone_name": f"Test Name for ZoneID: {zone_id}",
}
request_body = {
"Incident": _create_data_for_incident(test_zone_details)
}
response = scworkforcemanagement.createIncidentWithoutAssignee(
org, pid, prop_id, json.dumps(request_body), test_client
)
elif op == WORKFORCE_MGMT_OP_GET_INCIDENT_SETTINGS:
response = scworkforcemanagement.get_incident_settings(org, pid, prop_id, test_client)
else:
seat_id = os.environ['TEST_SEAT_ID']
shift_id = os.environ['TEST_SHIFT_ID']
incident_id = os.environ['TEST_INCIDENT_ID']
request_body = {
"SeatId": seat_id,
"ShiftID": shift_id,
"zoneId": zone_id,
"IncidentID": incident_id
}
response = scworkforcemanagement.assign_shift_to_incident(
org, pid, prop_id, json.dumps(request_body), test_client)
print(
f"{test_client} client was used for this request. Response will be parsed accordingly."
)
# region Parse response based on type of client
if test_client == CLIENT_TYPE_ASYNC:
response_content = response
print("Obtained response")
else:
status_code = response.status_code
print(f"Status code in this response is: {status_code}")
response_content = response.json()
print("Obtained .json() from response.")
# endregion
print("Type of response content is:")
type_response = type(response_content)
print(type_response)
if type_response is HTTPClientError or type_response is HTTPTimeoutError:
_status_text = "Error in HTTP Request by sc-python-sdk"
_err_text = response_content.message
_status_code = response_content.code
return_text = f"{_status_text}: code: {_status_code}| message: {_err_text}"
print(return_text)
return
# Example of error response:
# Error in HTTP Request by sc-python-sdk: code: 400| message: Bad Request
print("Keys in Response content is:")
print(list(response_content.keys()))