-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSE_task.py
218 lines (169 loc) · 5.52 KB
/
SE_task.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
import unittest
from flask import Flask, request, jsonify
import json
import subprocess
app = Flask(__name__)
login_details={}
art_form_options={}
def login():
while True:
username = input("Enter your username: ")
password = input("Enter your password: ")
if username == login_details["username"] and password == login_details["password"]:
print("Login successful!")
return True
else:
print("Invalid username or password. Please try again.")
# Function to display the available art forms and allow the user to choose one
def choose_art_form():
print("\nSelect an art form:")
print("1. Music")
print("2. Dance")
print("3. Spoken word")
print("4. Regional theatricals")
art_form = int(input("Enter a number: "))
if art_form == 1:
return view_or_buy("music")
elif art_form == 2:
return view_or_buy("dance")
elif art_form == 3:
return view_or_buy("spoken word")
elif art_form == 4:
return view_or_buy("regional theatricals")
else:
print("Invalid input. Please try again.")
return choose_art_form()
def view_or_buy(art_form_name):
print("\nSelect an option for", art_form_name)
print("1. View")
print("2. Buy")
print("3. Add new view or buy option")
option = int(input("Enter a number: "))
if option == 1:
return view_art_form(art_form_name)
elif option == 2:
return buy_art_form(art_form_name)
elif option == 3:
return add_option(art_form_name)
else:
print("Invalid input. Please try again.")
return view_or_buy(art_form_name)
def add_option(art_form_name):
option_name = input("Enter option name: ")
option_price = input("Enter option price: ")
try:
option_price = int(option_price)
except ValueError:
print("Invalid price. Please try again.")
return add_option(art_form_name)
art_form_options[art_form_name]['view'].append(option_name)
art_form_options[art_form_name]['buy'][option_name] = option_price
print(f"Successfully added {option_name} to {art_form_name} {view_or_buy} options.")
return go_back_option(art_form_name)
def view_art_form(art_form_name):
view_options = art_form_options[art_form_name]["view"]
if len(view_options) == 0:
print("No options available for", art_form_name)
else:
print("View options for", art_form_name, ":")
for option in view_options:
print("-", option)
return go_back_option(art_form_name)
def buy_art_form(art_form_name):
buy_options = art_form_options[art_form_name]["buy"]
if len(buy_options) == 0:
print("No options available for", art_form_name)
else:
print("Buy options for", art_form_name, ":")
for option in buy_options:
print("-", option)
option = input("Enter name of option to see buy price: ")
if option in buy_options:
assert buy_options[option]==art_form_options[art_form_name]["buy"][option],"inconsistent value"
print("Buy price for", option, "is", buy_options[option])
else:
print("Invalid input. Please try again.")
return buy_art_form(art_form_name)
return go_back_option(art_form_name)
def go_back_option(art_form_name):
print("\nEnter 1 to go back to", art_form_name)
print("Enter 2 to exit")
option = int(input("Enter a number: "))
if option == 1:
return view_or_buy(art_form_name)
elif option == 2:
return True
else:
print("Invalid input. Please try again")
#regression testing:
class TestArtForms(unittest.TestCase):
def test_choose_art_form(self):
self.assertEqual(choose_art_form(), True)
def test_login(self):
self.assertEqual(login(), True)
#API:
@app.route('/data', methods=['GET'])
def get_data():
# Get the data from the request
global login_details,art_form_options
data = request.get_json()
login_details=data["login"]
art_form_options=data["art"]
inpt=input("enter 1 to perform regression testing , 2 to run program , 3 to exit")
if(inpt=='1'):
unittest.main()
elif inpt=='2':
while True:
choice = input("Press 1 to login, 2 to exit ")
if choice == "1":
if login():
# integration testing:
assert choose_art_form() == True, "Execution error"
elif choice == "2":
print("Exiting program.")
break
else:
print("invalid input")
print("program completed")
else:
print("invalid input")
# Return a success message
return jsonify({'message': 'program execution successful'})
app.run(debug=True)
'''data to pass to http://localhost:5000/data using postman:
{"login":{
"username": "sigma",
"password": "20270508"
},"art":{
"music": {
"view": ["rock", "jazz", "blues"],
"buy": {
"rock": 10,
"jazz": 15,
"blues": 20
}
},
"dance": {
"view": ["ballet", "tap", "salsa"],
"buy": {
"ballet": 25,
"tap": 20,
"salsa": 30
}
},
"spoken word": {
"view": ["poetry", "storytelling"],
"buy": {
"poetry": 5,
"storytelling": 8
}
},
"regional theatricals": {
"view": ["nautanki", "jatra"],
"buy": {
"nautanki": 12,
"jatra": 18
}
}
}}
'''