-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_api.py
3077 lines (2647 loc) · 142 KB
/
test_api.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 pymysql
from datetime import datetime
import json
from decimal import Decimal
import requests
from dotenv import load_dotenv
from flask_restful import Resource
import os
#python -m pytest -v -s Use this in cmd to run the pytest script
def connect():
conn = pymysql.connect(
host=os.getenv('RDS_HOST'),
user=os.getenv('RDS_USER'),
port=int(os.getenv('RDS_PORT')),
passwd=os.getenv('RDS_PW'),
db=os.getenv('RDS_DB'),
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
return DatabaseConnection(conn)
def serializeJSON(unserialized):
# print(unserialized, type(unserialized))
if type(unserialized) == list:
# print("in list")
serialized = []
for entry in unserialized:
serializedEntry = serializeJSON(entry)
serialized.append(serializedEntry)
return serialized
elif type(unserialized) == dict:
# print("in dict")
serialized = {}
for entry in unserialized:
serializedEntry = serializeJSON(unserialized[entry])
serialized[entry] = serializedEntry
return serialized
elif type(unserialized) == datetime.datetime:
# print("in date")
return str(unserialized)
elif type(unserialized) == bytes:
# print("in bytes")
return str(unserialized)
elif type(unserialized) == Decimal:
# print("in Decimal")
return str(unserialized)
else:
# print("in else")
return unserialized
class DatabaseConnection:
def __init__(self, conn):
self.conn = conn
def disconnect(self):
self.conn.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.disconnect()
def execute(self, sql, args=[], cmd='get'):
# print("In execute. SQL: ", sql)
# print("In execute. args: ",args)
# print("In execute. cmd: ",cmd)
response = {}
try:
with self.conn.cursor() as cur:
# print('IN EXECUTE')
if len(args) == 0:
# print('execute', sql)
cur.execute(sql)
else:
cur.execute(sql, args)
formatted_sql = f"{sql} (args: {args})"
# print(formatted_sql)
if 'get' in cmd:
# print('IN GET')
result = cur.fetchall()
result = serializeJSON(result)
# print('RESULT GET')
response['message'] = 'Successfully executed SQL query'
response['code'] = 200
response['result'] = result
# print('RESPONSE GET')
elif 'post' in cmd:
# print('IN POST')
self.conn.commit()
response['message'] = 'Successfully committed SQL query'
response['code'] = 200
# print('RESPONSE POST')
except Exception as e:
print('ERROR', e)
response['message'] = 'Error occurred while executing SQL query'
response['code'] = 500
response['error'] = e
print('RESPONSE ERROR', response)
return response
def select(self, tables, where={}, cols='*'):
response = {}
try:
sql = f'SELECT {cols} FROM {tables}'
for i, key in enumerate(where.keys()):
if i == 0:
sql += ' WHERE '
sql += f'{key} = %({key})s'
if i != len(where.keys()) - 1:
sql += ' AND '
response = self.execute(sql, where, 'get')
except Exception as e:
print(e)
return response
def insert(self, table, object):
response = {}
try:
sql = f'INSERT INTO {table} SET '
for i, key in enumerate(object.keys()):
sql += f'{key} = %({key})s'
if i != len(object.keys()) - 1:
sql += ', '
# print(sql)
# print(object)
response = self.execute(sql, object, 'post')
except Exception as e:
print(e)
return response
def update(self, table, primaryKey, object):
response = {}
try:
sql = f'UPDATE {table} SET '
print(sql)
for i, key in enumerate(object.keys()):
sql += f'{key} = %({key})s'
if i != len(object.keys()) - 1:
sql += ', '
sql += f' WHERE '
print(sql)
for i, key in enumerate(primaryKey.keys()):
sql += f'{key} = %({key})s'
object[key] = primaryKey[key]
if i != len(primaryKey.keys()) - 1:
sql += ' AND '
print(sql, object)
response = self.execute(sql, object, 'post')
print(response)
except Exception as e:
print(e)
return response
def delete(self, sql):
response = {}
try:
with self.conn.cursor() as cur:
cur.execute(sql)
self.conn.commit()
response['message'] = 'Successfully committed SQL query'
response['code'] = 200
# response = self.execute(sql, 'post')
except Exception as e:
print(e)
return response
def call(self, procedure, cmd='get'):
response = {}
try:
sql = f'CALL {procedure}()'
response = self.execute(sql, cmd=cmd)
except Exception as e:
print(e)
return response
ENDPOINT = "https://l0h6a9zi1e.execute-api.us-west-1.amazonaws.com/dev"
# Tables affecting: {maintenanceRequests, maintenanceQuotes, Properties, Property_Owner, Contracts, leases, lease_tenant, addPurchases, paymentMethods, payments}
class endPointTest_CLASS(Resource):
def get():
dt = datetime.today()
response = {}
# Insert temporary data into the database
try:
print("\n\n*** Inserting temporary data into the database ***\n")
insert_property_query = """
INSERT INTO `space`.`properties` (`property_uid`, `property_available_to_rent`, `property_active_date`, `property_listed_date`, `property_address`, `property_city`, `property_state`, `property_zip`, `property_longitude`, `property_latitude`, `property_type`, `property_num_beds`, `property_num_baths`, `property_value`, `property_value_year`, `property_area`, `property_listed_rent`, `property_deposit`, `property_pets_allowed`, `property_deposit_for_rent`, `property_featured`)
VALUES ('200-000000', '1', '10-28-2024', '10-28-2024', '123 Test Apt', 'San Jose', 'CA', '95119', '-121.7936071000', '37.2346668000', 'Single Family', '4', '2', '1500000', '2013', '2100', '2500', '1200', '1', '0', 'False');
"""
insert_property_owner_query = """
INSERT INTO `space`.`property_owner` (`property_id`, `property_owner_id`, `po_owner_percent`)
VALUES ('200-000000', '110-000000', '1');
"""
insert_users_query = """
INSERT INTO `space`.`users` (`user_uid`, `first_name`, `last_name`, `phone_number`, `email`, `role`, `notifications`, `dark_mode`, `cookies`)
VALUES ('100-000000', 'Test', 'Account', '(000) 000-0000', '[email protected]', 'OWNER,MANAGER,TENANT,MAINTENANCE', 'true', 'false', 'true');
"""
insert_business_profile_query = """
INSERT INTO `space`.`businessProfileInfo` (`business_uid`, `business_user_id`, `business_type`, `business_name`, `business_phone_number`, `business_email`)
VALUES ('600-000000', '100-000000', 'MANAGEMENT', 'Reserved For Test', '(000) 000-0000', '[email protected]');
"""
insert_owner_profile_query = """
INSERT INTO `space`.`ownerProfileInfo` (`owner_uid`, `owner_user_id`, `owner_first_name`, `owner_last_name`, `owner_phone_number`, `owner_email`)
VALUES ('110-000000', '100-000000', 'Test', 'Account', '(000) 000-0000', '[email protected]');
"""
insert_tenant_profile_query = """
INSERT INTO `space`.`tenantProfileInfo` (`tenant_uid`, `tenant_user_id`, `tenant_first_name`, `tenant_last_name`, `tenant_email`, `tenant_phone_number`, `tenant_documents`, `tenant_adult_occupants`, `tenant_children_occupants`, `tenant_vehicle_info`, `tenant_references`, `tenant_pet_occupants`, `tenant_employment`)
VALUES ('350-000000', '100-000000', 'Test', 'Account', '[email protected]', '(000) 000-0000', '[]', '[]', '[]', '[]', '[]', '[]', '[]');
"""
insert_purchases_query = """
INSERT INTO `space`.`purchases` (`purchase_uid`, `pur_timestamp`, `pur_property_id`, `purchase_type`, `pur_description`, `pur_notes`, `pur_cf_type`, `purchase_date`, `pur_due_date`, `pur_amount_due`, `purchase_status`, `pur_status_value`, `pur_receiver`, `pur_initiator`, `pur_payer`, `pur_late_Fee`, `pur_group`)
VALUES ('400-000000', '11-14-2024 00:00', '200-000000', 'Deposit', 'Test Deposit', 'Test Deposit Note', 'revenue', '11-15-2024 00:00', '11-30-2024 00:00', '299.00', 'UNPAID', '0', '110-000000', '350-000000', '350-000000', '0', '400-000000');
"""
insert_maintenance_requests_query = """
INSERT INTO `space`.`maintenanceRequests` (`maintenance_request_uid`, `maintenance_property_id`, `maintenance_request_status`, `maintenance_title`, `maintenance_request_type`, `maintenance_request_created_by`, `maintenance_priority`, `maintenance_can_reschedule`)
VALUES ('800-000000', '200-000000', 'NEW', 'Test Maintenance Request', 'Plumbing', '600-000000', 'Medium', '1');
"""
insert_maintenance_quotes_query = """
INSERT INTO `space`.`maintenanceQuotes` (`maintenance_quote_uid`, `quote_maintenance_request_id`, `quote_status`, `quote_business_id`, `quote_requested_date`)
VALUES ('900-000000', '800-000000', 'SCHEDULED', '600-000000', '11-12-2024 15:26:30');
"""
insert_contracts_query = """
INSERT INTO `space`.`contracts` (`contract_uid`, `contract_property_id`, `contract_business_id`, `contract_name`, `contract_status`, `contract_m2m`)
VALUES ('010-000000', '200-000000', '600-000000', 'Test Contract Name', 'ACTIVE', '1');
"""
update_contracts_query = """
UPDATE `space`.`contracts`
SET `contract_uid` = '010-000000'
WHERE (`contract_property_id` = '200-000000' AND `contract_business_id` = '600-000000' AND `contract_name` = 'Test Contract Name');
"""
insert_leases_query = """
INSERT INTO `space`.`leases` (`lease_uid`, `lease_property_id`, `lease_application_date`, `lease_start`, `lease_end`, `lease_status`, `lease_assigned_contacts`, `lease_documents`, `lease_renew_status`, `lease_move_in_date`, `lease_adults`, `lease_children`, `lease_pets`, `lease_vehicles`, `lease_referred`, `lease_effective_date`, `lease_docuSign`, `lease_end_notice_period`, `lease_income`, `lease_m2m`, `lease_utilities`)
VALUES ('300-000000', '200-000000', '11-15-2024', '11-19-2024', '11-19-2025', 'NEW', '[\"350-000000\"]', '[]', 'TRUE', '11-19-2024', '[]', '[]', '[]', '[]', '[]', '11-19-2024', 'null', '30', '[]', '1', '[]');
"""
update_leases_query = """
UPDATE `space`.`leases`
SET `lease_uid` = '300-000000'
WHERE (`lease_property_id` = '200-000000' AND `lease_status` = 'NEW');
"""
insert_lease_tenant_query = """
INSERT INTO `space`.`lease_tenant` (`lt_lease_id`, `lt_tenant_id`, `lt_responsibility`)
VALUES ('300-000000', '350-000000', '1');
"""
insert_lease_fees_query = """
INSERT INTO `space`.`leaseFees` (`leaseFees_uid`, `fees_lease_id`, `fee_name`, `fee_type`, `charge`, `frequency`, `available_topay`, `due_by`, `late_by`, `late_fee`, `perDay_late_fee`, `due_by_date`)
VALUES ('370-000000', '300-000000', 'Rent', 'Rent', '900.00', 'Monthly', '10', '5', '0', '0', '0.00', '12-19-2024');
"""
update_lease_fees_query = """
UPDATE `space`.`leaseFees`
SET `leaseFees_uid` = '370-000000'
WHERE (`fees_lease_id` = '300-000000' AND `fee_name` = 'Rent');
"""
with connect() as db:
insert_property_query_response = db.execute(insert_property_query, cmd='post')
insert_property_owner_query_response = db.execute(insert_property_owner_query, cmd='post')
insert_users_query_response = db.execute(insert_users_query, cmd='post')
insert_business_profile_query_response = db.execute(insert_business_profile_query, cmd='post')
insert_owner_profile_query_response = db.execute(insert_owner_profile_query, cmd='post')
insert_tenant_profile_query_response = db.execute(insert_tenant_profile_query, cmd='post')
insert_purchases_query_response = db.execute(insert_purchases_query, cmd='post')
insert_maintenance_requests_query_response = db.execute(insert_maintenance_requests_query, cmd='post')
insert_maintenance_quotes_query_response = db.execute(insert_maintenance_quotes_query, cmd='post')
insert_contracts_query_response = db.execute(insert_contracts_query, cmd='post')
update_contracts_query_response = db.execute(update_contracts_query, cmd='post')
# insert_leases_query_response = db.execute(insert_leases_query, cmd='post')
# update_leases_query_response = db.execute(update_leases_query, cmd='post')
# insert_lease_tenant_query_response = db.execute(insert_lease_tenant_query, cmd='post')
# insert_lease_fees_query_response = db.execute(insert_lease_fees_query, cmd='post')
# update_lease_fees_query_response = db.execute(update_lease_fees_query, cmd='post')
print("\n*** Completed ***\n")
response['insert_temporary_data'] = 'Passed'
except:
response['insert_temporary_data'] = 'Failed'
if response['insert_temporary_data'] != 'Passed':
return response['insert_temporary_data']
response['No of APIs tested'] = 0
response['APIs running successfully'] = []
response['APIs failing'] = []
response['Error in running APIs'] = []
try:
# ------------------------- MAINTENANCE ------------------------------
maintenance_request_uid = ""
maintenance_quote_uid = ""
try:
# -------- test post maintenance request --------
print("\nIn test POST Maintenance Requests")
post_maintenance_request_payload = {
"maintenance_property_id":"200-000000",
"maintenance_title":"Vents Broken",
"maintenance_desc":"Vents",
"maintenance_request_type":"Appliance",
"maintenance_request_created_by":"600-000000",
"maintenance_priority":"High",
"maintenance_can_reschedule":1,
"maintenance_assigned_business":"null",
"maintenance_assigned_worker":"null",
"maintenance_scheduled_date":"null",
"maintenance_scheduled_time":"null",
"maintenance_frequency":"One Time",
"maintenance_notes":"null",
"maintenance_request_created_date":"2024-11-13",
"maintenance_request_closed_date":"null",
"maintenance_request_adjustment_date":"null"
}
post_maintenance_request_response = requests.post(ENDPOINT + "/maintenanceRequests", data = post_maintenance_request_payload)
maintenance_request_uid = post_maintenance_request_response.json()['maintenance_request_uid']
if post_maintenance_request_response.status_code == 200:
response['APIs running successfully'].append('POST Maintenance Requests')
else:
response['APIs failing'].append('POST Maintenance Requests')
response['No of APIs tested'] += 1
# -------- test post get maintenance request --------
print("\nIn test GET after POST Maintenance Requests")
post_get_maintenance_request_response = requests.get(ENDPOINT + f"/maintenanceReq/200-000000")
data = post_get_maintenance_request_response.json()['result']['NEW REQUEST']['maintenance_items'][0]
for k, v in post_maintenance_request_payload.items():
if data[k] == v:
continue
else:
print(k, v, "not a match")
if post_get_maintenance_request_response.status_code == 200:
response['APIs running successfully'].append('GET after POST Maintenance Requests')
else:
response['APIs failing'].append('GET after POST Maintenance Requests')
response['No of APIs tested'] += 1
# -------- test put maintenance request --------
print("\nIn test PUT Maintenance Requests")
put_maintenance_request_payload = {
"maintenance_request_uid":f"{maintenance_request_uid}","maintenance_request_status":"SCHEDULED","maintenance_scheduled_date":"11/30/2024","maintenance_scheduled_time":"10:00:00"
}
put_maintenance_request_response = requests.put(ENDPOINT + "/maintenanceRequests", data = put_maintenance_request_payload)
if put_maintenance_request_response.status_code == 200:
response['APIs running successfully'].append('PUT Maintenance Requests')
else:
response['APIs failing'].append('PUT Maintenance Requests')
response['No of APIs tested'] += 1
# -------- test put get maintenance request --------
print("\nIn test GET after PUT Maintenance Requests")
put_get_maintenance_request_response = requests.get(ENDPOINT + f"/maintenanceReq/200-000000")
data = put_get_maintenance_request_response.json()['result']['SCHEDULED']['maintenance_items'][0]
for k, v in put_maintenance_request_payload.items():
if data[k] == v:
continue
else:
print(k, v, "not a match")
if put_get_maintenance_request_response.status_code == 200:
response['APIs running successfully'].append('GET after PUT Maintenance Requests')
else:
response['APIs failing'].append('GET after PUT Maintenance Requests')
response['No of APIs tested'] += 1
# -------- test post maintenance quotes --------
print("\nIn test POST Maintenance Quotes")
post_maintenance_quotes_payload = {
'quote_maintenance_request_id': f'{maintenance_request_uid}',
'quote_pm_notes': 'Vents',
'quote_business_id': '600-000000'
}
post_maintenance_quotes_response = requests.post(ENDPOINT + "/maintenanceQuotes", data = post_maintenance_quotes_payload)
maintenance_quote_uid = post_maintenance_quotes_response.json()['maintenance_quote_uid']
if post_maintenance_quotes_response.status_code == 200:
response['APIs running successfully'].append('POST Maintenance Quotes')
else:
response['APIs failing'].append('POST Maintenance Quotes')
response['No of APIs tested'] += 1
# -------- test post get maintenance quotes --------
print("\nIn test GET after POST Maintenance Quotes")
post_get_maintenance_quotes_response = requests.get(ENDPOINT + f"/maintenanceQuotes/600-000000")
data = post_get_maintenance_quotes_response.json()['maintenanceQuotes']['result'][0]
for k, v in post_maintenance_quotes_payload.items():
if data[k] == v:
continue
else:
print(k, v, "not a match")
if post_get_maintenance_quotes_response.status_code == 200:
response['APIs running successfully'].append('GET after POST Maintenance Quotes')
else:
response['APIs failing'].append('GET after POST Maintenance Quotes')
response['No of APIs tested'] += 1
# -------- test put maintenance quotes --------
print("\nIn test PUT Maintenance Quotes")
put_maintenance_quotes_payload = {
'maintenance_quote_uid': f'{maintenance_quote_uid}',
'quote_maintenance_request_id': f'{maintenance_request_uid}',
'quote_business_id': '600-000000',
'quote_services_expenses': '{"per Hour Charge":"10","event_type":5,"service_name":"Labor","parts":[{"part":"250","quantity":"1","cost":"250"}],"labor":[{"description":"","hours":5,"rate":"10"}],"total_estimate":50}',
'quote_notes': 'vents',
'quote_status': 'SENT',
'quote_event_type': '5 Hour Job',
'quote_total_estimate': '300',
'quote_created_date': '2000-04-23 00:00:00',
'quote_earliest_available_date': '12-12-2023',
'quote_earliest_available_date': '00:00:00'
}
put_maintenance_quotes_response = requests.put(ENDPOINT + "/maintenanceQuotes", data = put_maintenance_quotes_payload)
if put_maintenance_quotes_response.status_code == 200:
response['APIs running successfully'].append('PUT Maintenance Quotes')
else:
response['APIs failing'].append('PUT Maintenance Quotes')
response['No of APIs tested'] += 1
# -------- test put get maintenance quotes --------
print("\nIn test GET after PUT Maintenance Quotes")
put_get_maintenance_quotes_response = requests.get(ENDPOINT + f"/maintenanceQuotes/600-000000")
data = put_get_maintenance_quotes_response.json()['maintenanceQuotes']['result'][0]
for k, v in put_maintenance_quotes_payload.items():
if k == 'quote_services_expenses':
continue
if data[k] == v:
continue
else:
print(k, v, "not a match")
if put_get_maintenance_quotes_response.status_code == 200:
response['APIs running successfully'].append('GET after PUT Maintenance Quotes')
else:
response['APIs failing'].append('GET after PUT Maintenance Quotes')
response['No of APIs tested'] += 1
# -------- test get maintenance quotes by uid--------
print("\nIn test GET Maintenance Quotes By UID")
get_maintenance_quotes_by_uid_response = requests.get(ENDPOINT + f"/maintenanceQuotes/{maintenance_quote_uid}")
if get_maintenance_quotes_by_uid_response.status_code == 200:
response['APIs running successfully'].append('GET Maintenance Quotes By UID')
else:
response['APIs failing'].append('GET Maintenance Quotes By UID')
response['No of APIs tested'] += 1
except:
response['Error in running APIs'].append('Maintenance API')
finally:
# -------- delete data from Maintenance Requests and Maintenance Quotes --------
print("\nIn delete data from Maintenance Requests and Maintenance Quotes")
print(f"Deleting {maintenance_request_uid} from Maintenance Requests and {maintenance_quote_uid} from Maintenance Quotes")
with connect() as db:
if maintenance_request_uid != "":
delQuery_maintenance_req = ("""
DELETE space.maintenanceRequests
FROM space.maintenanceRequests
WHERE maintenance_request_uid = \'""" + maintenance_request_uid + """\';
""")
maintenance_req_response = db.delete(delQuery_maintenance_req)
if maintenance_quote_uid != "":
delQuery_maintenance_quotes = ("""
DELETE space.maintenanceQuotes
FROM space.maintenanceQuotes
WHERE maintenance_quote_uid = \'""" + maintenance_quote_uid + """\';
""")
maintenance_quotes_response = db.delete(delQuery_maintenance_quotes)
# ------------------------- Properties ------------------------------
try:
# -------- test post properties --------
print("\nIn test POST Properties")
post_properties_payload = {"property_latitude":37.2367236,
"property_longitude":-121.8876474,
"property_owner_id":"110-000000",
"property_active_date":"08-10-2024",
"property_address":"123 Test APT",
"property_unit":"2",
"property_city":"San Jose",
"property_state":"CA",
"property_zip":"95120",
"property_type":"Single Family",
"property_num_beds":4,
"property_num_baths":3,
"property_value":0,
"property_area":1450,
"property_listed":'1',
"property_notes":"Dot Court",
"appliances":["050-000000"],
}
post_properties_response = requests.post(ENDPOINT + "/properties", data=post_properties_payload)
property_uid = post_properties_response.json()['property_UID']
if post_properties_response.status_code == 200:
response['APIs running successfully'].append('POST Properties')
else:
response['APIs failing'].append('POST Properties')
response['No of APIs tested'] += 1
# -------- test get after post properties --------
print("\nIn test GET after POST Properties")
post_get_properties_response = requests.get(ENDPOINT + f"/properties/{property_uid}")
data = post_get_properties_response.json()['Property']['result'][0]
for k, v in post_properties_payload.items():
if k == "property_listed" or k == "appliances" or k == "property_latitude" or k == "property_longitude":
continue
if data[k] != v:
print('\n\n', k, v, '\tNot Match')
if post_get_properties_response.status_code == 200:
response['APIs running successfully'].append('GET after POST Properties')
else:
response['APIs failing'].append('GET after POST Properties')
response['No of APIs tested'] += 1
# -------- test put properties --------
print("\nIn test PUT Properties")
put_properties_payload = {
"property_uid": f"{property_uid}",
"property_address": "456 Test House",
"property_value":1500000
}
put_properties_response = requests.put(ENDPOINT + "/properties", data=put_properties_payload)
if put_properties_response.status_code == 200:
response['APIs running successfully'].append('PUT Properties')
else:
response['APIs failing'].append('PUT Properties')
response['No of APIs tested'] += 1
# -------- test get after put properties --------
print("\nIn GET after PUT Properties")
put_get_properties_response = requests.get(ENDPOINT + f"/properties/{property_uid}")
data = put_get_properties_response.json()['Property']['result'][0]
for k, v in put_properties_payload.items():
if data[k] != v:
print('\n\n', k, v, '\tNot Match')
if put_get_properties_response.status_code == 200:
response['APIs running successfully'].append('GET after PUT Properties')
else:
response['APIs failing'].append('GET after PUT Properties')
response['No of APIs tested'] += 1
# -------- test delete properties --------
print("\nIn Delete Properties")
print(f"Deleteing property with property_uid: {property_uid} and property_owner_id: 110-000000")
delete_properties_payload = {
"property_owner_id": "110-000000",
"property_id": f"{property_uid}"
}
headers = {
'Content-Type': 'application/json'
}
delete_properties_response = requests.delete(ENDPOINT + "/properties", data=json.dumps(delete_properties_payload), headers=headers)
if delete_properties_response.status_code == 200:
response['APIs running successfully'].append('DELETE Properties')
else:
response['APIs failing'].append('DELETE Properties')
response['No of APIs tested'] += 1
except:
response['Error in running APIs'].append('Properties API')
# ------------------------- Contracts ------------------------------
contract_uid = ""
try:
# -------- test post contracts --------
print("\nIn POST Contract")
post_contract_payload = {
"contract_property_ids": '["200-000000"]',
"contract_business_id": "600-000000",
"contract_start_date": "11-01-2024",
"contract_status": "NEW"
}
post_contract_response = requests.post(ENDPOINT + "/contracts", data=post_contract_payload)
contract_uid = post_contract_response.json()['contract_uid']
print('\nContract UID', contract_uid)
if post_contract_response.status_code == 200:
response['APIs running successfully'].append('POST Contracts')
else:
response['APIs failing'].append('POST Contracts')
response['No of APIs tested'] += 1
# -------- test get after contracts --------
print("\nIn GET after POST Contract")
post_get_contract_response = requests.get(ENDPOINT + "/contracts/600-000000")
data = post_get_contract_response.json()['result'][0]
if data.get('contract_uid', None) != contract_uid:
print("Not a match")
if post_get_contract_response.status_code == 200:
response['APIs running successfully'].append('GET after POST Contracts')
else:
response['APIs failing'].append('GET after POST Contracts')
response['No of APIs tested'] += 1
# -------- test put contracts --------
print("\nIn PUT Contract")
put_contract_payload = {
"contract_uid": f"{contract_uid}",
"contract_status": "ACTIVE"
}
put_contract_response = requests.put(ENDPOINT + "/contracts", data=put_contract_payload)
if put_contract_response.status_code == 200:
response['APIs running successfully'].append('PUT Contracts')
else:
response['APIs failing'].append('PUT Contracts')
response['No of APIs tested'] += 1
# -------- test get after put contracts --------
print("\nIn GET after PUT Contract")
put_get_contract_response = requests.get(ENDPOINT + "/contracts/600-000000")
data = put_get_contract_response.json()['result'][0]
if data.get('contract_uid', None) != contract_uid:
print("Not a match")
if put_get_contract_response.status_code == 200:
response['APIs running successfully'].append('PUT Contracts')
else:
response['APIs failing'].append('PUT Contracts')
response['No of APIs tested'] += 1
except:
response['Error in running APIs'].append('Contracts API')
finally:
# -------- test delete contracts --------
print("\nIn DELETE Contract")
print(f"Deleting {contract_uid} from Contract Table")
with connect() as db:
if contract_uid != "":
delQuery_contracts = ("""
DELETE FROM space.contracts
WHERE contract_uid = \'""" + contract_uid + """\';
""")
contract_response = db.delete(delQuery_contracts)
# ------------------------- Leases ------------------------------
curr_lease_api = ""
lease_uid = ""
try:
# -------- test post lease application --------
print("\nIn test POST Lease Application")
curr_lease_api = "POST"
post_lease_application_payload = {
"lease_property_id":"200-000000",
"lease_start":"01-31-2024",
"lease_end":"01-30-2025",
"lease_application_date":"06-27-2024",
"tenant_uid":"350-000000",
"lease_status":"NEW"
}
post_lease_application_response = requests.post(ENDPOINT + "/leaseApplication", data=post_lease_application_payload)
if (post_lease_application_response.status_code == 200):
response['APIs running successfully'].append('POST Lease Application')
else:
response['APIs failing'].append('POST Lease Application')
response['No of APIs tested'] += 1
# -------- get lease uid --------
curr_lease_api = "GET uid"
print("\nIn get lease_uid")
get_lease_uid_response = requests.get(ENDPOINT + "/leaseApplication/350-000000/200-000000")
lease_uid = get_lease_uid_response.json()
print("lease_uid", lease_uid)
# -------- test get after post lease details --------
print("\nIn test GET after POST Lease Application")
curr_lease_api = "GET POST"
post_get_lease_application_response = requests.get(ENDPOINT + "/leaseDetails/350-000000")
# data = post_get_lease_application_response.json()['Lease_Details']['result'][0]
# if data['lease_status'] != "NEW":
# print('Not Match')
if (post_get_lease_application_response.status_code == 200):
response['APIs running successfully'].append('GET after POST Lease Application')
else:
response['APIs failing'].append('GET after POST Lease Application')
response['No of APIs tested'] += 1
# -------- test put lease application --------
print("\nIn test PUT Lease Application")
curr_lease_api = "PUT"
put_lease_application_payload = {
"lease_uid":f"{lease_uid}",
"lease_status":"PROCESSING"
}
put_lease_application_response = requests.put(ENDPOINT + "/leaseApplication", data=put_lease_application_payload)
if (put_lease_application_response.status_code == 200):
response['APIs running successfully'].append('PUT Lease Application')
else:
response['APIs failing'].append('PUT Lease Application')
response['No of APIs tested'] += 1
# -------- test get after put lease details --------
print("\nIn test GET after PUT Lease Application")
curr_lease_api = "GET PUT"
put_get_lease_application_response = requests.get(ENDPOINT + "/leaseDetails/350-000000")
# data = put_get_lease_application_response.json()['Lease_Details']['result'][0]
# if data['lease_status'] != "PROCESSING":
# print('Not Match')
if (put_get_lease_application_response.status_code == 200):
response['APIs running successfully'].append('GET after PUT Lease Application')
else:
response['APIs failing'].append('GET after PUT Lease Application')
response['No of APIs tested'] += 1
except:
response['Error in running APIs'].append('Lease API')
finally:
# -------- test delete lease --------
print("\nIn DELETE Lease")
print(f"Deleting {lease_uid} from Lease Table & {lease_uid} from Lease_tenant")
with connect() as db:
if curr_lease_api != "" and curr_lease_api != "POST" and lease_uid != "":
delQuery_leases = ("""
DELETE FROM space.leases
WHERE lease_uid = \'""" + lease_uid + """\';
""")
delQuery_lease_tenant = ("""
DELETE FROM space.lease_tenant
WHERE lt_lease_id = \'""" + lease_uid + """\';
""")
leases_response = db.delete(delQuery_leases)
lease_tenant_response = db.delete(delQuery_lease_tenant)
# ------------------------- Payment Method ------------------------------
try:
# -------- test POST Payment Method --------
print("\nIn POST Payment Method")
post_payment_method_payload = {
"paymentMethod_profile_id": "110-000000",
"paymentMethod_type":"zelle",
"paymentMethod_name":"test123",
"paymentMethod_status":"Active"
}
post_payment_method_response = requests.post(ENDPOINT + "/paymentMethod", data=json.dumps(post_payment_method_payload), headers=headers)
if (post_payment_method_response.status_code == 200):
response['APIs running successfully'].append('POST Payment Method')
else:
response['APIs failing'].append('POST Payment Method')
response['No of APIs tested'] += 1
# -------- test GET Payment Method UID --------
print("\nIn GET Payment Method UID")
get_payment_method_uid = requests.get(ENDPOINT + "/paymentMethod/110-000000")
payment_method_uid = get_payment_method_uid.json()['result'][0]['paymentMethod_uid']
if (get_payment_method_uid.status_code == 200):
response['APIs running successfully'].append('GET Payment Method UID')
else:
response['APIs failing'].append('GET Payment Method UID')
response['No of APIs tested'] += 1
# -------- test PUT Payment Method --------
global put_payment_method_payload
put_payment_method_payload = {
"paymentMethod_uid": f"{payment_method_uid}",
"paymentMethod_status":"Inactive"
}
put_payment_method_response = requests.put(ENDPOINT + "/paymentMethod", data=json.dumps(put_payment_method_payload), headers=headers)
if (put_payment_method_response.status_code == 200):
response['APIs running successfully'].append('PUT Payment Method')
else:
response['APIs failing'].append('PUT Payment Method')
response['No of APIs tested'] += 1
# -------- test DELETE Payment Method --------
print("\nIn DELETE Payment Method")
delete_payment_method_response = requests.delete(ENDPOINT + f"/paymentMethod/110-000000/{payment_method_uid}")
if (delete_payment_method_response.status_code == 200):
response['APIs running successfully'].append('DELETE Payment Method')
else:
response['APIs failing'].append('DELETE Payment Method')
response['No of APIs tested'] += 1
except:
response['Error in running APIs'].append('Payment Method API')
# ------------------------- Add Purchases ------------------------------
purchase_uid = ""
curr_pur_pay_api = ""
try:
# -------- test POST Add Purchases --------
print("\nIn POST add purchase")
post_add_purchase_payload = {
"pur_property_id": "200-000000",
"purchase_type": "Rent",
"pur_description": "Test Rent",
"purchase_date": "11-07-2024",
"pur_due_date": "11-11-2024",
"pur_amount_due": 10.00,
"pur_late_fee": "0",
"pur_perDay_late_fee": "0",
"purchase_status": "UNPAID",
"pur_receiver": "600-000000",
"pur_initiator": "600-000000",
"pur_payer": "350-000000"
}
post_add_purchase_response = requests.post(ENDPOINT + "/addPurchase", data=post_add_purchase_payload)
purchase_uid = post_add_purchase_response.json()['purchase_UID']
if (post_add_purchase_response.status_code == 200):
response['APIs running successfully'].append('POST Add Purchases')
else:
response['APIs failing'].append('POST Add Purchases')
response['No of APIs tested'] += 1
# -------- test PUT Add Purchases --------
print("\nIn PUT add purchase")
put_add_purchase_payload = {
"purchase_uid": f"{purchase_uid}",
"pur_late_fee": "10"
}
put_add_purchase_response = requests.put(ENDPOINT + "/addPurchase", data=put_add_purchase_payload)
if (put_add_purchase_response.status_code == 200):
response['APIs running successfully'].append('PUT Add Purchases')
else:
response['APIs failing'].append('PUT Add Purchases')
response['No of APIs tested'] += 1
if purchase_uid == "":
raise Exception('No Purchase UID')
# ------------------------- Payments ------------------------------
# -------- test POST New Payments --------
print("\nIn POST New Payments")
post_payment_payload = {
"pay_purchase_id": [
{
"purchase_uid": f"{purchase_uid}",
"pur_amount_due": "10.00"
}
],
"pay_fee": 0,
"pay_total": 10,
"payment_notes": "Test Payment",
"pay_charge_id": "stripe transaction key",
"payment_type": "zelle",
"payment_verify": "Unverified",
"paid_by": "350-000000",
"payment_intent": "pi_1testaccountpayment",
"payment_method": "pm_1testaccountpayment"
}
post_payment_response = requests.post(ENDPOINT + "/makePayment", data=json.dumps(post_payment_payload), headers=headers)
if (post_payment_response.status_code == 200):
response['APIs running successfully'].append('POST New Payments')
else:
response['APIs failing'].append('POST New Payments')
response['No of APIs tested'] += 1
curr_pur_pay_api = "Completed"
except:
response['Error in running APIs'].append('Purchase & Payment API')
finally:
# -------- test DELETE Add purchases and New Payments --------
print("\nIn DELETE add purchase")
print(f"\nDeleting purchase_uid: {purchase_uid} from Purchases Table and payments with same purchase_uid from Payments Table")
with connect() as db:
if purchase_uid != "":
delQuery_add_purchase = ("""
DELETE FROM space.purchases
WHERE purchase_uid = \'""" + purchase_uid + """\';
""")
del_add_purchase_response = db.delete(delQuery_add_purchase)
if purchase_uid != "" and curr_pur_pay_api == "Completed":
delQuery_payment = ("""
DELETE FROM space.payments
WHERE pay_purchase_id = \'""" + purchase_uid + """\' AND paid_by = '350-000000'
""")
del_payment_response = db.delete(delQuery_payment)
# ------------------------- Dashboard ------------------------------
try:
# -------- test GET Dashboard --------
print("\nIn GET Dashboard")
business_response = requests.get(ENDPOINT + "/dashboard/600-000000")
owner_response = requests.get(ENDPOINT + "/dashboard/110-000000")
tenant_response = requests.get(ENDPOINT + "/dashboard/350-000000")
if (business_response.status_code == 200 and owner_response.status_code == 200 and tenant_response.status_code == 200):
response['APIs running successfully'].append('GET Dashboard')
else:
response['APIs failing'].append('GET Dashboard')
response['No of APIs tested'] += 1
except:
response['Error in running APIs'].append('Dashboard API')
# ------------------------- Profiles ------------------------------
owner_uid = ""
business_uid = ""
employee_uid = ""
tenant_uid = ""
try:
# -------- test POST Profile --------
print("\nIn test POST Profile")
post_owner_profile_payload = {
"owner_user_id": "100-000000",
"owner_first_name": "Test",
"owner_last_name": "Owner Account",
"owner_phone_number": "(000) 000-0000",
"owner_email": "[email protected]"
}
post_owner_profile_response = requests.post(ENDPOINT + "/profile", data=post_owner_profile_payload)
owner_uid = post_owner_profile_response.json()["owner_uid"]
post_business_profile_payload = {
"business_user_id": "100-000000",
"business_type": "Management",
"business_name": "Test Business Account",
"business_email": "[email protected]",
}
post_business_profile_response = requests.post(ENDPOINT + "/profile", data=post_business_profile_payload)
business_uid = post_business_profile_response.json()["business_uid"]
employee_uid = post_business_profile_response.json()["employee_uid"]
post_tenant_profile_payload = {
"tenant_user_id": "100-000000",
"tenant_first_name": "Test",
"tenant_last_name": "Tenant Account",
"tenant_email": "[email protected]",
"tenant_phone_number": "(000) 000-0000"
}
post_tenant_profile_response = requests.post(ENDPOINT + "/profile", data=post_tenant_profile_payload)
tenant_uid = post_tenant_profile_response.json()["tenant_uid"]
if (post_owner_profile_response.status_code == 200 and post_business_profile_response.status_code == 200 and post_tenant_profile_response.status_code == 200):
response['APIs running successfully'].append('POST Profile')
else:
response['APIs failing'].append('POST Profile')
response['No of APIs tested'] += 1
# -------- test GET after POST Profile --------
print("\nIn GET after POST Profile")
post_get_owner_profile_response = requests.get(ENDPOINT + f"/profile/{owner_uid}")
data = post_get_owner_profile_response.json()['profile']['result'][0]
if data["owner_first_name"] != "Test":
print("Not Match")
post_get_business_profile_response = requests.get(ENDPOINT + f"/profile/{business_uid}")
data = post_get_business_profile_response.json()['profile']['result'][0]
if data["business_type"] != "Management":
print("Not Match")
post_get_tenant_profile_response = requests.get(ENDPOINT + f"/profile/{tenant_uid}")
data = post_get_tenant_profile_response.json()['profile']['result'][0]
if data["tenant_first_name"] != "Test":
print("Not Match")
if (post_get_owner_profile_response.status_code == 200 and post_get_business_profile_response.status_code == 200 and post_get_tenant_profile_response.status_code == 200):
response['APIs running successfully'].append('GET after POST Profile')
else:
response['APIs failing'].append('GET after POST Profile')
response['No of APIs tested'] += 1
# -------- test PUT Profile --------
print("\nIn test PUT Profile")
put_owner_profile_payload = {
"owner_uid": f"{owner_uid}",
"owner_first_name": "Test Owner",
}
put_owner_profile_response = requests.put(ENDPOINT + "/profile", data=put_owner_profile_payload)
put_business_profile_payload = {
"business_uid": f"{business_uid}",
"business_type": "Maintenance",
}
put_business_profile_response = requests.put(ENDPOINT + "/profile", data=put_business_profile_payload)
put_tenant_profile_payload = {
"tenant_uid": f"{tenant_uid}",
"tenant_first_name": "Test Tenant",
}
put_tenant_profile_response = requests.put(ENDPOINT + "/profile", data=put_tenant_profile_payload)
if (put_owner_profile_response.status_code == 200 and put_business_profile_response.status_code == 200 and put_tenant_profile_response.status_code == 200):
response['APIs running successfully'].append('PUT Profile')
else:
response['APIs failing'].append('PUT Profile')