@@ -50,10 +50,25 @@ def test_post(self, mock_post):
5050
5151 data = ab .post ('the-url' , data = {'a' : 'b' }, headers = {'c' : 'd' })
5252
53- mock_post .assert_called_with (url = 'the-url' , data = '{"a": "b"}' ,
53+ mock_post .assert_called_with (url = 'the-url' , json = { 'a' : 'b' } ,
5454 headers = {'c' : 'd' , 'Content-Type' : 'application/json' })
5555
5656 self .assertEqual (data , {'x' : 'y' })
57+
58+ @mock .patch ('requests.post' )
59+ def test_post_with_defaults (self , mock_post ):
60+ ab = AuthenticationBase ('auth0.com' , telemetry = False )
61+
62+ mock_post .return_value .status_code = 200
63+ mock_post .return_value .text = '{"x": "y"}'
64+
65+ # Only required params are passed
66+ data = ab .post ('the-url' )
67+
68+ mock_post .assert_called_with (url = 'the-url' , json = None ,
69+ headers = {'Content-Type' : 'application/json' })
70+
71+ self .assertEqual (data , {'x' : 'y' })
5772
5873 @mock .patch ('requests.post' )
5974 def test_post_includes_telemetry (self , mock_post ):
@@ -67,7 +82,7 @@ def test_post_includes_telemetry(self, mock_post):
6782 self .assertEqual (mock_post .call_count , 1 )
6883 call_kwargs = mock_post .call_args [1 ]
6984 self .assertEqual (call_kwargs ['url' ], 'the-url' )
70- self .assertEqual (call_kwargs ['data ' ], '{"a": "b"}' )
85+ self .assertEqual (call_kwargs ['json ' ], { 'a' : 'b' } )
7186 headers = call_kwargs ['headers' ]
7287 self .assertEqual (headers ['c' ], 'd' )
7388 self .assertEqual (headers ['Content-Type' ], 'application/json' )
@@ -157,6 +172,35 @@ def test_post_error_with_no_response_text(self, mock_post):
157172 'a0.sdk.internal.unknown' )
158173 self .assertEqual (context .exception .message , '' )
159174
175+ @mock .patch ('requests.get' )
176+ def test_get (self , mock_get ):
177+ ab = AuthenticationBase ('auth0.com' , telemetry = False )
178+
179+ mock_get .return_value .status_code = 200
180+ mock_get .return_value .text = '{"x": "y"}'
181+
182+ data = ab .get ('the-url' , params = {'a' : 'b' }, headers = {'c' : 'd' })
183+
184+ mock_get .assert_called_with (url = 'the-url' , params = {'a' : 'b' },
185+ headers = {'c' : 'd' , 'Content-Type' : 'application/json' })
186+
187+ self .assertEqual (data , {'x' : 'y' })
188+
189+ @mock .patch ('requests.get' )
190+ def test_get_with_defaults (self , mock_get ):
191+ ab = AuthenticationBase ('auth0.com' , telemetry = False )
192+
193+ mock_get .return_value .status_code = 200
194+ mock_get .return_value .text = '{"x": "y"}'
195+
196+ # Only required params are passed
197+ data = ab .get ('the-url' )
198+
199+ mock_get .assert_called_with (url = 'the-url' , params = None ,
200+ headers = {'Content-Type' : 'application/json' })
201+
202+ self .assertEqual (data , {'x' : 'y' })
203+
160204 @mock .patch ('requests.get' )
161205 def test_get_includes_telemetry (self , mock_get ):
162206 ab = AuthenticationBase ('auth0.com' )
@@ -176,4 +220,4 @@ def test_get_includes_telemetry(self, mock_get):
176220 self .assertIn ('User-Agent' , headers )
177221 self .assertIn ('Auth0-Client' , headers )
178222
179- self .assertEqual (data , ' {"x": "y"}' )
223+ self .assertEqual (data , {"x" : "y" })
0 commit comments