44import time
55
66import pytest
7+ import responses
78from cryptojwt .jwk .rsa import import_private_rsa_key_from_file
89from cryptojwt .key_bundle import KeyBundle
910from oidcmsg .oauth2 import AccessTokenRequest
@@ -158,9 +159,8 @@ def test_do_userinfo_request_init(self):
158159 assert _info ['headers' ] == {'Authorization' : 'Bearer access' }
159160 assert _info ['url' ] == 'https://example.com/userinfo'
160161
161- def test_fetch_distributed_claims_1 (self , httpserver ):
162- _url = httpserver .url
163-
162+ def test_fetch_distributed_claims_1 (self ):
163+ _url = "https://example.com/claims.json"
164164 # split the example in 5.6.2.2 into two
165165 uinfo = OpenIDSchema (** {
166166 "sub" : 'jane_doe' ,
@@ -182,7 +182,7 @@ def test_fetch_distributed_claims_1(self, httpserver):
182182 })
183183
184184 # Wrong set of claims. Actually extra claim
185- httpserver . serve_content ( json . dumps ( {
185+ _info = {
186186 "shipping_address" : {
187187 "street_address" : "1234 Hollywood Blvd." ,
188188 "locality" : "Los Angeles" ,
@@ -192,16 +192,20 @@ def test_fetch_distributed_claims_1(self, httpserver):
192192 },
193193 "payment_info" : "Some_Card 1234 5678 9012 3456" ,
194194 "phone_number" : "+1 (310) 123-4567"
195- }))
195+ }
196196
197- res = self .client .fetch_distributed_claims (uinfo )
197+ with responses .RequestsMock () as rsps :
198+ rsps .add ("GET" , _url , body = json .dumps (_info ),
199+ adding_headers = {"Content-Type" : "application/json" }, status = 200 )
200+
201+ res = self .client .fetch_distributed_claims (uinfo )
198202
199203 assert 'payment_info' in res
200204 assert 'shipping_address' in res
201205 assert 'phone_number' not in res
202206
203- def test_fetch_distributed_claims_2 (self , httpserver ):
204- _url = httpserver . url
207+ def test_fetch_distributed_claims_2 (self ):
208+ _url = "https://example.com/claims.json"
205209
206210 uinfo = OpenIDSchema (** {
207211 "sub" : 'jane_doe' ,
@@ -222,16 +226,20 @@ def test_fetch_distributed_claims_2(self, httpserver):
222226 }
223227 })
224228
225- httpserver . serve_content ( json . dumps ( {
229+ _claims = {
226230 "credit_score" : 650
227- }))
231+ }
228232
229- res = self .client .fetch_distributed_claims (uinfo )
233+ with responses .RequestsMock () as rsps :
234+ rsps .add ("GET" , _url , body = json .dumps (_claims ),
235+ adding_headers = {"Content-Type" : "application/json" }, status = 200 )
236+
237+ res = self .client .fetch_distributed_claims (uinfo )
230238
231239 assert 'credit_score' in res
232240
233241 def test_fetch_distributed_claims_3 (self , httpserver ):
234- _url = httpserver . url
242+ _url = "https://example.com/claims.json"
235243
236244 uinfo = OpenIDSchema (** {
237245 "sub" : 'jane_doe' ,
@@ -251,11 +259,13 @@ def test_fetch_distributed_claims_3(self, httpserver):
251259 }
252260 })
253261
254- httpserver .serve_content (json .dumps ({
255- "credit_score" : 650
256- }))
262+ _claims = {"credit_score" : 650 }
263+
264+ with responses .RequestsMock () as rsps :
265+ rsps .add ("GET" , _url , body = json .dumps (_claims ),
266+ adding_headers = {"Content-Type" : "application/json" }, status = 200 )
257267
258- res = self .client .fetch_distributed_claims (
259- uinfo , callback = access_token_callback )
268+ res = self .client .fetch_distributed_claims (
269+ uinfo , callback = access_token_callback )
260270
261271 assert 'credit_score' in res
0 commit comments