-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
116 lines (85 loc) · 3.6 KB
/
tests.py
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
from websnake import Head, ResponseHandle, core, die, \
FormData, TokenAuth, Get, Post, Put, Delete, default_headers, Headers,\
BasicAuth, TokenAuth
from urllib.parse import urlencode, urlparse
import unittest
import json
class TestGet0(unittest.TestCase):
def setUp(self):
url = 'http://httpbin.org/get'
self.args = {'key0': 'value0', 'key1': 'value2'}
self.request = Get(url, args=self.args)
self.request.add_map(ResponseHandle.DONE, self.handle_done)
def handle_done(self, request, response):
response_data = json.loads(response.content())
self.assertTrue(response_data['args'], self.args)
die()
def test_get(self):
core.gear.mainloop()
class TestGet1(unittest.TestCase):
def setUp(self):
url = 'https://httpbin.org/get'
auth = BasicAuth('username', 'foobar')
self.request = Get(url, auth=auth)
self.request.add_map(ResponseHandle.DONE, self.handle_done)
def handle_done(self, request, response):
response_data = response.content()
response_data = json.loads(response_data)
authorization = response_data['headers']['Authorization']
self.assertEqual(authorization, request.headers['authorization'])
die()
def test_get(self):
core.gear.mainloop()
class TestGet2(unittest.TestCase):
def setUp(self):
self.url = 'https://httpbin.org/get?e=1&u=2'
auth = TokenAuth('fooobar')
self.request = Get(self.url, auth=auth)
self.request.add_map(ResponseHandle.DONE, self.handle_done)
def handle_done(self, request, response):
response_data = response.content()
response_data = json.loads(response_data)
self.assertEqual(self.url, response_data['url'])
die()
def test_get(self):
core.gear.mainloop()
class TestPost0(unittest.TestCase):
def setUp(self):
self.url = 'https://httpbin.org/post'
self.args = {'key0': 'value0', 'key1': 'value2'}
self.request = Post(self.url, args=self.args)
self.request.add_map(ResponseHandle.DONE, self.handle_done)
def handle_done(self, request, response):
response_data = json.loads(response.content())
self.assertTrue(response_data['args'], self.args)
die()
def test_get(self):
core.gear.mainloop()
class TestPost1(unittest.TestCase):
def setUp(self):
self.url = 'https://httpbin.org/post'
self.data = {'key0': 'value0', 'key1': 'value2'}
self.request = Post(self.url, payload=FormData(self.data))
self.request.add_map(ResponseHandle.DONE, self.handle_done)
def handle_done(self, request, response):
response_data = json.loads(response.content())
self.assertTrue(response_data['form'], self.data)
die()
def test_get(self):
core.gear.mainloop()
class TestPost2(unittest.TestCase):
def setUp(self):
self.url = 'https://httpbin.org/post'
self.data = {'key0': 'value0', 'key1': 'value2'}
self.args = {'key0': 'value0', 'key1': 'value2'}
self.request = Post(self.url, args=self.args, payload=FormData(self.data))
self.request.add_map(ResponseHandle.DONE, self.handle_done)
def handle_done(self, request, response):
response_data = json.loads(response.content())
self.assertTrue(response_data['form'], self.data)
self.assertTrue(response_data['args'], self.args)
url = '%s?%s' % (self.url, urlencode(self.args))
self.assertTrue(response_data['url'], url)
die()
def test_get(self):
core.gear.mainloop()