def test_fail_not_handled(self): user = self.create_user('view_bookmark_success') instance = self.create_instance('view_bookmark_success') handlers.library.unregister(BookmarkTestModel) request = self.get_post_request(user, self.get_data(instance)) response = views.bookmark(request) self.assertEqual(response.status_code, 400) self.assertEqual(response.content, views.ERRORS['handler']) handlers.library.register(BookmarkTestModel)
def test_fail_invalid_key(self): user = self.create_user('view_bookmark_success') instance = self.create_instance('view_bookmark_success') data = self.get_data(instance) data['key'] = 'invalid_key' request = self.get_post_request(user, data) response = views.bookmark(request) self.assertEqual(response.status_code, 400) self.assertEqual(response.content, views.ERRORS['key'])
def test_fail_invalid_instance(self): user = self.create_user('view_bookmark_success') instance = self.create_instance('view_bookmark_success') data = self.get_data(instance) data['object_id'] = str(int(data['object_id']) + 1) request = self.get_post_request(user, data) response = views.bookmark(request) self.assertEqual(response.status_code, 400) self.assertEqual(response.content, self.handler.failure_message)
def test_success(self): user = self.create_user('view_bookmark_success') instance = self.create_instance('view_bookmark_success') http_referer = '/bookmark/success/' request = self.get_post_request(user, self.get_data(instance), HTTP_REFERER=http_referer) # adding bookmark response = views.bookmark(request) self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], http_referer) exists = self.backend.exists(user, instance, self.handler.default_key) self.assertTrue(exists) # removing bookmark response = views.bookmark(request) self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], http_referer) exists = self.backend.exists(user, instance, self.handler.default_key) self.assertFalse(exists)
def test_fail_not_authenticated(self): instance = self.create_instance('view_bookmark_success') request = self.get_post_request(None, self.get_data(instance)) response = views.bookmark(request) self.assertEqual(response.status_code, 400) self.assertEqual(response.content, self.handler.failure_message)
def test_fail_invalid_method(self): user = self.create_user('view_bookmark_success') request = self.get_request(user) response = views.bookmark(request) self.assertEqual(response.status_code, 403)