Skip to content

Commit

Permalink
issue #182
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtepkeev committed Jan 6, 2018
1 parent 1066429 commit 1ad0838
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Changelog

- Support 204 status code when deleting a resource (`Issue #189 <https://github.com/maxtepkeev/python-redmine/
pull/189>`__) (thanks to `dotSlashLu <https://github.com/dotSlashLu>`__)
- Raise ``ValidationError`` instead of not helpful ``TypeError`` exception in case of trying to create a WikiPage
resource that already exists (`Issue #182 <https://github.com/maxtepkeev/python-redmine/issues/182>`__)

2.0.2 (2017-04-19)
++++++++++++++++++
Expand Down
6 changes: 5 additions & 1 deletion redminelib/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def create(self, **fields):
data['attachments'][index]['token'] = self.redmine.upload(attachment.pop('path', ''))

response = self.redmine.engine.request(self.resource_class.http_method_create, url, data=data)
resource = self.to_resource(response[self.container])

try:
resource = self.to_resource(response[self.container])
except TypeError:
raise exceptions.ValidationError('Resource already exists') # fix for repeated PUT requests (issue #182)

self.params = formatter.used_kwargs
self.url = self.redmine.url + self.resource_class.query_one.format(resource.internal_id, **fields)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def test_manager_is_picklable(self):
self.assertEqual(project.url, unpickled_project.url)
self.assertEqual(project.params['foo'], unpickled_project.params['foo'])

def test_create_validation_exception_via_put(self):
self.response.content = ''
self.assertRaises(exceptions.ValidationError, lambda: self.redmine.wiki_page.create(project_id=1, title='Foo'))

def test_reraises_not_found_exception(self):
self.response.status_code = 404
self.assertRaises(exceptions.ResourceNotFoundError, lambda: self.redmine.project.get('non-existent-project'))
Expand Down

0 comments on commit 1ad0838

Please sign in to comment.