def test_medicine_post_with_patient(self): request = self.factory.post('medicine/edit_medicine/(?P<pk>[0-9]+)/', { 'recipe_name': self.recipe_name, 'composition': self.composition }) request.user = self.patient with self.assertRaises(PermissionDenied): UpdateMedicine.as_view()(request, pk=1)
class TestEdit(TestCase): def setUp(self): self.model = Medicine self.view = UpdateMedicine() def test_get_url_sucess(self): self.assertEqual(self.view.get_success_url(), '/pt-br/medicine/list_all_medicines/') def test_get_url_false(self): self.assertNotEqual(self.view.get_success_url(), 'error')
def test_medicine_post_without_login(self): request = self.factory.post('medicine/edit_medicine/(?P<pk>[0-9]+)/', { 'recipe_name': self.recipe_name, 'composition': self.composition }) request.user = AnonymousUser() response = UpdateMedicine.as_view()(request, pk=1) self.assertEqual(response.status_code, 302)
def test_medicine_post_with_health_professional(self): request = self.factory.post('medicine/edit_medicine/(?P<pk>[0-9]+)/', { 'recipe_name': self.recipe_name, 'composition': self.composition }) request.user = self.health_professional response = UpdateMedicine.as_view()(request, pk=1) self.assertEqual(response.status_code, 200)
def test_medicine_get_with_health_professional(self): request = self.factory.get('medicine/edit_medicine/(?P<pk>[0-9]+)/') request.user = self.health_professional response = UpdateMedicine.as_view()(request, pk=1) self.assertEqual(response.status_code, 200)
def test_medicine_get_with_patient(self): request = self.factory.get('medicine/edit_medicine/(?P<pk>[0-9]+)/') request.user = self.patient with self.assertRaises(PermissionDenied): UpdateMedicine.as_view()(request, pk=1)
def test_medicine_get_without_login(self): request = self.factory.get('medicine/edit_medicine/(?P<pk>[0-9]+)/') request.user = AnonymousUser() response = UpdateMedicine.as_view()(request, pk=1) self.assertEqual(response.status_code, 302)
def setUp(self): self.model = Medicine self.view = UpdateMedicine()