Skip to content

Commit

Permalink
issue #64
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtepkeev committed Nov 5, 2014
1 parent ed1d835 commit 60d1693
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Changelog
---------

1.0.2 (2014-10-XX)
1.0.2 (2014-11-XX)
++++++++++++++++++

- Fixed: `Issue #55 <https://github.com/maxtepkeev/python-redmine/issues/55>`__ (TypeError was
raised during processing validation errors from Redmine when one of the errors was returned as
a list)
- Fixed: `Issue #59 <https://github.com/maxtepkeev/python-redmine/issues/59>`__ (Raise ForbiddenError
when a 403 is encountered) (thanks to `Rick Harris <https://github.com/rconradharris>`__)
- Fixed: `Issue #64 <https://github.com/maxtepkeev/python-redmine/issues/64>`__ (Make the Redmine class picklable) (thanks to `Rick Harris <https://github.com/rconradharris>`__)
- Fixed: `Issue #64 <https://github.com/maxtepkeev/python-redmine/issues/64>`__ (Redmine and Resource
classes weren't picklable) (thanks to `Rick Harris <https://github.com/rconradharris>`__)

1.0.1 (2014-09-23)
++++++++++++++++++
Expand Down
3 changes: 3 additions & 0 deletions redmine/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ def __setitem__(self, item, value):

def __getattr__(self, item):
"""Returns the requested attribute and makes a conversion if needed"""
if item.startswith('_'):
raise AttributeError

if item in self._attributes:
# If item shouldn't be converted let's return it as it is
if item in self._unconvertible:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ def test_update_validation_exception(self):
def test_delete_validation_exception(self):
self.assertRaises(ValidationError, lambda: self.redmine.wiki_page.delete('Foo'))

def test_manager_is_picklable(self):
import pickle
project = self.redmine.project
project.url = 'foo'
project.params = {'foo': 'bar'}
unpickled_project = pickle.loads(pickle.dumps(project))
self.assertEqual(project.url, unpickled_project.url)
self.assertEqual(project.params['foo'], unpickled_project.params['foo'])

@mock.patch('requests.put')
@mock.patch('requests.post')
def test_create_validation_exception_via_put(self, mock_post, mock_put):
Expand Down
15 changes: 7 additions & 8 deletions tests/test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ def test_auth(self):
self.response.json = json_response({'user': {'firstname': 'John', 'lastname': 'Smith', 'id': 1}})
self.assertEqual(self.redmine.auth().firstname, 'John')

def test_getattr_on_under_attribute(self):
"""
Attributes that begin with an underscore should not be treated as a
`Resource`. The impetus of this was to make `Redmine` picklable by
preventing the `__getstate__` access from being treated a `Resource`.
"""
with self.assertRaises(AttributeError):
self.redmine.__getstate__
def test_redmine_is_picklable(self):
import pickle
redmine = pickle.loads(pickle.dumps(self.redmine))
self.assertEqual(redmine.key, self.redmine.key)
self.assertEqual(redmine.username, self.redmine.username)
self.assertEqual(redmine.password, self.redmine.password)
self.assertEqual(redmine.requests, self.redmine.requests)
8 changes: 8 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ def test_setting_custom_field_raises_exception_if_not_list_of_dicts(self):
with self.assertRaises(CustomFieldValueError):
project.custom_fields = 'foo'

def test_resource_is_picklable(self):
import pickle
self.response.json = json_response(responses['project']['get'])
project = self.redmine.project.get(1)
unpickled_project = pickle.loads(pickle.dumps(project))
self.assertEqual(project.id, unpickled_project.id)
self.assertEqual(project.name, unpickled_project.name)

def test_project_version(self):
self.assertEqual(self.redmine.project.resource_class.redmine_version, '1.0')

Expand Down
8 changes: 8 additions & 0 deletions tests/test_resultsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ def test_values_resourceset_update_method(self):
self.assertEqual(projects[1]['name'], 'FooBar')
self.assertEqual(projects[2]['name'], 'FooBar')

def test_resourceset_is_picklable(self):
import pickle
projects = self.redmine.project.all()
unpickled_projects = pickle.loads(pickle.dumps(projects))
self.assertEqual(projects[0]['name'], unpickled_projects[0]['name'])
self.assertEqual(projects[1]['name'], unpickled_projects[1]['name'])
self.assertEqual(projects[2]['name'], unpickled_projects[2]['name'])

def test_values_resourceset_delete_method(self):
self.assertEqual(self.redmine.project.all().values().delete(), True)

Expand Down

0 comments on commit 60d1693

Please sign in to comment.