-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_ops.py
109 lines (83 loc) · 2.87 KB
/
data_ops.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
import logging
import json
from data_ops_fns import *
# from sqlalchemy import create_engine
# from sqlalchemy.orm import sessionmaker
# from sqlalchemy import MetaData
# from sqlalchemy.ext.declarative import declarative_base
## msg - is the msg recvd by sanket
## expected to be a string
# engine = create_engine('mysql+mysqlconnector://user:password@localhost:3306/DSTRY')
# Session = sessionmaker(bind=engine)
# Base = declarative_base()
# session = Session()
def msg_handler(msg):
# msg = json.loads(msg)
# each method will return json dumped in form of string
#### SELLER
if(msg['method'] == "signup_seller"):
return signup_seller(msg)
if(msg['method'] == "login_seller"):
return login_seller(msg)
if(msg['method'] == "add_product"):
return add_product(msg)
#### BUYER
if(msg['method'] == "signup_buyer"):
return signup_buyer(msg)
if(msg['method'] == "login_buyer"):
return login_buyer(msg)
if(msg['method'] == "view_all_products"):
return view_all_products(msg)
if(msg['method'] == "filter_products"):
return filter_products(msg)
if(msg['method'] == "add_to_cart"):
return add_to_cart(msg)
if(msg['method'] == "view_cart"):
return view_cart(msg)
if(msg['method'] == "update_quantity"):
return update_quantity(msg)
if(msg['method'] == "checkout"):
return checkout(msg)
ret = {"ack":True, "error":"MSG_FORMAT"}
return json.dumps(ret)
def main():
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,datefmt="%H:%M:%S")
print("--------------------------------------------------------------")
with open("test_data_ops.json") as f:
test_json = json.load(f)
# signup seller check
msg_handler(test_json['signup_seller1'])
# msg_handler(json.dumps(test_json['signup_seller2']))
# # test login seller
msg_handler(test_json['login_seller1'])
# # add
msg_handler(test_json['add_product1'])
# msg_handler(test_json['add_product1'])
msg_handler(test_json['add_product2'])
msg_handler(test_json['view_all_products'])
# msg_handler(json.dumps(test_json['filter_products1']))
# # signup buyer check
msg_handler(test_json['signup_buyer1'])
msg_handler(test_json['signup_buyer2'])
# # test login seller
msg_handler(test_json['login_buyer1'])
# # add
msg_handler(test_json['add_to_cart1'])
msg_handler(test_json['add_to_cart3'])
msg_handler(test_json['add_to_cart1'])
msg_handler(test_json['view_cart1'])
# update quantity
# msg_handler(json.dumps(test_json['update_quantity1']))
# msg_handler(json.dumps(test_json['view_cart1']))
# # should produce error
# msg_handler(json.dumps(test_json['update_quantity2']))
# msg_handler(json.dumps(test_json['view_cart1']))
# success checkout
msg_handler(test_json['checkout1'])
msg_handler(test_json['view_cart1'])
# failure checkout
# msg_handler(json.dumps(test_json['add_to_cart3']))
# msg_handler(test_json['checkout2'])
if __name__ == '__main__':
main()