def test_view_decorators(self):
c = Client()
# Call a view that locks the object
r = c.get(reverse('view-that-locks-object-1'), {
'object_id': self.test_model_instance.id
})
self.assertEqual(r.status_code, 200)
self.assertTrue(self.test_model_instance.is_locked())
# Call another view that locks the object (same session)
r = c.get(reverse('view-that-locks-object-2',
args=[self.test_model_instance.id]))
self.assertEqual(r.status_code, 200)
self.assertTrue(self.test_model_instance.is_locked())
# Call a view that unlocks the object after execution
r = c.get(reverse('view-that-unlocks-object',
args=[self.test_model_instance.id]))
self.assertEqual(r.status_code, 200)
self.assertFalse(self.test_model_instance.is_locked())
评论列表
文章目录