@@ -105,6 +105,24 @@ def test_username_password(self):
105105 self .assertLoosely (result )
106106 self .assertCacheWorks (result )
107107
108+ def test_device_flow (self ):
109+ self .app = PublicClientApplication (
110+ CONFIG ["client_id" ], authority = CONFIG ["authority" ])
111+ flow = self .app .initiate_device_flow (scopes = CONFIG .get ("scope" ))
112+ logging .warn (flow ["message" ])
113+
114+ duration = 30
115+ logging .warn ("We will wait up to %d seconds for you to sign in" % duration )
116+ flow ["expires_at" ] = time .time () + duration # Shorten the time for quick test
117+ result = self .app .acquire_token_by_device_flow (flow )
118+ self .assertLoosely (
119+ result ,
120+ assertion = lambda : self .assertIn ('access_token' , result ),
121+ skippable_errors = self .app .client .DEVICE_FLOW_RETRIABLE_ERRORS )
122+
123+ if "access_token" in result :
124+ self .assertCacheWorks (result )
125+
108126
109127@unittest .skipUnless ("client_id" in CONFIG , "client_id missing" )
110128class TestClientApplication (Oauth2TestCase ):
@@ -136,19 +154,3 @@ def test_auth_code(self):
136154 error_description = result .get ("error_description" )))
137155 self .assertCacheWorks (result )
138156
139- def test_device_flow (self ):
140- flow = self .app .initiate_device_flow (scopes = CONFIG .get ("scope" ))
141- logging .warn (flow ["message" ])
142-
143- duration = 30
144- logging .warn ("We will wait up to %d seconds for you to sign in" % duration )
145- flow ["expires_at" ] = time .time () + duration # Shorten the time for quick test
146- result = self .app .acquire_token_by_device_flow (flow )
147- self .assertLoosely (
148- result ,
149- assertion = lambda : self .assertIn ('access_token' , result ),
150- skippable_errors = self .app .client .DEVICE_FLOW_RETRIABLE_ERRORS )
151-
152- if "access_token" in result :
153- self .assertCacheWorks (result )
154-
0 commit comments