def test_invalid_import(self): """ If the setting isn't a proper string, raise ImproperlyConfigured. """ with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_missing_attribute(self): """ If the module is imported, but the function isn't found, raise ImproperlyConfigured. """ with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_error_importing(self): """ If there is an error importing the module, raise ImproperlyConfigured. """ with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_error_importing(self): """ If there is an error importing the module, raise ImproperlyConfigured. """ with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_invalid_import(self): """ If the setting isn't a proper string, raise ImproperlyConfigured. """ with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_missing_attribute(self): """ If the module is imported, but the function isn't found, raise ImproperlyConfigured. """ with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_missing_attribute(self, import_module): """ If the module is imported, but the function isn't found, raise ImproperlyConfigured. """ import_module.return_value = Mock(spec=[]) with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_missing_attribute(self, import_module): """ If the module is imported, but the function isn't found, raise ImproperlyConfigured. """ import_module.return_value = Mock(spec=[]) with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING')
def test_error_importing(self, import_module): """ If there is an error importing the module, raise ImproperlyConfigured. """ import_module.side_effect = ImportError with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING') import_module.assert_called_with('foo.bar')
def test_error_importing(self, import_module): """ If there is an error importing the module, raise ImproperlyConfigured. """ import_module.side_effect = ImportError with self.assertRaises(ImproperlyConfigured): import_from_setting('TEST_SETTING') import_module.assert_called_with('foo.bar')
def authenticate(self, assertion=None, audience=None, request=None, **kwargs): """ Authenticate a user by verifying a BrowserID assertion. Defers to the verifier returned by :func:`BrowserIDBackend.get_verifier` for verification. You may either pass the ``request`` parameter to determine the audience from the request, or pass the ``audience`` parameter explicitly. :param assertion: Assertion submitted by the user. This asserts that the user controls a specific email address. :param audience: The audience to use when verifying the assertion; this prevents another site using an assertion for their site to login to yours. This value takes precedence over the audience pulled from the request parameter, if given. :param request: The request that generated this authentication attempt. This is used to determine the audience to use during verification, using the :func:`django_browserid.base.get_audience` function. If the audience parameter is also passed, it will be used instead of the audience from the request. :param kwargs: All remaining keyword arguments are passed to the ``verify`` function on the verifier. """ email = self.verify(assertion, audience, request, **kwargs) if not email or not self.is_valid_email(email): return None # In the rare case that two user accounts have the same email address, # log and bail. Randomly selecting one seems really wrong. users = self.filter_users_by_email(email=email) if len(users) > 1: logger.warn('%s users with email address %s.', len(users), email) return None if len(users) == 1: return users[0] create_user = getattr(settings, 'BROWSERID_CREATE_USER', True) if not create_user: logger.debug('Login failed: No user with email %s found, and ' 'BROWSERID_CREATE_USER is False', email) return None else: if create_user is True: create_function = self.create_user else: # Find the function to call. create_function = import_from_setting('BROWSERID_CREATE_USER') user = create_function(email) user_created.send(create_function, user=user) return user
def test_existing_attribute(self, import_module): """ If the module is imported and has the requested function, return it. """ module = Mock(spec=['baz']) import_module.return_value = module self.assertEqual(import_from_setting('TEST_SETTING'), module.baz)
def test_existing_attribute(self, import_module): """ If the module is imported and has the requested function, return it. """ module = Mock(spec=['baz']) import_module.return_value = module self.assertEqual(import_from_setting('TEST_SETTING'), module.baz)
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import logging from django.conf.urls import patterns, url from django.core.exceptions import ImproperlyConfigured from django_browserid import views from django_browserid.util import import_from_setting logger = logging.getLogger(__name__) try: Verify = import_from_setting('BROWSERID_VERIFY_CLASS') logger.debug('django_browserid using custom Verify view ' + '.'.join([Verify.__module__, Verify.__name__])) except ImproperlyConfigured as e: logger.debug('django_browserid using default Verify view.') Verify = views.Verify urlpatterns = patterns('', url(r'^browserid/login/$', Verify.as_view(), name='browserid.login'), url(r'^browserid/logout/$', views.Logout.as_view(), name='browserid.logout'), url(r'^browserid/csrf/$', views.CsrfToken.as_view(), name='browserid.csrf'), )
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import logging from django.conf import settings try: from django.conf.urls import patterns, url except ImportError: from django.conf.urls.defaults import patterns, url from django.contrib.auth.views import logout from django.core.exceptions import ImproperlyConfigured from django_browserid.util import import_from_setting logger = logging.getLogger(__name__) try: Verify = import_from_setting('BROWSERID_VERIFY_CLASS') except ImproperlyConfigured as e: logger.info('Loading BROWSERID_VERIFY_CLASS failed: {0}.\nFalling back to ' 'default.'.format(e)) from django_browserid.views import Verify urlpatterns = patterns( '', url(r'^login/', Verify.as_view(), name='browserid_login'), url(r'^logout/', logout, {'next_page': getattr(settings, 'LOGOUT_REDIRECT_URL', '/')}, name='browserid_logout'))
def test_no_setting(self): """If the setting doesn't exist, raise ImproperlyConfigured.""" with self.assertRaises(ImproperlyConfigured): import_from_setting('DOES_NOT_EXIST')
def test_no_setting(self): """If the setting doesn't exist, raise ImproperlyConfigured.""" with self.assertRaises(ImproperlyConfigured): import_from_setting('DOES_NOT_EXIST')
def test_existing_attribute(self): """ If the module is imported and has the requested function, return it. """ self.assertEqual(import_from_setting('TEST_SETTING'), 1)
def test_existing_attribute(self): """ If the module is imported and has the requested function, return it. """ self.assertEqual(import_from_setting('TEST_SETTING'), 1)