def test_get_object(self, user: settings.AUTH_USER_MODEL,
                     request_factory: RequestFactory):
     view = UserUpdateView()
     request = request_factory.get("/fake-url/")
     request.user = user
     view.request = request
     assert view.get_object() == user
Esempio n. 2
0
    def test_get_success_url(self, user, request_factory):
        view = UserUpdateView()
        request = request_factory.get("/fake-url/")
        request.user = user
        view.request = request

        assert view.get_success_url() == f"/users/dashboard/"
Esempio n. 3
0
    def test_get_object(self, user: User, rf: RequestFactory):
        view = UserUpdateView()
        request = rf.get("/fake-url/")
        request.user = user

        view.request = request

        assert view.get_object() == user
Esempio n. 4
0
    def test_get_success_url(self, user: User, rf: RequestFactory):
        view = UserUpdateView()
        request = rf.get("/fake-url/")
        request.user = user

        view.request = request

        assert view.get_success_url() == f"/users/{user.username}/"
Esempio n. 5
0
    def test_get_success_url(self, user: settings.AUTH_USER_MODEL,
                             request_factory: RequestFactory):
        view = UserUpdateView()
        request = request_factory.get("/fake-url/")
        request.user = user

        view.request = request

        assert view.get_success_url() == f"/users/dashboard/"
Esempio n. 6
0
def test__user_update_view__get_object(user):
    """Tests the get_object method of UserUpdateView."""
    # Create view and request for testing
    request = RequestFactory()
    request.user = user
    view = UserUpdateView()
    view.request = request

    assert view.get_object() == user
Esempio n. 7
0
def test__user_update_view__get_success_url(user):
    """Tests the get_success_url method of UserUpdateView."""
    # Create view and request for testing
    request = RequestFactory()
    request.user = user
    view = UserUpdateView()
    view.request = request

    assert view.get_success_url() == f'/users/{user.username}/'
 def setUp(self):
     # call BaseUserTestCase.setUp()
     super(TestUserUpdateView, self).setUp()
     # Instantiate the view directly. Never do this outside a test!
     self.view = UserUpdateView()
     # Generate a fake request
     request = self.factory.get('/fake-url')
     # Attach the user to the request
     request.user = self.user
     # Attach the request to the view
     self.view.request = request
Esempio n. 9
0
    def test_form_valid(self, user: User, rf: RequestFactory):
        view = UserUpdateView()
        request = rf.get("/fake-url/")

        # Add the session/message middleware to the request
        SessionMiddleware().process_request(request)
        MessageMiddleware().process_request(request)
        request.user = user

        view.request = request

        # Initialize the form
        form = UserChangeForm()
        form.cleaned_data = []
        view.form_valid(form)

        messages_sent = [m.message for m in messages.get_messages(request)]
        assert messages_sent == ["Information successfully updated"]
Esempio n. 10
0
 def setUp(self):
     super(TestUserUpdateView, self).setUp()
     self.view = UserUpdateView()
     request = self.factory.get('/fake-url')
     request.user = self.user
     self.view.request = request