def test_patch_status(self): reminder = Photo(creator=self.user) reminder.save() self.validate_response( f"{self.endpoint}{reminder.pk}/", method="patch", headers=self.auth_headers, # data={"status": ReminderStatus.NOTIFIED.name}, expected_status_code=status.HTTP_400_BAD_REQUEST, ) reminder.refresh_from_db() self.assertEqual("CREATED", reminder.status) self.validate_response( f"{self.endpoint}{reminder.pk}/", method="patch", headers=self.auth_headers, # data={"status": ReminderStatus.DONE.name}, expected_status_code=status.HTTP_200_OK, ) reminder.refresh_from_db() self.assertEqual("DONE", reminder.status)
def test_patch_normal_readonly(self): reminder = Photo(creator=self.user) reminder.save() dtm = utcnow() - timedelta(days=1) dataset = { "created_at": dtm, "creator": self.user2.pk, "notified_at": dtm, } old = {_f: getattr(reminder, _f) for _f in dataset} for field, value in dataset.items(): self.validate_response( f"{self.endpoint}{reminder.pk}/", method="patch", headers=self.auth_headers, data={field: value}, expected_status_code=status.HTTP_200_OK, ) reminder.refresh_from_db() for field, expected_value in old.items(): self.assertEqual(expected_value, getattr(reminder, field), field)
def test_delete_normal(self): reminder = Photo(creator=self.user) reminder.save() self.validate_response( f"{self.endpoint}{reminder.pk}/", method="delete", headers=self.auth_headers, expected_status_code=status.HTTP_204_NO_CONTENT, ) with self.assertRaises(Reminder.DoesNotExist): reminder.refresh_from_db()