<s> from django . test import TestCase <EOL> from django . db import connections <EOL> from salesforce . testrunner . example . models import User <EOL> from requests . exceptions import ConnectionError <EOL> class DynamicAuthTest ( TestCase ) : <EOL> def assertConnectionProblem ( self , queryset ) : <EOL> with self . assertRaises ( Exception ) as cm : <EOL> len ( queryset ) <EOL> exc = cm . exception <EOL> self . assertTrue ( isinstance ( exc , ( ConnectionError , LookupError , KeyError ) ) ) <EOL> def test_dynamic_auth ( self ) : <EOL> """<STR_LIT>""" <EOL> users = User . objects . all ( ) [ : <NUM_LIT:2> ] <EOL> with connections [ '<STR_LIT>' ] . cursor ( ) as cursor : <EOL> access_token = cursor . oauth [ '<STR_LIT>' ] <EOL> instance_url = cursor . oauth [ '<STR_LIT>' ] <EOL> self . assertConnectionProblem ( users ) <EOL> connections [ '<STR_LIT>' ] . sf_session . auth . dynamic_start ( access_token , instance_url = instance_url ) <EOL> self . assertGreater ( len ( users ) , <NUM_LIT:0> ) <EOL> connections [ '<STR_LIT>' ] . sf_session . auth . dynamic_end ( ) <EOL> users = User . objects . all ( ) [ : <NUM_LIT:2> ] <EOL> self . assertConnectionProblem ( users ) </s>
