Ejemplo n.º 1
0
    def test_register_bad_request(self, mock_render, mock_register_form,
                                  mock_settings):
        mock_request = mock.MagicMock()
        mock_request.method = 'FOO'

        mock_settings.ENABLE_OPEN_SIGNUP = True

        mock_form = mock.MagicMock()

        mock_register_form.return_value = mock_form

        # mock validate the form
        mock_form.is_valid.return_value = True

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_not_called()

        mock_register_form.assert_called_with()

        context = {'form': mock_form}

        # mock redirect after logged in using next parameter or default to user profile
        mock_render.assert_called_once_with(
            mock_request, 'tethys_portal/accounts/register.html', context)
Ejemplo n.º 2
0
 def test_register_not_enable_open_signup(self, mock_redirect, mock_settings):
     mock_request = mock.MagicMock()
     mock_request.user.is_anonymous = True
     mock_request.user.username = '******'
     mock_settings.ENABLE_OPEN_SIGNUP = False
     register(mock_request)
     mock_redirect.assert_called_once_with('accounts:login')
Ejemplo n.º 3
0
 def test_register_not_enable_open_signup(self, mock_redirect,
                                          mock_settings):
     mock_request = mock.MagicMock()
     mock_request.user.is_anonymous = True
     mock_request.user.username = '******'
     mock_settings.ENABLE_OPEN_SIGNUP = False
     register(mock_request)
     mock_redirect.assert_called_once_with('accounts:login')
Ejemplo n.º 4
0
    def test_register_post_request_not_active_user(self, mock_render,
                                                   mock_register_form,
                                                   mock_authenticate,
                                                   mock_login, mock_settings,
                                                   mock_messages):
        mock_request = mock.MagicMock()
        mock_request.method = 'POST'
        mock_request.POST = 'register-submit'
        mock_request.user.is_anonymous = True
        mock_request.user.username = '******'
        mock_request.GET = ''

        mock_settings.ENABLE_OPEN_SIGNUP = True

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

        # mock validate the form
        mock_form.is_valid.return_value = True

        mock_username = mock.MagicMock()
        mock_email = mock.MagicMock()
        mock_password = mock.MagicMock()
        mock_form.clean_username.return_value = mock_username
        mock_form.clean_email.return_value = mock_email
        mock_form.clean_password2.return_value = mock_password

        # mock authenticate
        mock_user = mock.MagicMock()
        mock_authenticate.return_value = mock_user

        # mock the password has been verified for the user
        mock_user.is_active = False

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_called_once()

        mock_register_form.assert_called_with(mock_request.POST)

        # mock authenticate call
        mock_authenticate.asset_called_with(username=mock_username,
                                            password=mock_password)

        # mock the user is valid, active, and authenticated, so login in the user
        mock_login.assert_not_called()

        mock_messages.error.assert_called_once_with(
            mock_request, "Sorry, but your account has been disabled. "
            "Please contact the site "
            "administrator for more details.")

        context = {'form': mock_form}

        # mock redirect after logged in using next parameter or default to user profile
        mock_render.assert_called_once_with(
            mock_request, 'tethys_portal/accounts/register.html', context)
Ejemplo n.º 5
0
    def test_register_post_request_user_none(self, mock_render,
                                             mock_register_form,
                                             mock_authenticate, mock_login,
                                             mock_messages):
        mock_request = mock.MagicMock()
        mock_request.method = 'POST'
        mock_request.POST = 'register-submit'
        mock_request.user.is_anonymous = True
        mock_request.user.username = '******'
        mock_request.GET = ''

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

        # mock validate the form
        mock_form.is_valid.return_value = True

        mock_username = mock.MagicMock()
        mock_email = mock.MagicMock()
        mock_password = mock.MagicMock()
        mock_form.clean_username.return_value = mock_username
        mock_form.clean_email.return_value = mock_email
        mock_form.clean_password2.return_value = mock_password

        # mock authenticate
        mock_user = mock.MagicMock()
        mock_authenticate.return_value = None

        # mock the password has been verified for the user
        mock_user.is_active = False

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_called_once()

        mock_register_form.assert_called_with(mock_request.POST)

        # mock authenticate call
        mock_authenticate.asset_called_with(username=mock_username,
                                            password=mock_password)

        # mock the user is valid, active, and authenticated, so login in the user
        mock_login.assert_not_called()

        mock_messages.warning.assert_called_once_with(
            mock_request, "Whoops! We were not able to log you in. "
            "Please check your username and "
            "password and try again.")

        context = {'form': mock_form}

        # mock redirect after logged in using next parameter or default to user profile
        mock_render.assert_called_once_with(
            mock_request, 'tethys_portal/accounts/register.html', context)
