MobilePost.py
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# coding=utf-8
'''
Author: jipeigong 2017年7月19日17:53:38
'''
import json
from atdd.ATDDCase import ATDDCase
class MobilePost(ATDDCase):
def do_login(self):
login_url = '/Public/Api/Debug/Login/SetCookie?uid=' + self.uid + '&_identifier=studycenter'
print("开始登录", self.host + '/' + self.domain + login_url)
response = self.get(login_url)
assert response.status_code == 200, "登陆请求失败" + response.text
data = response.json()
assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False)
return data
# 手机端接口模板
def MobilePost(self, interfaceUrl, data=None, **options):
self.interfaceUrl = interfaceUrl
self.data = data
url = self.host + '/' + self.domain + self.interfaceUrl
r = self.post(url, self.data, **options)
self.assertEquals(200, r.status_code)
result = json.loads(r.text)
errcode = result['errcode']
self.assertEquals(0, errcode)
return result
# 后端接口模板-异常判断
def MobilePostAbnormal(self, interfaceUrl, data=None, code=None, **options):
self.interfaceUrl = interfaceUrl
self.data = data
self.code = code
url = self.host + '/' + self.domain + self.interfaceUrl
r = self.post(url, self.data, **options)
self.assertEquals(200, r.status_code)
result = json.loads(r.text)
errcode = result['errcode']
self.assertEquals(code, errcode)
return result