forked from juanique/python-webclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
109 lines (71 loc) · 3.44 KB
/
Copy pathtests.py
File metadata and controls
109 lines (71 loc) · 3.44 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
import unittest
from webclient import WebClient
class WebClientUnitTest(unittest.TestCase):
def test_init(self):
"It can be initialized specifying a server."
client = WebClient("graph.facebook.com")
self.assertEquals("graph.facebook.com", client.host)
def test_init_secure(self):
"It can be specified wheter the server uses https or not."
client = WebClient("graph.facebook.com", https=True)
self.assertTrue(client.https)
def test_init_fromstring_secure(self):
"Use of https can be infered from the input string."
client = WebClient("https://graph.facebook.com")
self.assertEquals("graph.facebook.com", client.host)
self.assertTrue(client.https)
def test_init_fromstring(self):
"Use (and not use) of https can be infered from the input string."
client = WebClient("http://graph.facebook.com")
self.assertEquals("graph.facebook.com", client.host)
self.assertFalse(client.https)
class WebClientUnitTestRequest(unittest.TestCase):
def setUp(self):
self.client = WebClient("http://localhost:3000")
def test_get_html_status_code(self):
"It can issue a GET request and return a status code"
response = self.client.get("/")
self.assertEquals(200, response.status_code)
def test_get_html_content(self):
"It can issue a GET request and return the page content"
response = self.client.get("/")
self.assertEquals("this is text", response.content)
def test_get_json(self):
"It automatically parses json data."
response = self.client.get("data.json")
self.assertEquals(response.data['name'], "coca cola")
def test_get_data(self):
"It passes POST data arguments thru the querystring."
data = {"param1": "value1", "param2": "value2"}
response = self.client.get("echo_get", data=data)
self.assertEqual(response.data, data)
def test_post_data_json(self):
"It passes json POST data as the request body content."
data = {"param1": "value1", "param2": "value2"}
response = self.client.post("echo_post_json", data=data,
content_type='application/json')
self.assertEqual(response.data, data)
def test_post_data_multipart(self):
"It can POST multipart/form-data"
data = {"param1": "value1", "param2": "value2"}
response = self.client.post("echo_post_multipart", data=data,
content_type='multipart/form-data')
self.assertEqual(response.data, data)
def test_post_data_multipart_file(self):
"It can POST multipart/form-data with attached files"
data = {"param1": "value1", "param2": "value2"}
files = {"textfile" : "fixtures/test1.txt"}
response = self.client.post("echo_post_files", data=data,
files=files, content_type='multipart/form-data')
data.update({'textfile': 'Awesome\n'})
self.assertEqual(response.data, data)
class WebClientUnitTestAuth(unittest.TestCase):
def test_auth(self):
"It support basic http authentication."
client = WebClient("http://localhost:3000")
client.authenticate(username="Aladdin", password="open sesame")
response = client.get("test_auth")
self.assertEqual(response.data['username'], "Aladdin")
self.assertEqual(response.data['password'], "open sesame")
if __name__ == '__main__':
unittest.main()