Пример #1
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"]
Пример #2
0
def test_user_get_absolute_url(user: User):
    assert user.get_absolute_url() == f"/users/{user.username}/"