import unittest from waeup.cas.authenticators import ( get_all_authenticators, get_authenticator, filter_auth_opts, Authenticator, DummyAuthenticator, ) class TestHelpers(unittest.TestCase): def test_get_all_authenticators(self): # we can get authenticators via entry points auths = get_all_authenticators() assert 'dummy' in auths assert auths['dummy'] is DummyAuthenticator def test_filter_auth_opts(self): # we can filter auth opts result = filter_auth_opts( dict(auth='foo', auth_bar='baz', auth_baz='blah') ) assert result == ( {'auth': 'foo'}, {'auth_bar': 'baz', 'auth_baz': 'blah'} ) def test_get_authenticator(self): # we can parse a paste.deploy config dict for auth result = get_authenticator({}) assert result == {} result = get_authenticator({'auth': 'dummy'}) assert isinstance(result['auth'], DummyAuthenticator) class AuthenticatorTests(unittest.TestCase): def test_create(self): # we can create Authenticator instances auth = Authenticator() assert isinstance(auth, Authenticator) class DummyAuthenticatorTests(unittest.TestCase): def test_create(self): # we can create DummyAuthenticator instances auth = DummyAuthenticator() assert isinstance(auth, DummyAuthenticator) def test_check_credentials(self): # we can succeed with 'bird'/'bebop'. Others will fail. auth = DummyAuthenticator() result1 = auth.check_credentials('bird', 'bebop') assert result1 == (True, '') result2 = auth.check_credentials('foo', 'bar') assert result2 == (False, 'Invalid username or password.')