Commit b49bcddb59ae02b29b1a10004d708454e77c9dba
1 parent
d3c1131f
yq-test
Showing
6 changed files
with
312 additions
and
0 deletions
.gitignore
0 → 100644
atdd/ATDDCase.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
3 | + | |
4 | +import unittest | |
5 | +import requests | |
6 | + | |
7 | +# 多企业选择处理 | |
8 | + | |
9 | + | |
10 | +class ATDDCase(unittest.TestCase): | |
11 | + | |
12 | + #全局变量 | |
13 | + | |
14 | + global list | |
15 | + host = "https://yq.vchangyi.com" | |
16 | + uc_host = "http://l-rst.vchangyi.com" | |
17 | + domain = '6B2A70EB0A6916AB0A71D556550EA970' | |
18 | + | |
19 | + | |
20 | + mobile = '17321009308' | |
21 | + psw = '123456' | |
22 | + uid = '6B2A7F0F0A69039F559F4AA2A010BB26' | |
23 | + cert = ('1_vchangyi.com_bundle.crt', '2_vchangyi.com.key') | |
24 | + | |
25 | + header_json = {"Content-Type": "application/json; charset=utf-8"} | |
26 | + header_form = {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"} | |
27 | + | |
28 | + | |
29 | + # 全局cookie | |
30 | + session = requests.Session() | |
31 | + | |
32 | + | |
33 | + def parse_array(self, prop, value_array): | |
34 | + req_params = {} | |
35 | + count = 0 | |
36 | + tpl = "{prop}[{count}][{key}]" | |
37 | + for value in value_array: | |
38 | + for key, val in value.items(): | |
39 | + req_params[tpl.format_map({ | |
40 | + "prop":prop, | |
41 | + "count":count, | |
42 | + "key":key | |
43 | + })] = val | |
44 | + | |
45 | + count += 1 | |
46 | + | |
47 | + return req_params | |
48 | + | |
49 | + | |
50 | + def tearDown(self): | |
51 | + if self.session is not None: | |
52 | + self.session.close() | |
53 | + | |
54 | + # 请求方法定义 | |
55 | + def post(self, url, data=None, **kwargs): | |
56 | + | |
57 | + assert self.session | |
58 | + assert url | |
59 | + | |
60 | + return self.session.post( | |
61 | + url, | |
62 | + data=data, | |
63 | + **kwargs | |
64 | + ) | |
65 | + | |
66 | + def get(self, url, **kwargs): | |
67 | + assert self.session | |
68 | + assert url | |
69 | + return self.session.get( | |
70 | + self.host + '/' + self.domain + url, | |
71 | + **kwargs | |
72 | + ) | |
73 | + | |
74 | + def put(self, url, data=None, **kwargs): | |
75 | + | |
76 | + assert self.session | |
77 | + assert url | |
78 | + | |
79 | + return self.session.put( | |
80 | + self.host + '/' + self.domain + url, | |
81 | + data=data, **kwargs | |
82 | + ) | |
83 | + | |
84 | + def delete(self, url, **kwargs): | |
85 | + | |
86 | + assert self.session | |
87 | + assert url | |
88 | + | |
89 | + return self.session.delete( | |
90 | + self.host + '/' + self.domain + url, | |
91 | + **kwargs | |
92 | + ) | |
93 | + | |
94 | + def patch(self, url, data=None, **kwargs): | |
95 | + | |
96 | + assert self.session | |
97 | + assert url | |
98 | + | |
99 | + return self.session.patch( | |
100 | + self.host + '/' + self.domain + url, | |
101 | + data=data, **kwargs | |
102 | + ) | |
103 | + | |
104 | + def head(self, url, **kwargs): | |
105 | + | |
106 | + assert self.session | |
107 | + assert url | |
108 | + | |
109 | + return self.session.head( | |
110 | + self.host + '/' + self.domain + url, | |
111 | + **kwargs | |
112 | + ) | |
113 | + | |
114 | + def options(self, url, **kwargs): | |
115 | + | |
116 | + assert self.session | |
117 | + assert url | |
118 | + | |
119 | + return self.session.options( | |
120 | + self.host + '/' + self.domain + url, | |
121 | + **kwargs | |
122 | + ) | |
123 | + | ... | ... |
atdd/Config.py
0 → 100644
1 | + | |
2 | +class Errocode: | |
3 | + | |
4 | + global list | |
5 | + | |
6 | + NONE_PARAMETER = 500 #参数为空 | |
7 | + RROR_PARAMETER = 700 #UC报错,参数传递错误 | |
8 | + ERR_TEST = 2064001 #错误码示例', | |
9 | + ERR_PARAM_CAN_NOT_BE_EMPTY = 2074050 #{$name}不能为空', | |
10 | + ERR_PARAM_MUST_IN_RANGE = 2074051 #提交参数({$name}), 必须在({$range})之中', | |
11 | + ERR_PARAM_MAX_LENGTH = 2074052 #提交参数({$name}), 不得超过长度({$maxLength})', | |
12 | + ERR_EMPTY_DATA = 207053 #{$name}数据不存在', | |
13 | + ERR_INTEGRAL_LEVELS_SIZE = 207054 #积分等级至少保留两级', | |
14 | + ERR_INTEGRAL_FIRST_LEVELS_MAX = 207055 #第一级最大积分值不能小于1', | |
15 | + ERR_INTEGRAL_LAST_LEVELS_MAX = 207056 #最后一级最大积分值不正确', | |
16 | + ERR_INTEGRAL_ADJACENT_LEVELS_MAX = 207057 #第({$currentLevel})级的最大积分值必须大于第({$previousLevel})级的最大积分值', | |
17 | + ERR_INTEGRAL_LEVELS_MAX_NULL = 207058 #第({$currentLevel})级的最大积分值不能为空', | |
18 | + ERR_INTEGRAL_LEVELS_NAME_NULL = 207059 #第({$currentLevel})级的等级名称不能为空', | |
19 | + ERR_INTEGRAL_NAME_NULL = 207060 #积分名称不能为空', | |
20 | + ERR_INTEGRAL_UNIT_NULL = 207061 #积分单位不能为空', | |
21 | + ERR_ILLEGAL_POST_PARAM = 207062 #非法的数据类型提交({$name})', | |
22 | + ERR_INTEGRAL_LEVELS_ICON_NULL = 207063 #第({$currentLevel})级的图标不能为空', | |
23 | + ERR_INTEGRAL_ICON_TYPE_NULL = 207063# 第({$currentLevel})级的图标类型不能为空' | |
0 | 24 | \ No newline at end of file | ... | ... |
atdd/MobilePost.py
0 → 100644
1 | +#!/usr/bin/python | |
2 | +# coding=utf-8 | |
3 | + | |
4 | +''' | |
5 | +Author: jipeigong 2017年7月19日17:53:38 | |
6 | +''' | |
7 | + | |
8 | +import json | |
9 | +from atdd.ATDDCase import ATDDCase | |
10 | + | |
11 | +class MobilePost(ATDDCase): | |
12 | + | |
13 | + def do_login(self): | |
14 | + | |
15 | + login_url = '/Public/Api/Debug/Login/SetCookie?uid=' + self.uid + '&_identifier=studycenter' | |
16 | + print("开始登录", self.host + '/' + self.domain + login_url) | |
17 | + response = self.get(login_url) | |
18 | + | |
19 | + assert response.status_code == 200, "登陆请求失败" + response.text | |
20 | + data = response.json() | |
21 | + assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False) | |
22 | + return data | |
23 | + | |
24 | + | |
25 | + # 手机端接口模板 | |
26 | + def MobilePost(self, interfaceUrl, data=None, **options): | |
27 | + | |
28 | + self.interfaceUrl = interfaceUrl | |
29 | + self.data = data | |
30 | + | |
31 | + url = self.host + '/' + self.domain + self.interfaceUrl | |
32 | + r = self.post(url, self.data, **options) | |
33 | + self.assertEquals(200, r.status_code) | |
34 | + result = json.loads(r.text) | |
35 | + errcode = result['errcode'] | |
36 | + self.assertEquals(0, errcode) | |
37 | + return result | |
38 | + | |
39 | + # 后端接口模板-异常判断 | |
40 | + def MobilePostAbnormal(self, interfaceUrl, data=None, code=None, **options): | |
41 | + self.interfaceUrl = interfaceUrl | |
42 | + self.data = data | |
43 | + self.code = code | |
44 | + | |
45 | + url = self.host + '/' + self.domain + self.interfaceUrl | |
46 | + r = self.post(url, self.data, **options) | |
47 | + self.assertEquals(200, r.status_code) | |
48 | + result = json.loads(r.text) | |
49 | + errcode = result['errcode'] | |
50 | + self.assertEquals(code, errcode) | |
51 | + return result | |
0 | 52 | \ No newline at end of file | ... | ... |
atdd/PcPost.py
0 → 100644
1 | +from atdd.ATDDCase import ATDDCase | |
2 | +import hashlib | |
3 | +import json | |
4 | + | |
5 | + | |
6 | +class PcPost(ATDDCase): | |
7 | + | |
8 | + # 多企业登录 | |
9 | + def get_enterprise(self, data): | |
10 | + result = data['result'] | |
11 | + | |
12 | + if isinstance(result, list): | |
13 | + user = result[0] | |
14 | + if len(result) > 1: | |
15 | + print("选择企业:", user['enterpriseInfo']['epName']) | |
16 | + | |
17 | + return user | |
18 | + | |
19 | + def do_login(self, host, mobile=None, pwd=None, domain=None): | |
20 | + | |
21 | + assert host is not None, "登录 host 必须设置" | |
22 | + assert (domain is not None) or ( | |
23 | + mobile is not None and pwd is not None), 'domain 和 mobile/pwd 不能同时为空' | |
24 | + | |
25 | + if mobile is None or pwd is None: | |
26 | + print('没有手机或密码,跳过登陆阶段') | |
27 | + return | |
28 | + | |
29 | + check_mobile_pwd_url = self.host + '/comm/Public/Apicp/Admin/ChkMobilePwd?_identifier=common' | |
30 | + print("校验登录账号密码", check_mobile_pwd_url) | |
31 | + | |
32 | + pwd = hashlib.md5(pwd.encode('utf-8')).hexdigest() | |
33 | + response = self.post( | |
34 | + check_mobile_pwd_url, | |
35 | + { | |
36 | + 'mobile': mobile, | |
37 | + 'passwd': pwd | |
38 | + } | |
39 | + ) | |
40 | + | |
41 | + assert response.status_code == 200, "检测手机和密码" + response.text | |
42 | + | |
43 | + data = response.json() | |
44 | + assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False) | |
45 | + | |
46 | + user = self.get_enterprise(data) | |
47 | + assert user is not None, '选择企业管理员失败' | |
48 | + | |
49 | + self.domain = user['enterpriseInfo']['epEnumber'] | |
50 | + logintoken = user['adminerInfo']['loginToken'] | |
51 | + | |
52 | + login_url = self.host + '/' + self.domain +'/Public/Apicp/Admin/Login?_identifier=common' | |
53 | + print("开始登录", login_url) | |
54 | + response = self.post( | |
55 | + login_url, | |
56 | + { | |
57 | + 'loginToken': logintoken, | |
58 | + 'passwd': pwd | |
59 | + } | |
60 | + ) | |
61 | + | |
62 | + assert response.status_code == 200, "登陆请求失败" + response.text | |
63 | + | |
64 | + data = response.json() | |
65 | + assert data['errcode'] == 0, json.dumps(data, indent=2, sort_keys=False, ensure_ascii=False) | |
66 | + return data | |
67 | + | |
68 | + # 后端接口模板-正常 | |
69 | + def PcPost(self, interfaceUrl, data=None, **options): | |
70 | + | |
71 | + self.interfaceUrl = interfaceUrl | |
72 | + self.data = data | |
73 | + | |
74 | + url = self.host + '/' + self.domain + self.interfaceUrl | |
75 | + r = self.post(url, self.data, **options) | |
76 | + self.assertEquals(200, r.status_code) | |
77 | + result = json.loads(r.text) | |
78 | + errcode = result['errcode'] | |
79 | + self.assertEquals(0, errcode) | |
80 | + return result | |
81 | + | |
82 | + # 后端接口模板-异常判断 | |
83 | + def PcPostAbnormal(self, interfaceUrl, data=None, code = None,**options): | |
84 | + self.interfaceUrl = interfaceUrl | |
85 | + self.data = data | |
86 | + self.code = code | |
87 | + | |
88 | + url = self.host + '/' + self.domain + self.interfaceUrl | |
89 | + r = self.post(url, self.data, **options) | |
90 | + self.assertEquals(200, r.status_code) | |
91 | + result = json.loads(r.text) | |
92 | + errcode = result['errcode'] | |
93 | + self.assertEquals(code, errcode) | |
94 | + return result | |
0 | 95 | \ No newline at end of file | ... | ... |
tests/Staff-Management/Organization/test_search_org.py
0 → 100644
1 | + | |
2 | + # Author: jipeihong 2017年11月7日11:22:08 | |
3 | + | |
4 | +from atdd.PcPost import PcPost | |
5 | + | |
6 | +class SearchOrg(PcPost): | |
7 | + def setUp(self): | |
8 | + self.do_login(self.host, self.mobile, self.psw, self.domain) | |
9 | + | |
10 | + def test_search_org(self): | |
11 | + interfaceUrl = "/contact/Apicp/Department/Search" | |
12 | + data = { | |
13 | + "keyword": 123 | |
14 | + } | |
15 | + result = self.PcPost(interfaceUrl,data) | |
16 | + print(result) | |
17 | + return result | |
18 | + | |
19 | + | |
20 | + | ... | ... |