1212from oauth2cli .oauth2 import Client
1313from oauth2cli .authcode import obtain_auth_code
1414from oauth2cli .assertion import JwtSigner
15- from tests import unittest
15+ from tests import unittest , Oauth2TestCase
1616
1717
18+ logging .basicConfig (level = logging .DEBUG )
19+ logger = logging .getLogger (__file__ )
20+
1821CONFIG_FILENAME = "config.json"
1922
2023def load_conf (filename ):
@@ -46,7 +49,7 @@ def load_conf(filename):
4649 with open (filename ) as f :
4750 conf = json .load (f )
4851 except :
49- logging .warn ("Unable to open/read JSON configuration %s" % filename )
52+ logger .warn ("Unable to open/read JSON configuration %s" % filename )
5053 raise
5154 openid_configuration = {}
5255 try :
@@ -56,7 +59,7 @@ def load_conf(filename):
5659 discovery_uri = conf ["oidp" ] + '/.well-known/openid-configuration'
5760 openid_configuration .update (requests .get (discovery_uri ).json ())
5861 except :
59- logging .warn ("openid-configuration uri not accesible: %s" , discovery_uri )
62+ logger .warn ("openid-configuration uri not accesible: %s" , discovery_uri )
6063 openid_configuration .update (conf .get ("openid_configuration" , {}))
6164 if openid_configuration .get ("device_authorization_endpoint" ):
6265 # The following urljoin(..., ...) trick allows a "path_name" shorthand
@@ -69,21 +72,6 @@ def load_conf(filename):
6972THIS_FOLDER = os .path .dirname (__file__ )
7073CONFIG = load_conf (os .path .join (THIS_FOLDER , CONFIG_FILENAME )) or {}
7174
72- logging .basicConfig (level = logging .DEBUG )
73-
74-
75- class Oauth2TestCase (unittest .TestCase ):
76-
77- def assertLoosely (self , response , assertion = None ,
78- skippable_errors = ("invalid_grant" , "interaction_required" )):
79- if response .get ("error" ) in skippable_errors :
80- # Some of these errors are configuration issues, not library issues
81- raise unittest .SkipTest (response .get ("error_description" ))
82- else :
83- if assertion is None :
84- assertion = lambda : self .assertIn ("access_token" , response )
85- assertion ()
86-
8775
8876# Since the OAuth2 specs uses snake_case, this test config also uses snake_case
8977@unittest .skipUnless ("client_id" in CONFIG , "client_id missing" )
@@ -156,10 +144,10 @@ def test_device_flow(self):
156144 "enter the code {user_code} to authenticate." .format (** flow ))
157145 except KeyError : # Some IdP might not be standard compliant
158146 msg = flow ["message" ] # Not a standard parameter though
159- logging .warn (msg ) # We avoid print(...) b/c its output would be buffered
147+ logger .warn (msg ) # We avoid print(...) b/c its output would be buffered
160148
161149 duration = 30
162- logging .warn ("We will wait up to %d seconds for you to sign in" % duration )
150+ logger .warn ("We will wait up to %d seconds for you to sign in" % duration )
163151 result = self .client .obtain_token_by_device_flow (
164152 flow ,
165153 exit_condition = lambda end = time .time () + duration : time .time () > end )
0 commit comments