1
- import os
2
1
import pickle
3
- from os import path
2
+
4
3
try :
5
4
import unittest2 as unittest
6
5
except ImportError :
7
6
import unittest
8
- from python_http_client .client import Client , Response
7
+ from python_http_client .client import Client
9
8
from python_http_client .exceptions import (
10
9
handle_error ,
11
10
HTTPError ,
15
14
ServiceUnavailableError
16
15
)
17
16
18
-
19
17
try :
20
18
# Python 3
21
19
import urllib .request as urllib
22
20
except ImportError :
23
21
# Python 2
24
22
import urllib2 as urllib
25
23
26
-
27
24
try :
28
25
basestring
29
26
except NameError :
@@ -63,7 +60,7 @@ def __init__(self, host, response_code, timeout=None):
63
60
Client .__init__ (self , host )
64
61
65
62
def _make_request (self , opener , request , timeout = None ):
66
- if 200 <= self .response_code < 299 : # if successful code
63
+ if 200 <= self .response_code < 299 : # if successful code
67
64
return MockResponse (self .response_code )
68
65
else :
69
66
raise handle_error (MockException (self .response_code ))
@@ -76,7 +73,7 @@ def setUp(self):
76
73
self .api_key = "SENDGRID_API_KEY"
77
74
self .request_headers = {
78
75
'Content-Type' : 'application/json' ,
79
- 'Authorization' : 'Bearer ' + self .api_key ,
76
+ 'Authorization' : 'Bearer ' + self .api_key
80
77
}
81
78
self .client = Client (host = self .host ,
82
79
request_headers = self .request_headers ,
@@ -154,7 +151,7 @@ def test__getattr__(self):
154
151
self .assertEqual (client ._version , 3 )
155
152
156
153
# Test GET
157
- mock_client ._url_path + ['test' ]
154
+ mock_client ._url_path + ['test' ]
158
155
r = mock_client .get ()
159
156
self .assertEqual (r .status_code , 200 )
160
157
@@ -191,11 +188,14 @@ def test__getattr__(self):
191
188
mock_client .response_code = 523
192
189
self .assertRaises (HTTPError , mock_client .delete )
193
190
194
-
195
191
def test_client_pickle_unpickle (self ):
196
192
pickled_client = pickle .dumps (self .client )
197
193
unpickled_client = pickle .loads (pickled_client )
198
- self .assertDictEqual (self .client .__dict__ , unpickled_client .__dict__ , "original client and unpickled client must have the same state" )
194
+ self .assertDictEqual (
195
+ self .client .__dict__ ,
196
+ unpickled_client .__dict__ ,
197
+ "original client and unpickled client must have the same state"
198
+ )
199
199
200
200
201
201
if __name__ == '__main__' :
0 commit comments