Beispiel #1
0
    def test_user_normal(self):
        reminder = Photo(creator=self.user)
        reminder.save()

        self.validate_response(
            self.endpoint,
            headers=self.auth_headers,
            expected_response_payload=[
                {
                    "created_at":
                    reminder.created_at.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
                    "creator":
                    self.user.pk,
                    "description":
                    reminder.description,
                    "id":
                    reminder.pk,
                    "location":
                    reminder.location,
                    "notified_at":
                    reminder.notified_at,
                    "notify_at":
                    reminder.notify_at,
                    "participants": [],
                    "status":
                    ReminderStatus.CREATED.name,
                    "title":
                    reminder.title,
                },
            ],
        )
Beispiel #2
0
    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)
Beispiel #3
0
    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)
Beispiel #4
0
    def test_patch_normal_title(self):
        rem = Photo(creator=self.user, title="xxx")
        rem.save()

        self.validate_response(
            f"{self.endpoint}{rem.pk}/",
            method="patch",
            headers=self.auth_headers,
            data={
                "title": "yyy",
            },
            expected_status_code=status.HTTP_200_OK,
        )

        reminders = Reminder.objects.filter(title="yyy")
        self.assertEqual(1, reminders.count())

        reminder = reminders.first()
        self.assertTrue(reminder)

        self.assertEqual("yyy", reminder.title)
        self.assertEqual(rem.creator, reminder.creator)
        self.assertListEqual(list(rem.participants.all()),
                             list(reminder.participants.all()))
        self.assertEqual(rem.pk, reminder.pk)
Beispiel #5
0
    def test_patch_anon(self):
        reminder = Photo(creator=self.user)
        reminder.save()

        self.validate_response(
            f"{self.endpoint}{reminder.pk}/",
            method="patch",
            expected_status_code=status.HTTP_401_UNAUTHORIZED,
        )
Beispiel #6
0
    def setUp(self) -> None:
        self.endpoint = "/api/v1/photo/"
        self.user = self.create_user()
        self.token = self.create_auth_token(self.user)
        self.auth_headers = {"HTTP_AUTHORIZATION": f"Token {self.token}"}

        self.user2 = self.create_user()
        self.reminder2 = Photo(creator=self.user2)
        self.reminder2.save()
Beispiel #7
0
    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()