22from urllib .parse import parse_qsl , urlparse
33
44import pytest
5- import requests
65
76import workos
87from workos .sso import SSO
98from workos .utils .requests import RESPONSE_TYPE_CODE
109
11- class MockResponse (object ):
12- def __init__ (self , response_dict , status_code ):
13- self .response_dict = response_dict
14- self .status_code = status_code
15-
16- def json (self ):
17- return self .response_dict
18-
1910class TestSSO (object ):
2011 @pytest .fixture (autouse = True )
2112 def setup (self , set_api_key_and_project_id ):
@@ -36,24 +27,6 @@ def mock_profile(self):
3627 'idp_id' : '00u1klkowm8EGah2H357'
3728 }
3829
39- @pytest .fixture
40- def mock_request_post_profile (self , monkeypatch , mock_profile ):
41- def mock_post (* args , ** kwargs ):
42- return MockResponse ({
43- 'profile' : {
44- 'object' : 'profile' ,
45- 'id' : mock_profile ['id' ],
46- 'email' : mock_profile ['email' ],
47- 'first_name' : mock_profile ['first_name' ],
48- 'connection_type' : mock_profile ['connection_type' ],
49- 'last_name' : mock_profile ['last_name' ],
50- 'idp_id' : mock_profile ['idp_id' ],
51- },
52- 'access_token' : '01DY34ACQTM3B1CSX1YSZ8Z00D' ,
53- }, 200 )
54-
55- monkeypatch .setattr (requests , 'post' , mock_post )
56-
5730 def test_authorization_url_has_expected_query_params (self ):
5831 authorization_url = self .sso .get_authorization_url (
5932 self .customer_domain ,
@@ -73,8 +46,23 @@ def test_authorization_url_has_expected_query_params(self):
7346
7447
7548 def test_get_profile_returns_expected_workosprofile_object (
76- self , mock_request_post_profile , mock_profile
49+ self , mock_profile , mock_request_method
7750 ):
51+ response_dict = {
52+ 'profile' : {
53+ 'object' : 'profile' ,
54+ 'id' : mock_profile ['id' ],
55+ 'email' : mock_profile ['email' ],
56+ 'first_name' : mock_profile ['first_name' ],
57+ 'connection_type' : mock_profile ['connection_type' ],
58+ 'last_name' : mock_profile ['last_name' ],
59+ 'idp_id' : mock_profile ['idp_id' ],
60+ },
61+ 'access_token' : '01DY34ACQTM3B1CSX1YSZ8Z00D' ,
62+ }
63+
64+ mock_request_method ('post' , response_dict , 200 )
65+
7866 profile = self .sso .get_profile (123 )
7967
8068 assert profile .to_dict () == mock_profile
0 commit comments