class Query(unittest.TestCase): def setUp(self): self.log = Log() self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.gettoken_loginbyUID() #直接取第二部登录 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' } @unittest.skip('no reason') def test_query_hosName(self): u'模糊查询医院接口' url = 'http://api.rih.medohealth.com/API/V1/DoctorInfo/SeacherHosName' content = [' ', '南京', '02182', '麦澜德'] #模糊查询的内容 for i in content: print(i) json_data = {"token": self.uid_token, "query": i} print(json_data) r = self.s.post(url, headers=self.header, json=json_data) self.assertEqual('Success', r.json()['msg'], '查询出错') 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.gettoken_loginbyUID() #直接取第二部登录 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() #实例化日志的类 @unittest.skip('无理由') def test_download_attach(self): u'下载讲义接口' url = 'http://api.meet.sunnycare.com/v2/attach/mine' json_data = {"token": self.uid_token, "attach_code": 'ss'} r = self.s.post(url, headers=self.header, json=json_data) def tearDown(self): self.s.close()
class Adress(unittest.TestCase): def setUp(self): self.log = Log() self.s = requests.session() self.lgin = LG() #实例化登录类 self.uid_token = self.lgin.gettoken_loginbyUID() #直接取第二部登录 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.set_nonce = Hash.get_md5(Hash.get_str()) self.set_sign = Hash.get_md5(Hash.get_str()) @unittest.skip('无条件跳过') def test_All_Adress(self): u'获取用户的全部收货地址接口' self.log.info('开始测试获取用户的全部收货地址接口') url = 'http://api.common.wrightin.com/v1/address/records' print(self.set_sign) print(self.set_nonce) json_data = { "nonce": self.set_nonce, "timestamp": str(time.time()), #"sign":self.set_sign, "token": self.uid_token } r = self.s.post(url, headers=self.header, json=json_data) print(r.json()) if self.assertEqual('请求成功.', r.json()['note']): self.log.info('获取用户的全部收货地址接口成功') else: self.log.error('获取用户的全部收货地址接口失败') self.log.info('测试获取用户的全部收货地址接口结束') @unittest.skip('无条件跳过') def testAddAdress(self): u'测试增加收货地址接口' self.log.info('开始测试新增收货地址接口') url = 'http://api.common.wrightin.com/v1/address/apend' json_data = { "zone": "江苏省南京市江宁区", "content": "南京江宁区气象台", "contact_call": "15651797525", "contact_name": "许下会", "token": self.uid_token, "timestamp": "1525674917", } r = self.s.post(url, headers=self.header, json=json_data) print(r.json()) self.assertEqual('请求成功.', r.json()['note']) 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 Wechat_login(unittest.TestCase): ''' APP 编号:澜渟 - 1,澜渟私教 - 2,澜婷医生 - 3; 客户端类型编号:Android - 1,iOS - 2,PC - 3,Web - 4; ''' def setUp(self): self.log = Log() self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.gettoken_loginbyUID() #直接取第二部登录 self.header1 = {'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_login_by_wechat(self): u'测试澜渟医生IOS微信登录接口' self.log.info('澜渟医生IOS微信登录接口测试开始') url = 'http://api.rih.medohealth.com/API/V1/DoctorLoginForToken/doctorLoginByWeChat' json_data = {"WeChatOpenID":"ogCzv1U6KPBJxRu0-LgrHBhRiJpI", "WeChatUnionID":"oh3fH06yJfDB6smX6kJACRNlglVY" } r = self.s.post(url,headers = self.header1,json=json_data) self.assertEqual('登录成功',r.json()['msg'],msg='澜渟医生IOS微信方式登录失败') self.log.info('澜渟医生IOS微信登录接口测试结束') def test_login_by_wechat2(self): u'澜渟医生测试Andriod微信登录接口' self.log.info('澜渟医生Andriod微信登录接口测试开始') self.header1['requestclient'] = str(1) url = 'http://api.rih.medohealth.com/API/V1/DoctorLoginForToken/doctorLoginByWeChat' json_data = {"WeChatOpenID":"ogCzv1U6KPBJxRu0-LgrHBhRiJpI", "WeChatUnionID":"oh3fH06yJfDB6smX6kJACRNlglVY" } r = self.s.post(url,headers = self.header1,json=json_data) self.log.info('澜渟医生Andriod微信登录返回:%s' % r.json()) self.assertEqual('登录成功',r.json()['msg'],msg='澜渟医生Andriod微信方式登录失败') self.log.info('澜渟医生Andriod微信登录接口测试结束') def test_login_by_wechat3(self): u'澜渟测试Andriod微信登录接口' self.header1['requestApp'] = str(1) self.log.info('澜渟Andriod微信登录接口测试开始') url = 'http://api.rih.medohealth.com/API/V1/DoctorLoginForToken/doctorLoginByWeChat' json_data = {"WeChatOpenID":"ogCzv1U6KPBJxRu0-LgrHBhRiJpI", "WeChatUnionID":"oh3fH06yJfDB6smX6kJACRNlglVY" } r = self.s.post(url,headers = self.header1,json=json_data) self.log.info('澜渟Andriod微信登录返回:%s' % r.json()) self.assertEqual('登录成功',r.json()['msg'],msg='澜渟Andriod微信方式登录失败') self.log.info('澜渟Andriod微信登录接口测试结束') def tearDown(self): self.s.close()
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 Doctor(unittest.TestCase): def setUp(self): self.log = Log() self.s = requests.session() self.lgin = LG(self.s) #实例化登录类 self.uid_token = self.lgin.gettoken_loginbyUID() #直接取第二部登录 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' } @unittest.skip('无条件跳过') def test_update_good_at(self): u'更新专业擅长接口' '''专业擅长内容:10 至 512 个字符''' self.log.info('开始测试更新专业擅长接口') url = 'http://api.rih.medohealth.com/API/V1/DoctorInfo/modifyRep' content = [ ' ', '08152', '!@#$%^&~!@#$%^&*!@###@@', '专业擅长吹牛a皮看电视手机立刻就', '1asdddsa23WEsjkla在卡利姆多卢' ] for i in content: json_data = {"token": self.uid_token, "rep": i} r = self.s.post(url, headers=self.header, json=json_data) if len(i) < 10: self.assertEqual('请输入 10 至 512 个字符.', r.json()['msg'], msg='更新擅长内容失败') else: self.assertEqual('Success.', r.json()['msg'], msg='更新擅长内容失败') self.log.info('测试更新专业擅长接口结束!') @unittest.skip('无条件跳过') def test_update_person_info(self): u'更新个人简介接口' '''简介内容:10 至 512 个字符''' self.log.info('开始测试更新个人简介接口') url = 'http://api.rih.medohealth.com/API/V1/DoctorInfo/modifyRemark' content = [ '长度<10', '长度等于十88888', '长度大于10撒了很多哈桑的好阿三的快乐就到拉萨就叫', '!@@#¥¥%&**……%……&*……&(是否合适2212WEJash' ] for i in content: json_data = {"token": self.uid_token, "remark": i} r = self.s.post(url, headers=self.header, json=json_data) if len(i) < 10: self.assertEqual('请输入 10 至 512 个字符.', r.json()['msg'], msg='更新个人简介失败') else: self.assertEqual('Success.', r.json()['msg'], msg='更新个人简介失败') self.log.info('测试更新个人简介接口结束') @unittest.skip('无条件跳过') def test_update_born_date(self): u'测试更新出生日期接口' self.log.info('开始测试更新出生日期接口') url = 'http://api.rih.medohealth.com/API/V1/DoctorInfo/modifyBorn' json_data = {"token": self.uid_token, "born": "2017-05-01 00:00:00"} r = self.s.post(url, headers=self.header, json=json_data) self.assertEqual('Success.', r.json()['msg'], msg='更新出生日期失败') self.log.info('测试更新出生日期接口结束') @unittest.skip('无条件跳过') def test_uphospital_department(self): u'测试更新医院和科室接口' self.log.info('开始测试更新医院和科室接口') url = 'http://api.rih.medohealth.com/API/V1/DoctorInfo/modifyHosDep' json_data = { "token": self.uid_token, "huid": "99D8CA14B516813A698C63D745508D0E", "kuid": "umvtDTbiCaR3Yl7xgEQSqWs0FAI1NHhd" } r = self.s.post(url, headers=self.header, json=json_data) self.assertEqual('Success.', r.json()['msg'], msg='更新医院和科室失败') self.log.info('测试更新医院和科室接口结束') def tearDown(self): self.s.close()