def setUp(self): from lasco.auth import setup_who_api_factory from lasco.app import set_config LascoTestCase.setUp(self) set_config(self.config) self.config.testing_add_renderer('templates/layout.pt') setup_who_api_factory(self.config, None, None, DummyWhoApiFactory)
def make_app(global_settings, **settings): config = Configurator(settings=settings) set_config(config) initialize_sql(settings['lasco.db_string']) setup_who_api_factory( config, global_settings, settings['lasco.auth_config']) return config.make_wsgi_app()
def setUp(self): from lasco.auth import setup_who_api_factory from lasco.models import Picture LascoTestCase.setUp(self) setup_who_api_factory(self.config, None, None, DummyWhoApiFactory) self.add_gallery('g', u'Gallery') self.add_album('g', 'a', u'Album') self.picture = self.session.query(Picture).first()
def setUp(self): from lasco.auth import setup_who_api_factory LascoTestCase.setUp(self) class DummyWhoApi(object): def __init__(self, environ): self.environ = environ def authenticate(self): identity = self.environ.get('repoze.who.identity') if identity is None: return identity return identity.copy() setup_who_api_factory(self.config, None, None, DummyWhoApi)
def test_login_valid_credentials(self): from lasco.auth import setup_who_api_factory from lasco.views.auth import login class AlwaysLogsIn(object): def __init__(self, environ): pass def login(self, credentials): return True, {} setup_who_api_factory(self.config, None, None, AlwaysLogsIn) request = self._make_request(post={'login': u'jsmith', 'password': u'password', 'next': 'http://next'}) response = login(request) self.assertEqual(response.status, '303 See Other') self.assertEqual(response.location, 'http://next')
def test_logout(self): from lasco.auth import setup_who_api_factory from lasco.views.auth import logout headers = {'logout-marker': 'marker'} class DummyWhoApi(object): def __init__(self, environ): pass def logout(self): return headers setup_who_api_factory(self.config, None, None, DummyWhoApi) request = self._make_request() request.application_url = 'http://application.url' response = logout(request) self.assertEqual(response.status, '303 See Other') self.assertEqual(response.location, request.application_url) self.assertEqual(response.headers['logout-marker'], 'marker')
def test_login_try_invalid_credentials(self): from lasco.auth import setup_who_api_factory from lasco.views.auth import login class NeverLogsIn(object): def __init__(self, environ): pass def login(self, credentials): return False, {} def authenticate(self): # required by 'login_form' return None setup_who_api_factory(self.config, None, None, NeverLogsIn) request = self._make_request(post={'login': u'jsmith', 'password': u'password', 'next': 'http://next'}) res = login(request) self.assertEqual(res['error_msg'], u'Wrong user name or password.') self.assertEqual(res['login'], u'jsmith')