Skip to content

Commit

Permalink
fix for creation of some resources via new() method
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtepkeev committed Feb 20, 2014
1 parent eecd8d8 commit f127314
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
---------

0.6.1 (2014-02-XX)
++++++++++++++++++

- Fixed: `Issue #10 <https://github.com/maxtepkeev/python-redmine/issues/10>`__ (Python
Redmine was incorrectly raising ``ResourceAttrError`` while creating some resources via
new() method)

0.6.0 (2014-02-19)
++++++++++++++++++

Expand Down
4 changes: 2 additions & 2 deletions redmine/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _Resource(object):
_changes = {}
_includes = ()
_relations = ()
_readonly = ('id', 'created_on', 'updated_on', 'author', 'user', 'project', 'issue') #: Read-only attributes
_readonly = ('id', 'created_on', 'updated_on', 'author', 'user', 'project', 'issue')
__length_hint__ = None # fixes Python 2.6 list() call on resource object

def __init__(self, manager, attributes):
Expand Down Expand Up @@ -208,7 +208,7 @@ def post_update(self):

def save(self):
"""Creates or updates a resource"""
if any(item in self.attributes and item not in (self._relations + self._includes) for item in self._readonly):
if 'id' in self.attributes or 'created_on' in self.attributes:
self.pre_update()
self.manager.update(self.internal_id, **self._changes)
self.attributes['updated_on'] = datetime.utcnow().strftime(self.manager.redmine.datetime_format)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ def test_wiki_page_delete(self):
self.assertEqual(self.redmine.wiki_page.delete('Foo', project_id=1), True)

def test_wiki_page_update(self):
self.response.json.return_value = responses['wiki_page']['get']
response = {'wiki_page': {'title': 'Foo', 'version': 1, 'created_on': '2012-06-27T12:48:15Z'}}
self.response.json.return_value = response
wiki_page = self.redmine.wiki_page.get('Foo', project_id=1)
wiki_page.text = 'Foo'
self.assertEqual(wiki_page.save(), True)
Expand Down

0 comments on commit f127314

Please sign in to comment.