Пример #1
0
    def test_get_user(self):
        user = self.create_user()
        rem = Reminder(creator=user, title=f"title_{user.username}")
        rem.save()

        client = Client()
        client.login(username=user.username, password=user.username)

        self.validate_response(
            client=client,
            url=rem.get_absolute_url(),
            expected_view_name="reminders:reminder",
            expected_view=ReminderView,
            expected_template="reminders/reminder.html",
            content_filters=(
                lambda _c: f"title_{user.username}".encode() in _c, ),
        )
Пример #2
0
    def test_get_anonymous(self):
        user = self.create_user()
        rem = Reminder(creator=user, title=f"title_{user.username}")
        rem.save()

        self.validate_response(
            url=f"/r/{rem.pk * 999}/",
            expected_status_code=404,
            content_filters=(lambda _c: b"Not Found" in _c, ),
        )

        self.validate_response(
            url=rem.get_absolute_url(),
            expected_status_code=200,
            expected_view=ReminderView,
            expected_view_name="reminders:reminder",
            expected_template="reminders/reminder.html",
            content_filters=(lambda _c: b"Feel free to register" in _c, ),
        )
Пример #3
0
    def test_post_user(self):
        user = self.create_user()
        client = Client()
        client.login(username=user.username, password=user.username)

        rem = Reminder(creator=user, title=user.username)
        rem.save()

        created_at = rem.created_at
        dtm = utcnow() + timedelta(days=1)

        self.validate_response(
            client=client,
            method="post",
            url=f"{rem.get_absolute_url()}update/",
            form_data={
                "created_at": dtm,
                "status": ReminderStatus.NOTIFIED,
                "title": f"title_{user.username}",
                "participants": [
                    user.pk,
                ],
            },
            expected_view_name="reminders:reminder",
            expected_view=ReminderView,
            expected_redirect_chain=[(rem.get_absolute_url(), 302)],
            expected_template="reminders/reminder.html",
            content_filters=(
                lambda _c: b"error" not in _c,
                lambda _c: f"title_{user.username}".encode() in _c,
                lambda _c: ReminderStatus.NOTIFIED.value.encode() not in _c,
            ),
        )

        rem.refresh_from_db()

        self.assertEqual(rem.title, f"title_{user.username}")
        self.assertEqual(rem.status, ReminderStatus.CREATED.name)
        self.assertEqual(rem.created_at, created_at)
        self.assertNotEqual(rem.created_at, dtm)
Пример #4
0
    def test_post_user(self):
        user = self.create_user()
        client = Client()
        client.login(username=user.username, password=user.username)
        reminder = Reminder(creator=user, title=user.username)
        reminder.save()

        view_url = f"{reminder.get_absolute_url()}done/"

        self.validate_response(
            client=client,
            method="post",
            url=view_url,
            expected_view_name="reminders:reminder",
            expected_view=ReminderView,
            expected_redirect_chain=[(reminder.get_absolute_url(), 301)],
            expected_template="reminders/reminder.html",
            content_filters=(lambda _c: b"error" not in _c, ),
        )

        reminder.refresh_from_db()

        self.assertEqual(reminder.status, ReminderStatus.DONE.name)