-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #956 from eciis/fix-delete-event
Fix delete event
- Loading branch information
Showing
4 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,8 @@ def setUp(cls): | |
cls.event = mocks.create_event(cls.user, cls.institution) | ||
|
||
@patch('utils.verify_token', return_value={'email': '[email protected]'}) | ||
def test_delete(self, verify_token): | ||
"""Test the event_handler's delete method.""" | ||
def test_delete_by_author(self, verify_token): | ||
"""Test the event_handler's delete method when user is author.""" | ||
# Call the delete method | ||
self.testapp.delete("/api/events/%s" % | ||
self.event.key.urlsafe()) | ||
|
@@ -71,6 +71,32 @@ def test_delete(self, verify_token): | |
self.testapp.delete("/api/events/%s" % | ||
self.event.key.urlsafe()) | ||
|
||
@patch('utils.verify_token', return_value={'email': '[email protected]'}) | ||
def test_delete_by_admin(self, verify_token): | ||
"""Test the event_handler's delete method when user is admin.""" | ||
# Call the delete method and assert that it raises an exception, | ||
# because the user doesn't have the permission yet. | ||
with self.assertRaises(Exception) as raises_context: | ||
self.testapp.delete("/api/events/%s" % | ||
self.event.key.urlsafe()) | ||
message = self.get_message_exception(str(raises_context.exception)) | ||
self.assertEquals(message, "Error! The user can not remove this event") | ||
|
||
#Add permission of admin | ||
self.second_user.add_permissions(["remove_posts"], self.event.institution_key.urlsafe()) | ||
|
||
# Call the delete method | ||
self.testapp.delete("/api/events/%s" % | ||
self.event.key.urlsafe()) | ||
# Refresh event | ||
self.event = self.event.key.get() | ||
# Verify if after delete the state of event is deleted | ||
self.assertEqual(self.event.state, "deleted", | ||
"The state expected was deleted.") | ||
# Verify if after delete the last_modified | ||
self.assertEqual(self.event.last_modified_by, self.second_user.key, | ||
"The last_modified_by expected was user.") | ||
|
||
@patch('utils.verify_token', return_value={'email': '[email protected]'}) | ||
def test_patch(self, verify_token): | ||
"""Test the post_handler's patch method.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters