Skip to content
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

Make Redmine class picklable #65

Merged
merged 1 commit into from
Nov 5, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog
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>`__)

1.0.1 (2014-09-23)
++++++++++++++++++
Expand Down
3 changes: 3 additions & 0 deletions redmine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(self, url, **kwargs):

def __getattr__(self, resource):
"""Returns either ResourceSet or Resource object depending on the method used on the ResourceManager"""
if resource.startswith('_'):
raise AttributeError

return ResourceManager(self, resource)

def upload(self, filepath):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,12 @@ def test_auth(self):
self.response.status_code = 200
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__