Skip to content

Fix #80 #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
import pickle
from os import path

try:
import unittest2 as unittest
except ImportError:
import unittest
from python_http_client.client import Client, Response
from python_http_client.client import Client
from python_http_client.exceptions import (
handle_error,
HTTPError,
Expand All @@ -15,15 +14,13 @@
ServiceUnavailableError
)


try:
# Python 3
import urllib.request as urllib
except ImportError:
# Python 2
import urllib2 as urllib


try:
basestring
except NameError:
Expand Down Expand Up @@ -63,7 +60,7 @@ def __init__(self, host, response_code, timeout=None):
Client.__init__(self, host)

def _make_request(self, opener, request, timeout=None):
if 200 <= self.response_code < 299: # if successful code
if 200 <= self.response_code < 299: # if successful code
return MockResponse(self.response_code)
else:
raise handle_error(MockException(self.response_code))
Expand All @@ -76,7 +73,7 @@ def setUp(self):
self.api_key = "SENDGRID_API_KEY"
self.request_headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + self.api_key,
'Authorization': 'Bearer ' + self.api_key
}
self.client = Client(host=self.host,
request_headers=self.request_headers,
Expand Down Expand Up @@ -154,7 +151,7 @@ def test__getattr__(self):
self.assertEqual(client._version, 3)

# Test GET
mock_client._url_path+['test']
mock_client._url_path + ['test']
r = mock_client.get()
self.assertEqual(r.status_code, 200)

Expand Down Expand Up @@ -191,11 +188,14 @@ def test__getattr__(self):
mock_client.response_code = 523
self.assertRaises(HTTPError, mock_client.delete)


def test_client_pickle_unpickle(self):
pickled_client = pickle.dumps(self.client)
unpickled_client = pickle.loads(pickled_client)
self.assertDictEqual(self.client.__dict__, unpickled_client.__dict__, "original client and unpickled client must have the same state")
self.assertDictEqual(
self.client.__dict__,
unpickled_client.__dict__,
"original client and unpickled client must have the same state"
)


if __name__ == '__main__':
Expand Down