ATDDCase.py
2.62 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
import unittest
import requests
# 多企业选择处理
class ATDDCase(unittest.TestCase):
#全局变量
global list
host = "https://yq.vchangyi.com"
uc_host = "http://l-rst.vchangyi.com"
domain = '6B2A70EB0A6916AB0A71D556550EA970'
mobile = '17321009308'
psw = '123456'
uid = '6B2A7F0F0A69039F559F4AA2A010BB26'
cert = ('1_vchangyi.com_bundle.crt', '2_vchangyi.com.key')
header_json = {"Content-Type": "application/json; charset=utf-8"}
header_form = {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}
# 全局cookie
session = requests.Session()
def parse_array(self, prop, value_array):
req_params = {}
count = 0
tpl = "{prop}[{count}][{key}]"
for value in value_array:
for key, val in value.items():
req_params[tpl.format_map({
"prop":prop,
"count":count,
"key":key
})] = val
count += 1
return req_params
def tearDown(self):
if self.session is not None:
self.session.close()
# 请求方法定义
def post(self, url, data=None, **kwargs):
assert self.session
assert url
return self.session.post(
url,
data=data,
**kwargs
)
def get(self, url, **kwargs):
assert self.session
assert url
return self.session.get(
self.host + '/' + self.domain + url,
**kwargs
)
def put(self, url, data=None, **kwargs):
assert self.session
assert url
return self.session.put(
self.host + '/' + self.domain + url,
data=data, **kwargs
)
def delete(self, url, **kwargs):
assert self.session
assert url
return self.session.delete(
self.host + '/' + self.domain + url,
**kwargs
)
def patch(self, url, data=None, **kwargs):
assert self.session
assert url
return self.session.patch(
self.host + '/' + self.domain + url,
data=data, **kwargs
)
def head(self, url, **kwargs):
assert self.session
assert url
return self.session.head(
self.host + '/' + self.domain + url,
**kwargs
)
def options(self, url, **kwargs):
assert self.session
assert url
return self.session.options(
self.host + '/' + self.domain + url,
**kwargs
)