Beispiel #1
0
    def test_update_object(self, user: User, rf: RequestFactory):
        request = rf.post({"name": "Other name"})  # type: ignore
        from django.contrib.messages.storage.fallback import FallbackStorage

        setattr(request, "session", "session")
        messages = FallbackStorage(request)
        setattr(request, "_messages", messages)
        request.user = user
        response = UserUpdateView.as_view()(request)
        assert response.status_code == 302
Beispiel #2
0
    def test_form_valid(self, user: User, request_factory: RequestFactory):
        form_data = {"name": "John Doe"}
        request = request_factory.post(reverse("users:update"), form_data)
        request.user = user
        session_middleware = SessionMiddleware()
        session_middleware.process_request(request)
        msg_middleware = MessageMiddleware()
        msg_middleware.process_request(request)

        response = UserUpdateView.as_view()(request)
        user.refresh_from_db()

        assert response.status_code == 302
        assert user.name == form_data["name"]