def test_publishlist_success(self): '''所有参数都传''' token = Login().login() # 引用登录 params = 'pageno=1&perpage=600' print params r = self.myhttp('GET', self.url_path, params, token) print r js = json.loads(r) self.assertEqual(js['state'], 1) self.assertIn('获取我发布的成功', js['message']) print len(js['result']) for i in range(len(js['result'])): print js['result'][i]['contentId'] print js['result'][i]['contentType']
def test_followinglist_success(self): '''所有参数都传''' # token = 'YzYzMzZkZTNjZjE5ZTY4Nzc1YjcxMWJhZDgxODVmZjE=' token = Login().login() # 引用登录 params = 'targetCustomerId=1096&pageno=1&perpage=20&customerid=1081' print params r = self.myhttp('GET', self.url_path, params, token) print r js = json.loads(r) self.assertEqual(js['state'], 1) self.assertIn('获取关注列表', js['message']) print len(js['result']) for i in range(len(js['result'])): print js['result'][i]['nickname']
def test_followerlist_noncerror(self): '''nonce不正确''' self.token = Login().login() # 引用登录 print self.token # params = 'targetCustomerId=1096&pageno=1&perpage=20&customerid=1081' params = { 'targetCustomerId': '1096', 'pageno': '1', 'perpage': '20', 'customerid': '1081' } print params r = self.noncerror('GET', self.url_path, params, self.token) print r
def test_publishlist_success1(self): '''所有参数都不传''' token = Login().login() # 引用登录 params = 'customerid=1056' print params r = self.myhttp('GET', self.url_path, params, token ) print r js = json.loads(r) self.assertEqual(js['state'], 1) self.assertIn('操作成功', js['message'])
def test_publishlist_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = '' r = self.myhttp('GET', self.url_path, params, token+'ee' ) print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_showreport_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 params = 'type=15030&=123&showId=861' r = self.myhttp( 'POST', self.url_path, params, # {'type': '15030', '': '123', 'showId': 861}, token + '1') print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn("token无效", js['message'])
def test_topicreportpost_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token r = self.topicpost('POST', self.url_path, { 'type': 15000, 'content': u'其他', 'topicId': 323 }, token + '3e') print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_showreport_idpanull(self): '''必填参数(showid)为空''' token = Login().login() # 引用登录 params = 'type=15000&=907' r = self.myhttp( 'POST', self.url_path, params, # {'': '907', 'type': 15000}, token) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn("'show_id' cannot be null", js['message'])
def test_showreport_ctnull(self): '''类型为其他,content的值为空,举报失败''' token = Login().login() # 引用登录 params = 'type=15030&content=&showId=861' r = self.myhttp( 'POST', self.url_path, params, # {'type': '15030', 'content': '', 'showId': 861}, token) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn("内容不能为空", js['message'])
def test_showreport_idlose(self): '''测试参数不完整,必填参数(showId)未传''' token = Login().login() # 引用登录 params = 'type=15000' r = self.myhttp( 'POST', self.url_path, params, # {'type': 15000}, token) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn("'show_id' cannot be null", js['message'])
def test_unreg_noncerror(self): '''nonce不正确''' token = Login().login() # 引用登录 params = {'deviceId': '81251114'} print params r = self.noncerror('POST', self.url_path, params, token ) print r js = json.loads(r) self.assertEqual(js['state'], -2) self.assertIn('拦截请求授权出错', js['message'])
def test_unreg_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = 'deviceId=81251114' r = self.myhttp('POST', self.url_path, params, token + '1' ) print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_showdelpost_IDnull(self): '''必填字段(showid)的值为空''' token = Login().login() # 引用登录 params = 'showId=' r = self.myhttp( 'POST', self.url_path, params, # {'showId': ''}, token) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn("请选择一个作品", js['message'])
def test_showdelpost_IDlose(self): '''showId未传,删除失败''' token = Login().login() # 引用登录 params = '' r = self.myhttp( 'POST', self.url_path, params, # {'': ''}, token) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn("请选择一个作品", js['message'])
def test_recipesubmit_success11(self): '''所有参数都传入,提交成功''' self.url = self.base_url + self.url_path self.signature = generateSignature(self.nonce, 'POST', self.url) self.token = Login().login() # 引用登录 print self.token self.headers = {'nonce': self.nonce, 'User-Agent': 'chunmiapp', 'signature': self.signature } self.headers = {'nonce': self.nonce, 'User-Agent': 'chunmiapp', 'signature': self.signature } register_openers() # post_data ={"name": "测试发布食谱", # "tagList": [317, 318], # "DeviceModelGroup":[1,3], # "ingredientList": [{"name": "牛肉", "quality": "一斤"}, {"name": "五花肉", "quality": "二斤"}], # "steps": [{"stepPic": "pic1", "description": "step1"}, {"stepPic": "pic2", "description": "step2"}], # "content": "content", # "iconPath": "iconPath", # "peopleNum": 5, # "duration": 10, # "description": "description", # "state": 2100, # "categoryId": 3} post_data ='json={"id":"","name":"Zho222","deviceid":"1083258","templetid":"19","tagList":[319,267,266,257,164],"auxiliaryList":[{"name":"Q","quality":"1"},{"name":"W","quality":"2"}],"ingredientList":[{"name":"E","quality":"2"},{"name":"R","quality":""},{"name":"","quality":"4"}],"steps":[{"stepPic":"1498529207/4986F036-0F1E-4C62-8CE7-2DFD2B87FC28-960F91E6-0AC3-4B62-A750-5113C58DF9FD.jpg","description":"1"},{"stepPic":"","description":"2"},{"stepPic":"","description":"3"},{"stepPic":"1498529232/4986F036-0F1E-4C62-8CE7-2DFD2B87FC28-44D5C93F-0652-481B-8A5E-B974D0AA4E87.jpg","description":"4"}],"StepDto":[],"content":"","iconPath":"1498529157/4986F036-0F1E-4C62-8CE7-2DFD2B87FC28-8FABB4F3-FADA-4B62-82CA-DE409E0389B1.jpg","peopleNum":"2","duration":"","description":"Hah ","deviceModelGroupList":[]}' encoded = encryptAES(post_data,self.key) data = {'data': encoded} payload = urllib.urlencode(data) print data print payload request = urllib2.Request(self.url, data=payload) request.add_header('nonce', self.nonce) request.add_header('signature', self.signature) request.add_header('User-Agent', 'chunmiapp') request.add_header('token', self.token) result = urllib2.urlopen(request).read() print result s = decryptAES(result, self.key) print s js = json.loads(s) self.assertEqual(js['state'], 1) self.assertEqual(js['message'], '提交成功,正在审核') recipeid = js['result'] print recipeid
def test_v3addpost_noncerror(self): '''nonce不正确''' self.token = Login().login() # 引用登录 print self.token params = {'recipeId': '431'} print params r = self.noncerror('POST', self.url_path, params, self.token ) print r js = json.loads(r) self.assertEqual(js['state'], -2) self.assertIn('拦截请求授权出错', js['message'])
def test_v3addpost_relose(self): '''测试参数不完整,必填参数(recipeId)未传''' token = Login().login() # 引用登录 print token params = '' r = self.myhttp('POST', self.url_path, params, token ) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn('请选择一个食谱', js['message'])
def test_praise_noncerror(self): '''nonce不正确''' self.token = Login().login() # 引用登录 print self.token params ={'topicId': 16, 'praise': 'praise'} print params r = self.noncerror('GET', self.url_path, params, self.token ) print r js = json.loads(r) self.assertEqual(js['state'], -2) self.assertIn('拦截请求授权出错', js['message'])
def test_showinformationget_noncerror(self): '''nonce不正确''' self.token = Login().login() # 引用登录 print self.token params ={'showId': 874} print params r = self.noncerror('GET', self.url_path, params, self.token ) print r js = json.loads(r) self.assertEqual(js['state'], -2) self.assertIn('拦截请求授权出错', js['message'])
def test_topiccomment_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = 'content=test&topicId=6' r = self.myhttp( 'POST', self.url_path, params, # {'topicId': 6, 'content': 'hao'}, token + '1') print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_praise_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = 'praise=praise&topicId=16' r = self.myhttp('POST', self.url_path, params, # {'topicId': 56, 'praise': 'praise'}, token+ '1' ) print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_topiccommentdeletes_signerror(self): '''签名错误''' self.token = Login().login() # 引用登录 print self.token params ={'recipeId': '256', 'content': '123', 'stars': 4} print params r = self.signerror('POST', self.url_path, params, self.token ) print r js = json.loads(r) self.assertEqual(js['state'], -2) self.assertIn('拦截请求授权出错', js['message'])
def test_recipeCommentdelpost_signerror(self): '''签名错误''' self.token = Login().login() # 引用登录 print self.token params ={'commentId': '902'} print params r = self.signerror('POST', self.url_path, params, self.token ) print r js = json.loads(r) self.assertEqual(js['state'], -2) self.assertIn('拦截请求授权出错', js['message'])
def test_recipeCommentadd_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = 'recipeId=256&stars=4&content=123' r = self.myhttp('POST', self.url_path, params, # {'recipeId': '256', 'content': '123','stars': 4}, token + '1' ) print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_recipeCommentadd_ctlose(self): '''必填参数(content)未传''' token = Login().login() # 引用登录 print token params = 'recipeId=256&stars=4' r = self.myhttp('POST', self.url_path, params, # {'recipeId': '256', 'stars': 4}, token ) print r js = json.loads(r) self.assertEqual(js['state'], 1) self.assertIn( '发表成功',js['message'])
def test_recipeCommentadd_idpanull(self): '''必填参数(recipeId)为空''' token = Login().login() # 引用登录 print token params = '=1661&parentId=1882&content=棒&stars=4' r = self.myhttp('POST', self.url_path, params, # {'': '1661', 'content': '123', 'parentId': '1882', 'stars': 4}, token ) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn( '发表评论发生错误',js['message'])
def test_draftlist_success(self): '''获取用户上传食谱草稿列表''' token = Login().login() #引用登录 # token = 'ZDI5ZTcyNjUyZTFhMzdhNjVhZWQ0ODhlN2M5MjJhNDk=' print token r = self.nocryp('GET', self.url_path, {'': ''}, token) print r js = json.loads(r) self.assertEqual(js['state'], 1) self.assertIn(u'获取用户草稿成功', js['message']) print len(js['result']) for i in range(len(js['result'])): print js['result'][i]['name'] print js['result'][i]['id']
def test_v3addpost_repanull(self): '''必填字段(recipeId)为空''' token = Login().login() # 引用登录 print token params = '=431' r = self.myhttp('POST', self.url_path, params, token ) print r js = json.loads(r) self.assertEqual(js['state'], -1) self.assertIn('请选择一个食谱', js['message'])
def test_review_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = 'showId=784&content=test' r = self.myhttp( 'POST', self.url_path, params, # {'showId': '818', 'content': 'test123'}, token + '1') print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])
def test_showcommentdpost_tokenerror(self): '''token错误''' token = Login().login() # 引用登录 print token params = 'showId=816&commentId=1021' r = self.myhttp( 'POST', self.url_path, params, # {'showId': '816','commentId': '1021'}, token + '1') print r js = json.loads(r) self.assertEqual(js['state'], -3) self.assertIn('token无效', js['message'])