<s> from unittest import TestCase <EOL> from thorium import auth , errors <EOL> class SampleAuthenticator ( auth . Authenticator ) : <EOL> def _authenticate ( self ) : <EOL> return self . request <EOL> def _authorize ( self ) : <EOL> return self . request <EOL> @ auth . validation <EOL> def good_auth ( self ) : <EOL> return True <EOL> @ auth . validation <EOL> def bad_auth ( self ) : <EOL> return False <EOL> @ auth . use ( SampleAuthenticator ) <EOL> class SampleTestedClass ( object ) : <EOL> _authenticator_classes = None <EOL> def __init__ ( self ) : <EOL> self . request = True <EOL> self . response = False <EOL> self . auth = self . _authenticator_classes [ <NUM_LIT:0> ] ( self ) <EOL> def method1 ( self ) : <EOL> pass <EOL> @ SampleAuthenticator . no_auth <EOL> def method2 ( self ) : <EOL> pass <EOL> @ SampleAuthenticator . good_auth <EOL> def method3 ( self ) : <EOL> pass <EOL> @ SampleAuthenticator . bad_auth <EOL> def method4 ( self ) : <EOL> pass <EOL> class TestAuth ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . sample = SampleTestedClass ( ) <EOL> def test_bad_auth ( self ) : <EOL> self . sample . auth . request = False <EOL> self . assertRaises ( errors . UnauthorizedError , self . sample . auth . check_auth , self . sample . method1 ) <EOL> def test_no_auth ( self ) : <EOL> self . sample . auth . request = False <EOL> self . sample . auth . check_auth ( self . sample . method2 ) <EOL> def test_custom_auth_method ( self ) : <EOL> self . sample . auth . check_auth ( self . sample . method3 ) <EOL> def test_custom_auth_method_failure ( self ) : <EOL> self . assertRaises ( errors . ForbiddenError , self . sample . auth . check_auth , self . sample . method4 ) </s>
