def test_good_list(): # url = "http://211.103.136.242:8064/categories/115/skus" #---使用配置文件的url了 #定义测试数据 url_y = ConfigYaml() url_path = url_y.get_conf_url() url = url_path + "/categories/115/skus" data = {"page": "1", "page_size": "10", "ordering": "create_time"} # r = requests.get(url,json=data) r = requeests_get(url, json=data) from utils.RequestsUtil import request request = request() r = request.get(url, json=data) # print(r.json()) print(r) code = r["code"] # print("-----test",code) AssertUtil().assert_code(code, 200) # body = r["body"] # print("-------test------",body) # AssertUtil().assert_in_body(body, 'count:14') #初始化数据对象 conn = init_db("db_1") #查询结果 res_db = conn.fetchone("select * from roles") print("数据库查询结果:%s" % res_db)
def test_login(): #3、定义测试数据 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/authorizations/" #url = "http://211.103.136.242:8064/authorizations/" data = {"username": "******", "password": "******"} #4、发送POST请求 #r = requests.post(url,json=data) #r = requests_post(url,json=data) request = Request() r = request.post(url, json=data) #5、输出结果 #print(r.json()) print(r) #验证 #返回状态码 code = r["code"] #assert code == 200 AssertUtil().assert_code(code, 200) #返回结果内容 #body = json.dumps(r["body"]) body = r["body"] #assert '"user_id": 1, "username": "******"' in body AssertUtil().assert_in_body(body, '"user_id": 1, "username": "******"') #1、初始化数据库对象 conn = init_db("db_1") #2、查询结果 res_db = conn.fetchone( "select id,username from tb_users where username='******'") print("数据库查询结果", res_db) #3、验证 user_id = body["user_id"] assert user_id == res_db["id"]
def test_login(): # 3、定义测试数据 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/authorizations/" # url = "http://211.103.136.242:8064/authorizations/" data = {"username": "******", "password": "******"} # 4、发送POST请求 # r = requests.post(url,json=data) # r = requests_post(url,json=data) request = Request() r = request.post(url, json=data) # 5、输出结果 # print(r.json()) print(r) # 返回状态码 code = r['code'] AssertUtil().assert_code(code, 200) body = r['body'] # print(body) AssertUtil().assert_in_body(body, '"username": "******"') # 1、初始化数据库对象 conn = init_db('db_1') # 2、查询结果 res_db = conn.fetchone("select id from tb_users where username='******'") print("数据库查询结果:", res_db) # 3、验证 user_id = body['user_id'] assert user_id == res_db['id']
def __init__(self, env=None, excel_filename=None, sheet_name=None): # 1. 初始化信息,可单独定义或者写成配置文件 conf = ConfigYaml() self.env_url = conf.get_conf_url(env) self.env_excel_file = conf.get_excel_file(env).get(excel_filename) self.env_excel_sheet = conf.get_excel_sheet(env).get(sheet_name) self.case_file = get_data_path() + os.sep + self.env_excel_file # 2. 获取需要运行的测试用例数据 self.data_list = Data(self.case_file, self.env_excel_sheet).get_run_data()
def goods_list(): # 1、参数 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/categories/115/skus/" # url = "http://211.103.136.242:8064/categories/115/skus/" data = {"page": "1", "page_size": "10", "ordering": "create_time"} # 2、请求 r = requests.get(url, json=data) # 3、结果 print(r.json())
def test_01(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetSampleDeviceAndPoint" data = {"Inputs": "{CName:\"\",MCode:0,pageCurrent:1,PageSize:10}"} requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body(body, "'Page': {'Current': 1, 'Total': 150}") print(body)
def test_06(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetDevStateBySysAndName" data = {"Inputs": ""} # headers = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"} requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] # AssertUtil().assert_in_body(body, "'Page': {'Current': 1, 'Total': 0}, 'SysId': 0, 'SysName': '全系统'") print(body)
def cart(): # 1、参数 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/cart/" # url = "http://211.103.136.242:8064/cart/" data = {"sku_id": "3", "count": "1", "selected": "true"} token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1ODg0MDc0MTUsInVzZXJuYW1lIjoicHl0aG9uIiwiZW1haWwiOiI5NTI2NzM2MzhAcXEuY29tIiwidXNlcl9pZCI6MX0.9vLuVHskV89xPDKy4EvhGNqULD1c5ciHFRIHyKH-29U' headers = {'Authorization': 'JWT ' + token} # 2、请求 # r = requests.post(url,json=data,headers=headers) r = requests_post(url, json=data, headers=headers) # 3、结果 # print(r.json()) print(r)
def test_01(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=DeleteReportInfo" data = {"Inputs": "{ID:1}"} requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'ErrorCode': 0, 'Success': True, 'ExceptionMsg': '删除成功!'") print(body) conn = init_db("db_1") conn.execute("truncate table TB_IMS_REPORTFORMS")
def test_info(): # 1、参数 conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/user/" # url = 'http://211.103.136.242:8064/user/' token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1ODg1MDIzMjgsInVzZXJuYW1lIjoicHl0aG9uIiwiZW1haWwiOiI5NTI2NzM2MzhAcXEuY29tIiwidXNlcl9pZCI6MX0.uQuz0gCtfHAM4RzhmNfTuqCRemU-A77UcK9SIl5ps5o' headers = {'Authorization': 'JWT ' + token} # 2、get请求 # r = requests.get(url,headers=headers) # r = requests_get(url,headers = headers) request = Request() r = request.get(url, headers=headers) # 3、输出 # print(r.json()) print(r)
def test_03(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetSampleDeviceAndPoint" data = { "Inputs": "{CName:\"1设备11\",MCode:\"M014\",pageCurrent:1,PageSize:10}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body(body, "'Page': {'Current': 1, 'Total': 1}") print(body)
def test_08(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetDeviceBySysAndName" # data = {"Inputs":"{DateType:0,List:[{TableNum:18,Num:1,RecordNo:null,DeviceId:1}]}"} # data = {"Inputs": "{strMcode:\"M009\",strName:\"\",PageCurrent:1,PageSize:10}"} data = { "Inputs": "{strMcode:0,strName:\"@@@@\",PageCurrent:1,PageSize:10}" } requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'Page': {'Current': 1, 'Total': 0}, 'list': []") print(body)
def test_Login(): # 3、定义测试数据 conf_y = ConfigYaml() #加载config.Conf文件中的ConfigYaml类 url_path = conf_y.get_conf_url() # 读取配置文件中的url url = url_path + "/authorizations/" # 拼接url+登录参数 # url = "http://211.103.136.242:8064/authorizations/" data = {"username": "******", "password": "******"} # 4、发送Post请求 # r = requests_post(url,json = data) r = request.post(url, json=data) # 5、输出结果 # print(json.dumps(r,sort_keys=True,ensure_ascii = False,indent=4,separators=(', ', ': '))) #Json格式打印 #验证返回状态码 code = r["code"] # assert code == 200 #调用assert封装函数 AssertUtil().assert_code(code, 200) #验证返回结果内容 # body = json.dumps(r["body"]) # assert '"user_id": 1, "username": "******"' in body body = r["body"] # print(body) # AssertUtil().assert_in_body(body,'"user_id": 1') AssertUtil().assert_in_body(body, '"username": "******"') print( "***************************************************************************************************" ) #数据库断言 #1、初始化数据库对象 conn = init_db("db_1") #2、查询结果 res_db = conn.fetchone( "select id,username from tb_users where username = '******'") print("数据库查询结果:", res_db) #3、数据库断言 user_id = body["user_id"] assert user_id == res_db["id"] # 6、返回token result_token = r['body']['token'] # print(result_token) return result_token
def test_09(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetHistoryMonitor" data = { "Inputs": "{particle:1,Unit:1,QueryType:\"avg\",StartTime:\"2020-09-09 00:00:00\",EndTime:\"2020-09-09 10:51:59\"," "DeviceId:1,SampleType:1,NumList:[\"20002000\"]}" } requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'Items': [{'ItemName': '模拟量点1', 'ItemValue': 10.0, 'Unit': 'V'}]") print(body)
def test_13(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetDevicePDRData" data = {"Inputs": "{alarmId:\"e815175d-3051-4d8e-a52e-c97d498bed7e\"}"} headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } Cookie = {"userid": "admin"} requests = Request() r = requests.post(url, data=data, headers=None, cookies=Cookie) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'Success': False, 'ExceptionMsg': '没有数据', 'ActionName': '获取告警曲线数据'") print(body)
def test_10(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=ExportSelectedAlarms" data = { "Inputs": "{AlarmIds:['e815175d-3051-4d8e-a52e-c97d498bed7e'],PageSize:10,PageIndex:1,AllAlarm:true,CampusIds:1001}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'Success': False, 'ExceptionMsg': '登录超时,请重新登录'") print(body)
def test_03(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/admin/action.ashx?prefix=admin&action=AddMonitorIndexFormula" data = { "Inputs": "{IndexFormulaList:[{OprationType:0,ID:null,SystemId:1,FormulaName:'配电自动化系统联动',AnalyzeType:6,SourceName:'',SourceID:1,IndexType:301,IndexFormula:'YC_20002000=30',FormulaParm:0,IsExeute:1,isPushEAM:null,BounceTime:null,ClassType:null,Ext:'',Description:'',UpdateTime:'2020-12-17 18:47:17'}]}" } headers = { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", "Accept-Language": "zh-CN,zh;q=0.9" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] # AssertUtil().assert_in_body(body, "'IndexName': '告警联动', 'IndexFormula': '(YC_20004000+1)'") print(body)
def test_01(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/admin/action.ashx?prefix=admin&action=AddMonitorIndexFormula" data = { "inputs": "{IndexFormulaList:[{OprationType:0,ID:null,'SystemId':1,FormulaName:'配电自动化(1)1设备1:越下限',AnalyzeType:5,SourceName:'',SourceID:1,IndexType:'405',IndexFormula:'YC_20002000=10',FormulaParm:0,IsExeute:1,isPushEAM:0,BounceTime:15,ClassType:0,Ext:'{\"StartTime\":\"00:00:00\",\"EndTime\":\"23:59:59\",\"EndDate\":\"same\"}',Description:'测试告警',UpdateTime:'2020-12-31 10:24:51'}]}" } headers = { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", "Accept-Language": "zh-CN,zh;q=0.9" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] # AssertUtil().assert_in_body(body, "'list': [{'DeviceId': 1, 'TableNum': 18, 'SampleId': 20002000}]") print(body)
def test_07(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?prefix=admin&action=GetDeviceLimit" # data = {"Inputs":"{DateType:0,List:[{TableNum:18,Num:0,RecordNo:null,DeviceId:1}]}"} # data = {"Inputs":"{DateType:0,List:[{TableNum:18,Num:1,RecordNo:null,DeviceId:1}]}"} data = { "Inputs": "{DateType:1,List:[{TableNum:18,Num:null,RecordNo:20002000,DeviceId:1}]}" } requests = Request() r = requests.post(url, data=data, headers=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'ResLimitList': {'18_20002000': {'UpperLimit': '2', " "'LowerLimit': '1', 'DeadZoneValue': '0'}}") print(body)
def test_04(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=ExportDeviceHistoryData" data = { "Inputs": "{Unit:1,StartTime:\"2020-09-08 00:00\",EndTime:\"2020-09-08 11:09\",MinutesNum:10," "DeviceList:[{DeviceId:1,DeviceName:\"1设备1:\",NumList:[{SampleType:18,RecordNo:20002000}]}]}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body(body, "'status': 'success'") print(body)
def test_02(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetSampleDeviceAndPoint" data = { "Inputs": "{CName:\"1设备1\",MCode:\"M009\",pageCurrent:1,PageSize:10}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'ActionInfo': {'ErrorCode': 0, 'Success': True, 'ExceptionMsg': '', " "'ExtendContent': None}, 'Page': {'Current': 1, 'Total': 2}") print(body)
def test_14(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetAlarmsByAlarmCount" data = { "Inputs": "{StartTime:\"2020-08-15\",EndTime:\"2020-09-14\",CampusInfo:1001,AlarmClass:0,PageIndex:1," "PageSize:10,AlarmLevel:3,SysId:1}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } Cookie = {"userid": "admin"} requests = Request() r = requests.post(url, data=data, headers=None, cookies=Cookie) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] # AssertUtil().assert_in_body(body, "'Success': True, 'ExceptionMsg': None, 'ActionName': '获取告警统计弹窗数据'") print(body)
def test_11(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetAlarms" data = { "Inputs": "{ObjName:\"模拟量1\",IsAlarmPage:\"alarm\",StartTime:\"2020-09-14 00:00\"," "EndTime:\"2020-09-14 17:21\",PageSize:10,CampusIds:1001,PageIndex:1,SrcType:0,Flag:-1}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } Cookie = {"userid": "admin"} requests = Request() r = requests.post(url, data=data, headers=headers, cookies=Cookie) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body(body, "'total': 1, 'current': 1, 'Count': 2") print(body)
def test_12(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=ExportSelectedAlarms" data = { "Inputs": "{AlarmIds:[\"e815175d-3051-4d8e-a52e-c97d498bed7e\"],PageSize:10,PageIndex:1," "AllAlarm:true,CampusIds:1001}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } Cookie = {"userid": "admin"} requests = Request() r = requests.post(url, data=data, headers=None, cookies=None) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] # AssertUtil().assert_in_body(body, "'ErrorCode': 0, 'Success': True") print(body)
def test_05(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetDeviceRunInfo" data = { "Inputs": "{Start_StopState:0,DeviceType:1,DevName:\"@@@@\",strMcode:0,On_Offline:0," "RunState:0,pageCurrent:1,PageSize:10,CampusInfo:1001}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'Page': {'Current': 1, 'Total': 0}, 'SysId': 0, 'SysName': '全系统'") print(body)
def test_05(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetIndexPageConfChart" data = { "Inputs": "{SystemId:1,SystemName:'配电自动化',AnalyzeType:2,AnalyzeTypeName:'设备指标类',IndexType:1,IndexTypeName:'总供冷量(kW)',SourceList:[{devType:'CODE1-13',devTypeName:'智能照明3'}],StartTime:'2021-01-12',EndTime:'2021-01-12',TimeGranule:0,DataType:0,RatioType:0}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } requests = Request() r = requests.post(url, data=data, headers=headers) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'RowUnit': {'RowUnitList': {'对象CODE1-13': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}}" ) print(body)
def test_15(): conf_y = ConfigYaml() url_path = conf_y.get_conf_url() url = url_path + "/action.ashx?action=GetAlarmsByAlarmCount" data = { "Inputs": "{StartTime:'2020-08-15',EndTime:'2020-09-14',CampusInfo:1001,AlarmClass:0,PageIndex:1,PageSize:10,AlarmLevel:3,SysId:1}" } headers = { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" } Cookie = {"userid": "admin"} requests = Request() r = requests.post(url, data=data, headers=None, cookies=Cookie) code = r["code"] AssertUtil().assert_code(code, 200) body = r["body"] AssertUtil().assert_in_body( body, "'DeviceName': '设备2', 'AlarmObjName': '模拟量点1', 'AlarmContent': '模拟量1 置数5成功'" ) print(body)