<s> from mock import MagicMock , patch <EOL> from jumpgate . common . exceptions import ( Unauthorized , InvalidTokenError ) <EOL> from jumpgate . identity . drivers . sl . tokens import ( NoAuthDriver , SLAuthDriver , <EOL> TokensV2 , FakeTokenIdDriver <EOL> ) <EOL> import unittest <EOL> class TestNoAuthDriver ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . creds = MagicMock ( ) <EOL> self . instance = NoAuthDriver ( ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_authenticate ( self , mockSLClient ) : <EOL> mockAccount = MagicMock ( ) <EOL> mockAccount . getCurrentUser . return_value = '<STR_LIT>' <EOL> mockSLClient . return_value = { '<STR_LIT>' : mockAccount } <EOL> result = self . instance . authenticate ( self . creds ) <EOL> self . assertEquals ( result [ '<STR_LIT:user>' ] , '<STR_LIT>' ) <EOL> class TestFakeTokenIdDriver ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . token_id = MagicMock ( ) <EOL> self . instance = FakeTokenIdDriver ( ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_invalid_auth_driver ( self , mockIdentity ) : <EOL> mockIdentity . auth_driver . return_value = SLAuthDriver ( ) <EOL> with self . assertRaises ( InvalidTokenError ) : <EOL> self . instance . token_from_id ( self . token_id ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_auth_failed ( self , mockIdentity , mockNoAuthDriver ) : <EOL> mockIdentity . auth_driver . return_value = mockNoAuthDriver <EOL> mockNoAuthDriver . authenticate . return_value = None <EOL> with self . assertRaises ( Unauthorized ) : <EOL> self . instance . token_from_id ( self . token_id ) </s>
