11"""HTTPClient test module."""
2+ from requests_kerberos import HTTPKerberosAuth , OPTIONAL
23import pytest
34import unittest .mock as mock
45
6+ from splitio .client .config import AuthenticateScheme
57from splitio .api import client
68from splitio .engine .telemetry import TelemetryStorageProducer , TelemetryStorageProducerAsync
79from splitio .storage .inmemmory import InMemoryTelemetryStorage , InMemoryTelemetryStorageAsync
@@ -25,7 +27,8 @@ def test_get(self, mocker):
2527 client .SDK_URL + '/test1' ,
2628 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
2729 params = {'param1' : 123 },
28- timeout = None
30+ timeout = None ,
31+ auth = None
2932 )
3033 assert response .status_code == 200
3134 assert response .body == 'ok'
@@ -37,7 +40,8 @@ def test_get(self, mocker):
3740 client .EVENTS_URL + '/test1' ,
3841 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
3942 params = {'param1' : 123 },
40- timeout = None
43+ timeout = None ,
44+ auth = None
4145 )
4246 assert get_mock .mock_calls == [call ]
4347 assert response .status_code == 200
@@ -59,7 +63,8 @@ def test_get_custom_urls(self, mocker):
5963 'https://sdk.com/test1' ,
6064 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
6165 params = {'param1' : 123 },
62- timeout = None
66+ timeout = None ,
67+ auth = None
6368 )
6469 assert get_mock .mock_calls == [call ]
6570 assert response .status_code == 200
@@ -71,7 +76,8 @@ def test_get_custom_urls(self, mocker):
7176 'https://events.com/test1' ,
7277 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
7378 params = {'param1' : 123 },
74- timeout = None
79+ timeout = None ,
80+ auth = None
7581 )
7682 assert response .status_code == 200
7783 assert response .body == 'ok'
@@ -95,7 +101,8 @@ def test_post(self, mocker):
95101 json = {'p1' : 'a' },
96102 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
97103 params = {'param1' : 123 },
98- timeout = None
104+ timeout = None ,
105+ auth = None
99106 )
100107 assert response .status_code == 200
101108 assert response .body == 'ok'
@@ -108,7 +115,8 @@ def test_post(self, mocker):
108115 json = {'p1' : 'a' },
109116 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
110117 params = {'param1' : 123 },
111- timeout = None
118+ timeout = None ,
119+ auth = None
112120 )
113121 assert response .status_code == 200
114122 assert response .body == 'ok'
@@ -131,7 +139,8 @@ def test_post_custom_urls(self, mocker):
131139 json = {'p1' : 'a' },
132140 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
133141 params = {'param1' : 123 },
134- timeout = None
142+ timeout = None ,
143+ auth = None
135144 )
136145 assert response .status_code == 200
137146 assert response .body == 'ok'
@@ -144,12 +153,35 @@ def test_post_custom_urls(self, mocker):
144153 json = {'p1' : 'a' },
145154 headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
146155 params = {'param1' : 123 },
147- timeout = None
156+ timeout = None ,
157+ auth = None
148158 )
149159 assert response .status_code == 200
150160 assert response .body == 'ok'
151161 assert get_mock .mock_calls == [call ]
152162
163+ def test_authentication_scheme (self , mocker ):
164+ response_mock = mocker .Mock ()
165+ response_mock .status_code = 200
166+ response_mock .text = 'ok'
167+ get_mock = mocker .Mock ()
168+ get_mock .return_value = response_mock
169+ mocker .patch ('splitio.api.client.requests.get' , new = get_mock )
170+ httpclient = client .HttpClient (sdk_url = 'https://sdk.com' , authentication_scheme = AuthenticateScheme .KERBEROS )
171+ httpclient .set_telemetry_data ("metric" , mocker .Mock ())
172+ response = httpclient .get ('sdk' , '/test1' , 'some_api_key' , {'param1' : 123 }, {'h1' : 'abc' })
173+ call = mocker .call (
174+ 'https://sdk.com/test1' ,
175+ headers = {'Authorization' : 'Bearer some_api_key' , 'h1' : 'abc' , 'Content-Type' : 'application/json' },
176+ params = {'param1' : 123 },
177+ timeout = None ,
178+ auth = HTTPKerberosAuth (mutual_authentication = OPTIONAL )
179+ )
180+
181+ httpclient = client .HttpClient (sdk_url = 'https://sdk.com' , authentication_scheme = AuthenticateScheme .KERBEROS , authentication_params = ['bilal' , 'split' ])
182+ httpclient .set_telemetry_data ("metric" , mocker .Mock ())
183+ response = httpclient .get ('sdk' , '/test1' , 'some_api_key' , {'param1' : 123 }, {'h1' : 'abc' })
184+
153185 def test_telemetry (self , mocker ):
154186 telemetry_storage = InMemoryTelemetryStorage ()
155187 telemetry_producer = TelemetryStorageProducer (telemetry_storage )
0 commit comments