Skip to content

Client can be pickled and unpickled #22

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 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions python_http_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@ def http_request(*_, **kwargs):
else:
# Add a segment to the URL
return self._(name)

def __getstate__(self):
return self.__dict__

def __setstate__(self, state):
self.__dict__ = state
7 changes: 7 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pickle
from os import path
try:
import unittest2 as unittest
Expand Down Expand Up @@ -184,5 +185,11 @@ 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")


if __name__ == '__main__':
unittest.main()