Ejemplo n.º 6
0
    def test_register_post_request_user_none(self, mock_render, mock_register_form, mock_authenticate,
                                             mock_login, mock_settings, mock_messages):
        mock_request = mock.MagicMock()
        mock_request.method = 'POST'
        mock_request.POST = 'register-submit'
        mock_request.user.is_anonymous = True
        mock_request.user.username = '******'
        mock_request.GET = ''

        mock_settings.ENABLE_OPEN_SIGNUP = True

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

        # mock validate the form
        mock_form.is_valid.return_value = True

        mock_username = mock.MagicMock()
        mock_email = mock.MagicMock()
        mock_password = mock.MagicMock()
        mock_form.clean_username.return_value = mock_username
        mock_form.clean_email.return_value = mock_email
        mock_form.clean_password2.return_value = mock_password

        # mock authenticate
        mock_user = mock.MagicMock()
        mock_authenticate.return_value = None

        # mock the password has been verified for the user
        mock_user.is_active = False

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_called_once()

        mock_register_form.assert_called_with(mock_request.POST)

        # mock authenticate call
        mock_authenticate.asset_called_with(username=mock_username, password=mock_password)

        # mock the user is valid, active, and authenticated, so login in the user
        mock_login.assert_not_called()

        mock_messages.warning.assert_called_once_with(mock_request, "Whoops! We were not able to log you in. "
                                                                    "Please check your username and "
                                                                    "password and try again.")

        context = {'form': mock_form}

        # mock redirect after logged in using next parameter or default to user profile
        mock_render.assert_called_once_with(mock_request, 'tethys_portal/accounts/register.html', context)
Ejemplo n.º 7
0
    def test_register_post_request(self, mock_redirect, mock_register_form,
                                   mock_authenticate, mock_login,
                                   mock_settings):
        mock_request = mock.MagicMock()
        mock_request.method = 'POST'
        mock_request.POST = 'register-submit'
        mock_request.user.is_anonymous = True
        mock_request.user.username = '******'
        mock_request.GET = ''

        mock_settings.ENABLE_OPEN_SIGNUP = True

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

        # mock validate the form
        mock_form.is_valid.return_value = True

        mock_username = mock.MagicMock()
        mock_email = mock.MagicMock()
        mock_password = mock.MagicMock()
        mock_form.clean_username.return_value = mock_username
        mock_form.clean_email.return_value = mock_email
        mock_form.clean_password2.return_value = mock_password

        # mock authenticate
        mock_user = mock.MagicMock()
        mock_authenticate.return_value = mock_user

        # mock the password has been verified for the user
        mock_user.is_active = True

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_called_once()

        mock_register_form.assert_called_with(mock_request.POST)

        # mock authenticate call
        mock_authenticate.asset_called_with(username=mock_username,
                                            password=mock_password)

        # mock the user is valid, active, and authenticated, so login in the user
        mock_login.assert_called_with(mock_request, mock_user)

        # mock redirect after logged in using next parameter or default to user profile
        mock_redirect.assert_called_once_with('user:profile',
                                              username=mock_user.username)
Ejemplo n.º 8
0
    def test_register_post_request_next(self, mock_redirect, mock_register_form, mock_authenticate, mock_login,
                                        mock_settings):
        mock_request = mock.MagicMock()
        mock_request.method = 'POST'
        mock_request.POST = 'register-submit'
        mock_request.user.is_anonymous = True
        mock_request.user.username = '******'
        mock_request.GET = {'next': 'foo'}

        mock_settings.ENABLE_OPEN_SIGNUP = True

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

        # mock validate the form
        mock_form.is_valid.return_value = True

        mock_username = mock.MagicMock()
        mock_email = mock.MagicMock()
        mock_password = mock.MagicMock()
        mock_form.clean_username.return_value = mock_username
        mock_form.clean_email.return_value = mock_email
        mock_form.clean_password2.return_value = mock_password

        # mock authenticate
        mock_user = mock.MagicMock()
        mock_authenticate.return_value = mock_user

        # mock the password has been verified for the user
        mock_user.is_active = True

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_called_once()

        mock_register_form.assert_called_with(mock_request.POST)

        # mock authenticate call
        mock_authenticate.asset_called_with(username=mock_username, password=mock_password)

        # mock the user is valid, active, and authenticated, so login in the user
        mock_login.assert_called_with(mock_request, mock_user)

        # mock redirect after logged in using next parameter or default to user profile
        mock_redirect.assert_called_once_with(mock_request.GET['next'])
Ejemplo n.º 9
0
    def test_register_bad_request(self, mock_render, mock_register_form, mock_settings):
        mock_request = mock.MagicMock()
        mock_request.method = 'FOO'

        mock_settings.ENABLE_OPEN_SIGNUP = True

        mock_form = mock.MagicMock()

        mock_register_form.return_value = mock_form

        # mock validate the form
        mock_form.is_valid.return_value = True

        # call the login function with mock args
        register(mock_request)

        mock_form.save.assert_not_called()

        mock_register_form.assert_called_with()

        context = {'form': mock_form}

        # mock redirect after logged in using next parameter or default to user profile
        mock_render.assert_called_once_with(mock_request, 'tethys_portal/accounts/register.html', context)
Ejemplo n.º 10
0
 def test_register_not_anonymous_user(self, mock_redirect):
     mock_request = mock.MagicMock()
     mock_request.user.is_anonymous = False
     mock_request.user.username = '******'
     register(mock_request)
     mock_redirect.assert_called_once_with('user:profile', username='******')
Ejemplo n.º 11
0
 def test_register_not_enable_open_signup(self, mock_redirect):
     mock_request = mock.MagicMock()
     mock_request.user.is_anonymous = True
     mock_request.user.username = '******'
     register(mock_request)
     mock_redirect.assert_called_once_with('accounts:login')
Ejemplo n.º 12
0
 def test_register_not_anonymous_user(self, mock_redirect):
     mock_request = mock.MagicMock()
     mock_request.user.is_anonymous = False
     mock_request.user.username = '******'
     register(mock_request)
     mock_redirect.assert_called_once_with('user:profile', username='******')