-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverificationserver.py
142 lines (118 loc) · 4.61 KB
/
verificationserver.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
'''
not complete
VERIFICATION SERVER
AUTHOR: GEORGIA BLANCO-LITCHFIELD GBL06
'''
import traceback
from flask import Flask, request, jsonify
import autosmart_v2.function as cdb
from autosmart_v2.utils.utils import createFileLogger
from autosmart_v2.config.config import Config
from autosmart_v2.config.verification_config import verification_config
VERSION = 1.2
LOG_FILE = Config['verificationserverLog']
EXTRACTOR_REPORTS = Config['extractorReports']
logger = createFileLogger(LOG_FILE)
app = Flask(__name__)
@app.route('/verifyPara', methods=['GET'])
def verifyPara():
slotId = request.args['slotId']
attrib = request.args['attribute']
attribute = verification_config[attrib]
exp_value = request.args['exp_value']
logger.info("Verifying value from top paragraph for slot ID =" + slotId + " attribute =" + attribute + " expected value = " + exp_value)
# response = {}
print(EXTRACTOR_REPORTS + "cdb_report" + str(int(slotId)) + ".html")
path = EXTRACTOR_REPORTS + "cdb_report" + str(int(slotId)) + ".html"
value_to_be_verified = cdb.get_value_from_para(path, attribute)
logger.info('%s', attribute)
if exp_value != value_to_be_verified:
logger.error("Teststep verification Failed")
logger.info("Expecting: %s=%s, but, found %s=%s", attribute, exp_value,
attribute, value_to_be_verified)
logger.info("Ending test")
response = "incorrect"
else:
logger.info("Teststep verification passed")
response = "correct"
return response
# try:
# print(EXTRACTOR_REPORTS + "cdb_report" + str(int(slotId)) + ".html")
# path = EXTRACTOR_REPORTS + "cdb_report" + str(int(slotId)) + ".html"
# value_to_be_verified = cdb.get_value_from_para(path,
# attribute)
# logger.info('%s', attribute)
# if exp_value != value_to_be_verified:
# logger.error("Teststep verification Failed")
# logger.info("Expecting: %s=%s, but, found %s=%s", attribute, exp_value,
# attribute, value_to_be_verified)
# logger.info("Ending test")
# response = "incorrect"
#
# else:
# logger.info("Teststep verification passed")
# response = "correct"
#
# except Exception as exc:
# response["error"] = [
# str(exc),
# traceback.format_exc()
# ]
# return jsonify(response)
# if DEBUG:
# raise exc
@app.route('/verifyTable', methods=['GET'])
def verifyTable():
slotId = request.args['slotId']
header = request.args['header']
unique_id = request.args['unique_id']
column = request.args['column']
exp_value = request.args['exp_value']
logger.info("Verification of table values")
response = {}
try:
value_to_be_verified = cdb.get_value_from_row(
EXTRACTOR_REPORTS + "cdb_report" + str(int(slotId)) + ".html", header, unique_id,
column)
if exp_value != value_to_be_verified:
logger.error("Teststep verification Failed")
logger.info("Expecting: %s=%s, but, found %s=%s", column, exp_value,
column, value_to_be_verified)
return False
else:
logger.info("Teststep verification passed")
return True
except Exception as exc:
response["error"] = [
str(exc),
traceback.format_exc()
]
return jsonify(response)
@app.route('/verifyUnderTable', methods=['GET'])
def verifyUnderTable():
slotId = request.args['slotId']
header = request.args['header']
attribute = request.args['attribute']
exp_value = request.args['exp_value']
self.logger.info("Verification of value under table")
response = {}
try:
value_to_be_verified = cdb.get_value_under_table(
EXTRACTOR_REPORTS + "cdb_report" + str(int(slotId)) + ".html", header, attribute)
if exp_value != value_to_be_verified:
logger.error("Teststep verification Failed")
logger.info("Expecting: %s %s=%s, but, found %s=%s", header, attribute, exp_value,
header, value_to_be_verified)
logger.info("Ending test")
response = "incorrect"
else:
logger.info("Teststep verification passed")
response = "correct"
except Exception as exc:
response["error"] = [
str(exc),
traceback.format_exc()
]
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=8989)