class AddLearnRecord(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() def test_addlearn_record(self): u'测试增加学习记录接口' self.log.info('--------开始测试增加学习记录接口---------') url = 'http://api.lesson.sunnycare.cc/v1/learn/chapadd' L = ['J00201'] for i in L: #加入nonce json_data = { "chap_code": i, "timestamp": str(int(time.time())), "token": self.uid_token, "nonce": get_digit() } #加入sign json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data) try: self.log.info('请求返回的数据是%s' % r.json()) self.assertEqual('请求成功', r.json()['note']) except Exception as e: raise AssertionError self.log.error('增加章节学习记录请求失败,原因是:%s' % e) ''' #数据库查询出章节code,循环加入学习 i = 0 while i < len(chapters): json_data = {"chap_code":chapters[i][0].__str__(), "timestamp":str(time.time()), "token":self.uid_token} r = self.s.post(url,headers = self.header,json=json_data) try: self.log.info('请求返回的数据是%s' % r.json()) self.assertEqual('请求成功',r.json()['note']) except Exception as e: self.log.error('增加'+ chapters[i][0].__str__() +'章节学习记录请求失败,原因是:%s' % e ) i += 1 ''' def tearDown(self): self.s.close()
class Test_pay(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } def test_lesson_frontpage(self): u'测试课程首页接口' url = 'http://api.lesson.sunnycare.cc/v1/rec' #测试环境接口 json_data = { "timestamp": "1523937360", "token": self.uid_token, "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data, verify=False) print(r.json()) #判断返回状态 try: self.assertEqual('请求成功.', r.json()['note'], msg='请求返回状态不是200,有问题') except Exception as e: raise AssertionError print('首页请求失败:%s' % e) imagelinks = [] links = [] L = r.json()['data']['banner_list'] print(L) #将返回json中所有照片链接放进[] for i in L: imagelinks.append(i['image']) links.append(i['link']) print('照片链接:%s' % imagelinks) print('内容链接:%s' % links) #下面测试banner=图片链接是否可用 for image in imagelinks: r1 = self.s.get(image) self.assertEqual(200, r1.status_code, msg='banner图片链接打开失败') #下面测试banner链接是否可用 for link in links: r2 = self.s.get(link) self.assertEqual(200, r2.status_code, msg='banner链接打开失败') def tearDown(self): self.s.close()
class ColumnInfo(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #登录澜渟医生测试环境 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.EXCEL = Excel_util( r'C:\Users\Administrator\Desktop\Interface_testcase.xls') def testColumnInfo(self): u'测试专栏信息接口' url = 'http://api.lesson.sunnycare.cc/v1/spe' #将所有专栏的code放进list column_list = json.loads(self.EXCEL.read_value(4, 6)) print(column_list) new_column_list = [] for x in column_list.values(): new_column_list.append(x) #详情介绍链接 detail_links = [] for i in new_column_list: json_data = { "spe_code": i, "timestamp": str(int(time.time())), "token": self.uid_token, "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data, verify=False) #print(r.json()) detail_links.append(r.json()['data']['detail_link']) self.assertEqual('请求成功.', r.json()['note'], msg='专栏信息返回的状态不是请求成功,有问题!') #下面测试专栏介绍的链接 for link in detail_links: r2 = self.s.get(link, verify=False) self.assertEqual(200, r2.status_code, msg='专栏介绍链接返回状态码不是200!') def tearDown(self): self.s.close()
class ColumnList(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.EXCEL = Excel_util( r'C:\Users\Administrator\Desktop\Interface_testcase.xls') self.log = Log() def test_ColumnList(self): u'测试专栏列表接口' self.log.info('开始测试专栏列表接口....') url = 'http://api.lesson.sunnycare.cc/v1/spe/list' json_data = { "timestamp": str(int(time.time())), "token": self.uid_token, "time": "0" } #加入nonce参数 json_data['nonce'] = get_digit() json_data['sign'] = get_sign(json_data) print(json_data) r = self.s.post(url, headers=self.header, json=json_data, verify=False) self.EXCEL.write_value(4, 5, r.json()) print(r.json()) self.assertEqual('请求成功.', r.json()['note']) data = r.json()['data'] content = data['list'] #专栏列表的内容 self.assertTrue(len(content) >= 1, msg='专栏列表为空,肯定有问题!') spe_codes = {} n = 1 for i in r.json()['data']['list']: spe_codes['spe_code' + str(n)] = i['spe_code'] n += 1 self.EXCEL.write_value(4, 6, (spe_codes)) self.log.info('专栏列表接口测试结束!!') def tearDown(self): self.s.close()
class TestInvoice(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #登录 self.excel = Excel_util( r'C:\Users\Administrator\Desktop\Interface_testcase.xls') self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '1.3', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } def test_invoice(self): u'测试我的发票获取接口' url = 'http://api.exam.sunnycare.cc/v1/myInvoices' json_data2 = {"token": self.uid_token} #请求的参数上一接口返回的token print(json_data2) r = self.s.post(url, headers=self.header, json=json_data2) self.excel.write_value(6, 5, r.json()) self.assertEqual('请求成功.', r.json()['note'], msg='请求我的发票接口没有成功') list1 = r.json()['data']['list'] global d d = {} x = 1 for i in list1: d['code' + str(x)] = i['code'] x += 1 self.excel.write_value(6, 6, d) def test_invoice_detail(self): u'测试查看发票详情接口' url = 'http://api.exam.sunnycare.cc/v1/myInvoiceDetail' #for循环一次去请求每张发票详情 for value in d.values(): print('value', value) json_data = {"token": self.uid_token, "inv_code": value} r = self.s.post(url, headers=self.header, json=json_data) print(r.json()) self.assertEqual('请求成功.', r.json()['note'], msg='发票详情获取失败!') def tearDown(self): self.s.close()
class Con(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() #实例化日志的类 self.exel = Excel_util( r'C:\Users\Administrator\Desktop\interface_testcase.xls') def test_delete_contacts(self): u'删除联系人接口' self.log.info('删除联系人接口测试开始!') url = 'http://api.meet.sunnycare.cc/v2/contact/del' #读取contact_code code = self.exel.read_value(15, 6) be_code = json.loads(code) #如果非空 if code: for v in be_code.values(): json_data = { "token": self.uid_token, "contact_code": v, #读取excel中的code, "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data) self.log.info('删除该条联系人返回结果是:%s' % r.json()) self.assertEqual('请求成功.', r.json()['note']) else: self.log.warning('参会人code为空') self.log.info('删除联系人接口测试结束!!') def tearDown(self): self.s.close()
class Tickets(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() #实例化日志的类 self.excel = Excel_util( r'C:\Users\Administrator\Desktop\Interface_testcase.xls') def test_ticke_info(self): u'会议门票详情接口' self.log.info('开始测试会议门票详情接口') url = 'http://api.meet.sunnycare.cc/v2/ticket/order' #读取ticket_order_code read_code = self.excel.read_value(16, 6) be_use_code = json.loads(read_code) for v in be_use_code.values(): json_data = { "token": self.uid_token, "ticket_order_code": v, "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data) self.log.info('%s的门票详情返回的结果是:%s' % (v, r.json())) self.assertEqual('请求成功.', r.json()['note']) self.log.info('会议门票详情接口测试结束!') def tearDown(self): self.s.close()
class ColumnInfo(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() #实例化日志的类 def testAvailabelCoupon(self): u'测试可领用优惠券列表接口' self.log.info('-----开始测试可领的优惠券列表接口-------') url = 'http://api.lesson.sunnycare.cc/v1/coupon/canget' json_DATA = { "where_code": "K00112", "timestamp": str(int(time.time())), "for_where": "2", "token": self.uid_token, "nonce": get_digit() } json_DATA['sign'] = get_sign(json_DATA) r = self.s.post(url, headers=self.header, json=json_DATA) try: self.log.info('开始断言请求该接口返回的状态是否成功') self.assertEqual('请求成功.', r.json()['note']) except Exception as e: raise AssertionError self.log.error('请求接口返回不成功,原因:%s' % e) self.log.info('---------------测试接口结束--------------------') print(r.json()) def tearDown(self): self.s.close()
class Contact(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = {'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive'} self.log = Log()#实例化日志的类 self.excel = Excel_util(r'C:\Users\Administrator\Desktop\interface_testcase.xls') def test_contact_list(self): u'联系人列表接口' self.log.info('参会人列表接口测试开始') url = 'http://api.meet.sunnycare.cc/v2/contact/records' json_data = { "token":self.uid_token, "nonce": get_digit(), "timestamp": str(int(time.time())) } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) self.log.info('参会人列表返回内容是:%s' % r.json()) conten = r.json()['data']['content'] contact_code = {} j = 1 for i in conten: contact_code['contact_code'+str(j)] = i['contact_code'] j += 1 #将contact_code写入excel供其他借口调用 self.excel.write_value(15,6,contact_code) self.log.info('参会人列表接口测试结束!') def tearDown(self): self.s.close()
class MyInvitation(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #登录 self.header = {'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive'} self.log = Log() def test_my_invitation(self): u'测试我的邀请接口' self.log.info('--------开始测试我的邀请接口--------') url = 'http://api.lesson.sunnycare.cc/v1/invite/mine' json_data = { "token":self.uid_token, "time":"0", "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) try: self.assertEqual('请求成功.',r.json()['note']) self.assertEqual(200,r.json()['code']) self.log.info('我的邀请接口请求成功!') except Exception as e: raise AssertionError print(e) self.log.error('我的邀请接口请求失败,原因:%s' % e) self.log.info('--------我的邀请接口测试结束!--------') def tearDown(self): self.s.close()
class Attach(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() #实例化日志的类 def test_attach_list(self): u'讲义列表接口' self.log.info('开始测试讲义列表接口') url = 'http://api.meet.sunnycare.cc/v2/attach/list' json_data = { "token": self.uid_token, "meet_code": 'M2018072025468', "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data) self.log.info('该会议讲义列表接口返回内容是:%s' % r.json()) self.assertEqual('请求成功.', r.json()['note']) self.log.info('讲义接口测试结束!') def tearDown(self): self.s.close()
def test_banner(self): u'首页banner接口' self.s = requests.session() lgin = LG(self.s) #实例化登录类 uid_token = lgin.login() #直接取第二部登录 url = 'http://api.meet.sunnycare.cc/v2/banner' json_data = {"token": uid_token, "timestamp": int(time.time())} r = self.s.post(url, headers=self.header, json=json_data) d = r.json()['data'] #取出链接,打开,判断状态码 print(d) ''' links = [x['link'] for x in d] for n in links: re = self.s.get(n) self.assertEqual(200,re.status_code,msg='这个链接有问题'+n+'!') ''' #取出图片链接,打开,判断状态码 image_links = [x['image'] for x in d] for y in image_links: re = self.s.get(y) self.assertEqual(200, re.status_code, msg='这个链接有问题' + y + '!')
class SystemInfo(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.lgin.login() self.uid_token = self.lgin.gettoken_loginbyUID() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/2.0.0 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() self.Excel = Excel_util( r'C:\Users\Administrator\Desktop\Interface_testcase.xls') def test_sysinfo_list(self): u'测试系统消息列表接口' self.log.info('------> 开始测试系统消息列表接口 <-------') url = 'http://api.rih.medohealth.com/API/V1/DoctorInfo/doctorInfoWithTelephone' url_1 = 'http://api.common.wrightin.com/v1/note/unread' url_2 = 'http://api.common.wrightin.com/v1/note/records' json_data = {"token": self.uid_token, "Telephone": "15651797525"} json_data_1 = { "token": self.uid_token, "timestamp": '1525245187.2932727' } json_data_2 = { "timestamp": str(time.time()), "type": 0, "token": self.uid_token, "page": 1 } try: r = self.s.post(url, headers=self.header, json=json_data) r1 = self.s.post(url_1, headers=self.header, json=json_data_1) r2 = self.s.post(url_2, headers=self.header, json=json_data_2) print(r.json()) print(r1.json()) print(r2.json()) except Exception as e: self.log.error('请求系统消息列表失败,原因:%s' % e) #self.assertEqual('请求成功.',r.json()['note']) self.log.info('------> 测试系统消息列表接口结束 <-------') #def test_read_sysinfo(self): # u'测试读取系统信息接口' # self.log.info('------> 开始读取系统信息接口 <-------') # url = 'http://api.common.wrightin.com/v1/note/read' # json_data = {"code":"cd95705e442444ba88d3b1fb8b348484", # "token":self.uid_token} def tearDown(self): self.s.close()
class Buyed_lesson(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #登录测试环境澜渟医生 self.header = {'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive'} self.log = Log() def test_buyed_lesson(self): u'这是测试已购课程接口-课程类型为所有' self.log.info('-----开始测试已购课程接口(课程类型是所有)------') url = 'http://api.lesson.sunnycare.cc/v1/orders' json_data = { "timestamp":str(int(time.time())), "product_type":"", "token":self.uid_token, "time":"0", "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) try: self.log.info('断言请求接口是否成功!') self.log.info('返回的内容是:%s' % r.json()) self.assertEqual('请求成功.',r.json()['note']) except Exception as e: raise AssertionError self.log.error('请求已购课程接口失败,原因:%s' % e) def test_buyed_lesson2(self): u'这是测试已购课程接口-课程类型为所有课程' self.log.info('-----开始测试已购课程接口(课程类型是所有课程)------') url = 'http://api.lesson.sunnycare.cc/v1/orders' json_data = { "timestamp":str(int(time.time())), "product_type":"2", "token":self.uid_token, "time":"0", "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) try: self.log.info('断言请求接口是否成功!') self.log.info('返回的内容是:%s' % r.json()) self.assertEqual('请求成功.',r.json()['note']) except Exception as e: raise AssertionError self.log.error('请求已购课程接口失败,原因:%s' % e) def test_buyed_lesson3(self): u'这是测试已购课程接口-课程类型为所有专栏' self.log.info('-----开始测试已购课程接口(课程类型是所有专栏)------') url = 'http://api.lesson.sunnycare.cc/v1/orders' json_data = { "timestamp":str(time.time()), "product_type":"3", "token":self.uid_token, "time":"0", "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) try: self.log.info('断言请求接口是否成功!') self.log.info('返回的内容是:%s' % r.json()) self.assertEqual('请求成功.',r.json()['note']) except Exception as e: raise AssertionError self.log.error('请求已购课程接口失败,原因:%s' % e) def tearDown(self): self.s.close()
class LessonInfo(unittest.TestCase): log = Log() #实例化记录日志的类 def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.lgin.login() self.uid_token = self.lgin.login() #登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } def testLessonList(self): u'测试课程列表' self.log.info('-----开始测试课程列表接口-----') url = 'http://api.lesson.sunnycare.cc/v1/lesson/list' json_data = { "timestamp": str(int(time.time())), "token": self.uid_token, "time": "0", "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data, verify=False) self.log.info('课程列表返回:%s' % r.json()) #判断课程列表获取是否成功 self.assertEqual('请求成功.', r.json()['note'], msg='返回的状态不是请求成功!!!') self.log.info('------------测试结束--------') #将lesson_code保存至txt留下一接口所用 with open(r'C:\Users\Administrator\Desktop\test_data.txt', 'w') as f: for i in r.json()['data']['list']: f.write((i['lesson_code']) + '\n') def testLessonInfo(self): u'测试课程信息' self.log.info('------开始测试课程信息接口---------') url = 'http://api.lesson.sunnycare.cc/v1/lesson' #从txt读取上个接口的lesson_codes来循环post with open(r'C:\Users\Administrator\Desktop\test_data.txt', 'r') as f: lesson_codes = (f.readlines()) #因为readline读取的列表元素末尾有'\n' 所以利用字符串的strip()去除 #print(lesson_codes) need_codes = [] for x in lesson_codes: need_codes.append(x.strip()) print('需要的need_codes:%s' % need_codes, '长度是:%s' % len(need_codes)) #下面循环post课程 来断言课程详情是否获取成功 for n in need_codes: json_data = { "lesson_code": n, "token": self.uid_token, "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r2 = self.s.post(url, headers=self.header, json=json_data, verify=False) self.log.info('%s课程信息返回:%s' % (n, r2.json())) self.assertEqual('请求成功.', r2.json()['note']) self.log.info('------------测试结束---------------') def tearDown(self): self.s.close()
class Test_transaction(unittest.TestCase): def setUp(self): #self.url = 'http://api.lesson.sunnycare.cc/v1/orderHistory' #测试环境接口地址 self.url = 'http://api.exam.sunnycare.cc/v1/orderHistoryNew' self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() def test_transaction_0(self): u'测试交易记录接口(0:全部)' json_data = { 'token': self.uid_token, "is_invoices_req": "0" } #0全部 1未申请发票 2已经申请发票 r = self.s.post(self.url, headers=self.header, json=json_data) print('全部:%s' % r.json()) code = r.json()['code'] n = r.json()['note'] try: self.assertEqual(200, code, msg='返回的状态码不是200') self.assertEqual('请求成功.', n, msg='消息未请求成功') except Exception as e: pass #取出交易记录中的订单号 order_no_list = r.json()['data']['list'] L = [] for i in order_no_list: L.append(i['order_no']) def test_transaction_1(self): u'测试交易记录接口(1:未申请发票)' json_data = { "token": self.uid_token, "is_invoices_req": "1" } #0全部 1未申请发票 2已经申请发票 r = self.s.post(self.url, headers=self.header, json=json_data) print('未申请发票返回:%s' % r.json()) code = r.json()['code'] n = r.json()['note'] try: self.assertEqual(200, code, msg='返回的状态码不是200') self.assertEqual('请求成功.', n, msg='消息未请求成功') except Exception as e: pass def test_transaction_2(self): u'测试交易记录接口(2:已经申请发票)' json_data = { "token": self.uid_token, "is_invoices_req": "2" } #0全部 1未申请发票 2已经申请发票 r = self.s.post(self.url, headers=self.header, json=json_data) print('已申请发票返回:%s' % r.json()) code = r.json()['code'] n = r.json()['note'] try: self.assertEqual(200, code, msg='返回的状态码不是200') self.assertEqual('请求成功.', n, msg='消息未请求成功') except Exception as e: print(e) def test_transacation_detail(self): u'测试交易详情接口' self.log.info('-------------开始测试交易详情接口--------') url = 'http://api.exam.sunnycare.cc/v1/orderDetail' json_data = { 'token': self.uid_token, "is_invoices_req": "0" } #0全部 1未申请发票 2已经申请发票 r = self.s.post(self.url, headers=self.header, json=json_data) print('全部:%s' % r.json()) #取出交易记录中的订单号 order_no_list = r.json()['data']['list'] L = [] for i in order_no_list: L.append(i['order_no']) #循环订单号 for x in L: json_data2 = {"token": self.uid_token, "order_no": str(x)} r2 = self.s.post(url, headers=self.header, json=json_data2) #断言请求返回状态 try: self.assertEqual('请求成功.', r2.json()['note']) self.assertEqual(200, r2.json()['code']) self.log.info('商品交易详情请求成功') except Exception as e: self.log.error('交易详情获取失败,原因是:%s' % e) def tearDown(self): self.s.close()
class Test_pay(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.token = self.lgin.login() self.duid = self.lgin.gettoken_loginbyUID() #取登录成功后的uid self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } def testpayment(self): u'测试通用-支付接口-微信支付' url = 'http://api.rih.sunnycare.cc/API/V1/DoctorLoginForToken/doctorAutoLoginByUID' #医生用uid自动登录接口 json_data1 = { "UID": self.duid, } r = self.s.post( url, headers=self.header, json=json_data1) ##医生用uid自动登录接口的请求数据又是登录成功后返回的json中的duid t = r.json()['data']['Token'] #取到我想要的token json_data2 = { 'pay_method': '1', 'product_type': '3', 'timestamp': str(int(time.time())), "token": t, "product_code": "Z00028", 'nonce': get_digit() } json_data2['sign'] = get_sign(json_data2) #上一接口返回的token现在用来做请求参数 url2 = 'http://api.pay.sunnycare.cc/v1/pay' #支付接口地址 r2 = self.s.post(url2, headers=self.header, json=json_data2) print(r2.json()) self.assertEqual(200, r2.json()['code']) def testpayment2(self): u'测试通用-支付接口-支付宝支付' url = 'http://api.rih.sunnycare.cc/API/V1/DoctorLoginForToken/doctorAutoLoginByUID' #医生用uid自动登录接口 json_data1 = {"UID": self.duid} ##医生用uid自动登录接口的请求数据又是登录成功后返回的json中的duid r = self.s.post(url, headers=self.header, json=json_data1) t = r.json()['data']['Token'] #取到我想要的token #上一接口返回的token现在用来做请求参数 json_data2 = { 'pay_method': '0', 'product_type': '3', 'timestamp': str(int(time.time())), "token": t, "product_code": "Z00028", 'nonce': get_digit() } json_data2['sign'] = get_sign(json_data2) url2 = 'http://api.pay.sunnycare.cc/v1/pay' #支付接口地址 r2 = self.s.post(url2, headers=self.header, json=json_data2) print(r2.json()) self.assertEqual(200, r2.json()['code']) def tearDown(self): self.s.close()
class Mystudy(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #登录 self.header = { 'User-Agent': 'LanTingDoctor/2.0.2 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() self.excel = Excel_util(r'C:\Users\Administrator\Desktop\Interface_testcase.xls') def test_mystudy(self): u'测试我的学习接口' self.log.info('-----开始测试测试我的学习接口-----') url = 'http://api.lesson.sunnycare.cc/v1/learns' json_data = { "token":self.uid_token, "time": "0", "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data,verify=False) print(r.json()) self.assertEqual('请求成功.',r.json()['note']) lessons = r.json()['data']['list'] #定义全局变量 学习code global study_codes study_codes = [] for i in lessons: study_codes.append(i['code']) print('study_codes: ',study_codes) #课程code lesson_codes = [] for x in lessons: lesson_codes.append(x['lesson_code']) print('lesson_codes',lesson_codes) #创建字典 写入excel m = {} j = 1 for z in lesson_codes: m['lessoncode'+ str(j)] = z j += 1 self.excel.write_value(7,6,m) self.log.info('----测试我的学习接口结束----') def test_add_study_chap(self): u'测试增加课程的学习进度接口' self.log.info('====开始测试增加课程的学习进度接口=====') #先通过课程接口来获取章节 url = 'http://api.lesson.sunnycare.cc/v1/lesson' lesson_codes = json.loads(self.excel.read_value(7,6)) #定义全局变量 global chap_codes chap_codes = [] for value in lesson_codes.values(): json_data = { "lesson_code":value, "token":self.uid_token, "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data,verify=False) #断言,我的学习中的每一个课程的标签都应是‘已加入学习’ print(r.json()) self.assertEqual('已加入学习',r.json()['data']['btn'][0]['btn_name']) #将chap_code 加入chap_codes列表 for y in (r.json()['data']['chap_list']): chap_codes.append(y['chap_code']) print('chap_codes:',chap_codes) url_2 = 'http://api.lesson.sunnycare.cc/v1/learn/chapadd' for i in chap_codes: json_data2 = { "chap_code":i, "timestamp":str(int(time.time())), "token":self.uid_token, "nonce": get_digit() } json_data2['sign'] = get_sign(json_data2) r2 = self.s.post(url_2,headers = self.header,json=json_data2,verify=False) self.assertEqual('请求成功',r2.json()['note'],msg='增加课程的学习进度失败') self.log.info('====测试增加课程的学习进度接口结束=====') ''' def test_remove_study(self): u'这是测试取消加入学习接口' self.log.info('-----开始测试测试取消加入学习接口--------') url = 'https://api.lesson.wrightin.com/v1/learn/remove' for i in study_codes: json_data = { "timestamp":str(time.time()), "learn_code":i, "token":self.uid_token } try: r2 = self.s.post(url,headers = self.header,json=json_data) self.assertEqual('请求成功',r2.json()['note']) self.log.info('取消加入学习成功') except Exception as e: self.log.error('取消介入学习失败。原因:%s' % e) self.log.info('-------测试取消加入学习接口结束------') ''' def tearDown(self): self.s.close()
class Contact(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = {'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive'} self.log = Log()#实例化日志的类 self.exel = Excel_util(r'C:\Users\Administrator\Desktop\interface_testcase.xls') def test_add_contacts01(self): u'添加联系人-各个入参正常' self.log.info('开始测试添加参会人接口-参数正常') url = 'http://api.meet.sunnycare.cc/v2/contact/add' #for i in range(3): json_data = { "token": self.uid_token, "name": '你不知道我是谁', "phone": phone_nember(), "sex": '0', "address": '江苏省南京市江宁区', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) self.log.info('添加参会人返回结果:%s' % r.json()) self.assertEqual(200, r.json()['code']) self.assertEqual('请求成功.',r.json()['note']) self.log.info('添加参会人接口-参数正常情况测试结束!\n') def test_add_contacts02(self): u'添加联系人-姓名过长' self.log.info('新增参会人-名称过长') url = 'http://api.meet.sunnycare.cc/v2/contact/add' json_data = { "token": self.uid_token, "name": '大于32个字的名字大于32个字的名字大于32个字的名字大于32个字的名字大于32个字的名字大于32个字的名字', "phone": phone_nember(), "sex": '0', "address": '江苏省南京市江宁区', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) self.log.info('新增名字过长返回结果是:%s' % r.json()) self.assertEqual('请求成功.',r.json()['note']) self.log.info('新增参会人-名称过长情况测试结束!\n') def test_add_contacts03(self): u'添加联系人-手机号码格式不正确' self.log.info('新增参会人-手机号格式不正确') url = 'http://api.meet.sunnycare.cc/v2/contact/add' json_data = { "token": self.uid_token, "name": '司马上官', "phone": '6666111122', "sex": '0', "address": '江苏省南京市江宁区', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) self.log.info('新增手机号格式不正确返回结果是:%s' % r.json()) self.assertEqual(203, r.json()['code']) self.log.info('新增参会人-手机号格式不正确情况测试结束!\n') def test_add_contacts04(self): u'添加联系人-地址为空' self.log.info('新增参会人-地址为空') url = 'http://api.meet.sunnycare.cc/v2/contact/add' json_data = { "token": self.uid_token, "name": '司马上官', "phone": phone_nember(), "sex": '0', "address": ' ', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) self.log.info('新增参会人-地址为空返回结果是:%s' % r.json()) self.assertEqual(203, r.json()['code']) self.log.info('新增参会人-地址为空情况测试结束!\n') @unittest.skip('无理由') def test_add_contacts05(self): u'添加联系人-新增人数过多' self.log.info('新增参会人-新增人数过多') url = 'http://api.meet.sunnycare.cc/v2/contact/add' for i in range(105): json_data = { "token": self.uid_token, "name": '司马上官', "phone": phone_nember(), "sex": '0', "address": ' 南京南京', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url,headers = self.header,json=json_data) while i == 101: self.assertEqual('数量达到上限',r.json()['note']) self.log.info('新增参会人-新增人数过多返回结果是:%s' % r.json()) break self.log.info('新增参会人-新增人数过多情况测试结束!') def tearDown(self): self.s.close()
class Meet(unittest.TestCase): def setUp(self): #banner获取接口 self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = {'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() self.EXCEL = Excel_util(r'C:\Users\Administrator\Desktop\Interface_testcase.xls') def test_getbanner(self): u'测试获取banner链接接口' self.log.info('----------开始测试获取banner接口-----------') url = 'http://api.meet.sunnycare.cc/v2/banner' json_data = { "token":self.uid_token, 'timestamp': str(int(time.time())), 'nonce':get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url=url,headers = self.header,json=json_data) self.log.info('返回的内容是:%s' % r.json()) try: self.assertEqual('请求成功.',r.json()['note']) self.assertEqual(200,r.json()['code']) self.log.info('接口返回状态成功!') except Exception as e: self.log.error('请求失败,原因是:%s' % e) raise AssertionError #取出json中banner链接依次进行get links = r.json()['data'] for link in links: super_link = link['image'] r2 = self.s.get(url=super_link,headers = self.header) try: self.assertEqual(200,r2.status_code) self.log.info('banner链接请求成功') except Exception as e: self.log.error('banner链接请求失败,原因:%s' % e) raise AssertionError self.log.info('----------banner接口测试结束-----------') def test_get_meets(self): u'测试获取会议接口' url = 'http://api.exam.wrightin.com/v1/meetNew' self.log.info('------开始获取会议接口测试-------') json_data = { "token":self.uid_token, "time":"0" } r = self.s.post(url,headers = self.header,json=json_data) #判断返回状态 #print(r.json()) try: self.assertEqual('请求成功.',r.json()['note']) self.log.info('获取会议接口返回状态成功') except Exception as e: self.log.error('返回状态不成功,原因:%s' % e) raise AssertionError #判断会议内容不为空 meet_list = r.json()['data']['list'] try: self.assertLessEqual(1,len(meet_list)) self.log.info('会议内容不为空') except Exception as e: self.log.error('会议内容为空。原因:%s' % e) self.log.info('------获取会议接口测试结束-------') def test_meet_info(self): u'测试每个具体的会议信息' self.log.info('=========开始测试会议信息接口==========') #要先获取到每个会议的code url_1 = 'http://api.meet.sunnycare.cc/v2/meet/records' json_data_1 = { "token":self.uid_token, "time":"0", 'timestamp': str(int(time.time())), 'nonce': get_digit() } json_data_1['sign'] = get_sign(json_data_1) #先获取会议列表 r1 = self.s.post(url_1,headers = self.header,json=json_data_1) #从会议列表中取会议code response = r1.json()['data']['list'] codes = [] for i in response: codes.append(i['code']) #print('code::::',codes) #循环对每一个会议code获取会议信息 url_2 = 'http://api.meet.sunnycare.cc/v2/meet' #创建考试code list exam_codes = [] for code in codes: json_data_2 = { "token":self.uid_token, "meet_code":code, 'timestamp': str(int(time.time())), 'nonce': get_digit() } json_data_2['sign'] = get_sign(json_data_2) r2 = self.s.post(url_2,headers = self.header,json=json_data_2)#json_data可以共用 #print(r2.json()) #断言每个会议信息的返回状态 try: self.assertEqual('请求成功.',r2.json()['note']) self.log.info('会议信息返回状态成功') except Exception as e: self.log.error('会议信息返回状态失败,原因:%s' % e) raise AssertionError #获取试卷code作为关联参数 d = r2.json()['data'] exam_codes.append(d['exam_code']) #去除exam列表中的空元素 new_exam_codes = [] for i in exam_codes: if i != '': new_exam_codes.append(i) print('exam code:' ,new_exam_codes) #将exam code 以字典格式写入excel D = {} x = 1 for i in new_exam_codes: D['exam_code'+ str(x)] = i x += 1 self.EXCEL.write_value(3,5,json.dumps(D)) self.log.info('=========测试会议信息接口结束==========') def test_exam_msg(self): u'测试获取考试信息 接口' self.log.info('-----------开始测试获取考试信息 接口-----------') #之前写入excel是str类型,现在转换为dict类型 exam_codes = json.loads(self.EXCEL.read_value(3,5)) self.log.info('读取的考试code是:%s' % exam_codes) url = 'http://api.exam.sunnycare.cc/v1/examMsgByMeetCode' #循环字典的value作为examcode for value in exam_codes.values(): json_data = { "token":self.uid_token, "examcode":value, "userid":"107dfd1c1ade4a0f820e4897491710c6" } r = self.s.post(url,headers=self.header,json=json_data) try: self.assertEqual('请求成功.',r.json()['note']) self.log.info('考试信息获取成功!') except Exception as e: self.log.error('考试信息获取失败,原因是:%s' % e) raise AssertionError self.log.info('-----------开始测试获取考试信息 接口测试结束!-----------') def tearDown(self): self.s.close()
class LessonInfo(unittest.TestCase): log = Log() #实例化记录日志的类 def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } def testMyCouponList(self): u'测试我的优惠券列表接口--可用' self.log.info('-----------开始测试我的可用优惠券列表接口-------------') url = 'http://api.lesson.sunnycare.cc/v1/coupon/mine' #0.不可用/1.可用 json_data = { "can_use": "1", "timestamp": str(int(time.time())), "token": self.uid_token, "time": "0", "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data, verify=False) self.log.info('返回的可用优惠券参数是:%s' % r.json()) try: self.assertEqual('请求成功.', r.json()['note']) except Exception as e: raise AssertionError self.log.error('请求可用优惠券列表没有成功:%s' % e) #判断优惠券个数,如果个数不为0 ,那么优惠券不能重复! L = [] coupons = r.json()['data']['list'] if len(coupons) != 0: for x in coupons: L.append(x['code']) else: self.log.info('可用优惠券个数为空') self.log.info('可用优惠券的code是:%s' % L) #将code列表转为集合 set set会自动剔除重复的元素 以转为set后的长度来判断是否存在重复code s = set(L) if len(s) < len(L): self.log.error('可用优惠券存在重复的情况') self.log.info('--------我的可用优惠券列表接口测试结束----') def testMyCouponList2(self): u'测试我的优惠券列表接口--不可用' self.log.info('-----------开始测试我的不可用优惠券列表接口-------------') url = 'http://api.lesson.sunnycare.cc/v1/coupon/mine' #0.不可用/1.可用 json_data = { "can_use": "0", "timestamp": str(int(time.time())), "token": self.uid_token, "time": "0", "nonce": get_digit() } json_data['sign'] = get_sign(json_data) r = self.s.post(url, headers=self.header, json=json_data, verify=False) self.log.info('返回的不可用优惠券json是:%s' % r.json()) try: self.assertEqual('请求成功.', r.json()['note']) except Exception as e: raise AssertionError self.log.error('请求不可用优惠券列表没有成功:%s' % e) #判断优惠券个数,如果个数不为0 ,那么优惠券不能重复! L = [] coupons = r.json()['data']['list'] if len(coupons) != 0: for x in coupons: L.append(x['code']) else: self.log.info('不可用优惠券个数为空') self.log.info('不可用优惠券的code是:%s' % L) #将code列表转为集合 set set会自动剔除重复的元素 以转为set后的长度来判断是否存在重复code s = set(L) if len(s) < len(L): self.log.error('不可用优惠券存在重复的情况') self.log.info('--------不可用优惠券列表接口测试结束----') def tearDown(self): self.s.close()
class Contact(unittest.TestCase): def setUp(self): self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.login() #直接取第二部登录 self.header = { 'User-Agent': 'LanTingDoctor/1.3.1 (iPad; iOS 10.1.1; Scale/2.00)', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-Hans-CN;q=1', 'Content-Type': 'application/json', 'requestApp': '3', 'requestclient': '2', 'versionForApp': '2.0', 'Authorization': 'Basic YXBpTGFudGluZ0BtZWRsYW5kZXIuY29tOkFwaVRobWxkTWxkQDIwMTM=', 'Connection': 'keep-alive' } self.log = Log() #实例化日志的类 self.excel = Excel_util( r'C:\Users\Administrator\Desktop\interface_testcase.xls') def test_update_contacts01(self): u'更新联系人-更新名字' #先读取一个参会人code然后更新其信息 read_code = self.excel.read_value(15, 6) be_use_code = json.loads(read_code) update_url = 'http://api.meet.sunnycare.cc/v2/contact/update' json_data = { "token": self.uid_token, "name": '更新后的名字', "contact_code": be_use_code['contact_code1'], "phone": '13605246089', "sex": '0', "address": '江苏省南京市江宁区', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(update_url, headers=self.header, json=json_data) self.assertEqual(200, r.json()['code']) def test_update_contacts02(self): u'更新联系人-更新号码' read_code = self.excel.read_value(15, 6) be_use_code = json.loads(read_code) update_url = 'http://api.meet.sunnycare.cc/v2/contact/update' json_data = { "token": self.uid_token, "name": '更新后的名字', "contact_code": be_use_code['contact_code1'], "phone": '13888888888', "sex": '0', "address": '江苏省南京市江宁区', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(update_url, headers=self.header, json=json_data) self.assertEqual(200, r.json()['code']) def test_update_contacts03(self): u'更新联系人-更新名字' read_code = self.excel.read_value(15, 6) be_use_code = json.loads(read_code) update_url = 'http://api.meet.sunnycare.cc/v2/contact/update' json_data = { "token": self.uid_token, "name": '更新后的名字2', "contact_code": be_use_code['contact_code1'], "phone": '13888888888', "sex": '0', "address": '北京市江宁区天元东路122号', "company": '南京麦澜德', "job": 'xxx', "job_title": 'sss', "is_from_base": '1', "timestamp": str(int(time.time())), "nonce": get_digit() } #入参加密 json_data['sign'] = get_sign(json_data) r = self.s.post(update_url, headers=self.header, json=json_data) self.assertEqual(200, r.json()['code']) def tearDown(self): self.s.close()