Exemplo n.º 1
0
    def test_change_password_post(self, mock_redirect, mock_upf):
        username = '******'

        mock_user = mock.MagicMock()
        mock_user.username = '******'

        mock_request = mock.MagicMock()
        mock_request.user = mock_user

        mock_request.method = 'POST'
        mock_request.POST = 'change-password-submit'

        mock_form = mock.MagicMock()
        mock_form.is_valid.return_value = True
        mock_upf.return_value = mock_form

        change_password(mock_request, username)

        mock_redirect.assert_called_once_with('user:settings', username='******')

        mock_form.clean_old_password.assert_called()

        mock_form.clean_new_password2.assert_called()

        mock_form.save.assert_called()

        mock_upf.assert_called_once_with(user=mock_request.user, data=mock_request.POST)
Exemplo n.º 2
0
    def test_change_password(self, mock_redirect, mock_message_warn):
        mock_request = mock.MagicMock()
        username = '******'
        mock_user = mock.MagicMock()
        mock_user.username = '******'
        mock_request.user = mock_user

        change_password(mock_request, username)

        mock_message_warn.assert_called_once_with(mock_request, "You are not allowed to change other users' settings.")
        mock_redirect.assert_called_once_with('user:profile', username='******')
Exemplo n.º 3
0
    def test_change_password_get(self, mock_render, mock_upf):
        username = '******'

        mock_request_user = mock.MagicMock()
        mock_request_user.username = '******'

        mock_request = mock.MagicMock()
        mock_request.user = mock_request_user
        mock_request.method = 'GET'

        mock_form = mock.MagicMock()
        mock_upf.return_value = mock_form

        expected_context = {'form': mock_form}

        change_password(mock_request, username)

        mock_upf.assert_called_once_with(user=mock_request_user)

        mock_render.assert_called_once_with(mock_request, 'tethys_portal/user/change_password.html', expected_context)