|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
import pymysql
|
|
|
|
|
import random
|
|
|
|
|
from pymysql.cursors import DictCursor
|
|
|
|
|
from config import db_config
|
|
|
|
|
from lib.xml_to_dict import xml_to_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Result:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.db_conn = pymysql.connect(**db_config)
|
|
|
|
|
self.cursor = self.db_conn.cursor(cursor=DictCursor)
|
|
|
|
|
|
|
|
|
|
def save(self, data):
|
|
|
|
|
try:
|
|
|
|
|
self.cursor.execute(
|
|
|
|
|
"INSERT INTO result (api, test_type, case_id, xml_req_params, xml_resp_xml, xml_resp_json, xml_resp_format, json_req_method, json_req_params, json_req_data, json_resp_json, compare_result) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
|
|
|
|
|
data)
|
|
|
|
|
self.db_conn.commit()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('save_result', e)
|
|
|
|
|
|
|
|
|
|
def close_db(self):
|
|
|
|
|
self.cursor.close()
|
|
|
|
|
self.db_conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Case:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.db_conn = pymysql.connect(**db_config)
|
|
|
|
|
self.cursor = self.db_conn.cursor(cursor=DictCursor)
|
|
|
|
|
|
|
|
|
|
def get(self, case_id=None):
|
|
|
|
|
try:
|
|
|
|
|
self.cursor.execute("SELECT COUNT(*) as case_count FROM `case`;;")
|
|
|
|
|
count = int(self.cursor.fetchone()['case_count'])
|
|
|
|
|
if case_id is None:
|
|
|
|
|
case_id = random.randint(1, count + 1)
|
|
|
|
|
self.cursor.execute(
|
|
|
|
|
"SELECT * FROM `case` WHERE id = %s;", (case_id,))
|
|
|
|
|
case_data = self.cursor.fetchone()
|
|
|
|
|
print(case_data)
|
|
|
|
|
return case_data
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('save_result', e)
|
|
|
|
|
|
|
|
|
|
def get_all(self):
|
|
|
|
|
try:
|
|
|
|
|
self.cursor.execute("SELECT * FROM `case`;")
|
|
|
|
|
case_list = self.cursor.fetchall()
|
|
|
|
|
# print(case_list)
|
|
|
|
|
return case_list
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('save_result', e)
|
|
|
|
|
|
|
|
|
|
def transform(self, case_id):
|
|
|
|
|
case_data = []
|
|
|
|
|
try:
|
|
|
|
|
self.cursor.execute("SELECT * FROM `case` WHERE id >= %s;", (case_id,))
|
|
|
|
|
case_data = self.cursor.fetchall()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('get_case_failed', e)
|
|
|
|
|
|
|
|
|
|
for c in case_data:
|
|
|
|
|
xml_json = xml_to_dict(c['raw_req_params'])['SOAP-ENV:Envelope']['SOAP-ENV:Body'][
|
|
|
|
|
'ns1:setBuyingTicketsForDq']
|
|
|
|
|
seat_num = len(xml_json['Seats'].split('|'))
|
|
|
|
|
print(c['id'])
|
|
|
|
|
print(xml_json)
|
|
|
|
|
print(seat_num)
|
|
|
|
|
self.cursor.execute('UPDATE `case` SET test_params = %s, buy_seats_num = %s WHERE id = %s;', (json.dumps(xml_json), seat_num, c['id']))
|
|
|
|
|
self.db_conn.commit()
|
|
|
|
|
|
|
|
|
|
def close_db(self):
|
|
|
|
|
self.cursor.close()
|
|
|
|
|
self.db_conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CheckDbResult:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.db_conn = pymysql.connect(**db_config)
|
|
|
|
|
self.cursor = self.db_conn.cursor(cursor=DictCursor)
|
|
|
|
|
|
|
|
|
|
def check(self, req_data:dict):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
case = Case()
|
|
|
|
|
# case.get(1)
|
|
|
|
|
# all_cases = case.get_all()
|
|
|
|
|
case.transform(43)
|
|
|
|
|
# for c in all_cases:
|
|
|
|
|
# print(f"{c['id']} - {c['buy_seats_num']}")
|
|
|
|
|
# print(json.loads(c['test_params'])['BookingFeeInd'])
|
|
|
|
|
# print(json.loads(c['test_params'])['ServiceFeeCardNum'])
|
|
|
|
|
# print(json.loads(c['test_params'])['ServiceFeeCardType'])
|