|
3 | 3 | from unittest.mock import Mock, patch |
4 | 4 |
|
5 | 5 | import pytest |
6 | | -import requests |
7 | 6 |
|
8 | 7 | from openfeature.contrib.provider.unleash import UnleashProvider |
9 | 8 | from openfeature.evaluation_context import EvaluationContext |
10 | 9 | from openfeature.exception import ( |
11 | | - FlagNotFoundError, |
12 | | - GeneralError, |
13 | 10 | ParseError, |
14 | 11 | TypeMismatchError, |
15 | 12 | ) |
@@ -37,30 +34,6 @@ def test_resolve_boolean_details(): |
37 | 34 | assert flag.reason == Reason.TARGETING_MATCH |
38 | 35 |
|
39 | 36 |
|
40 | | -def test_resolve_boolean_details_error(): |
41 | | - """Test that FlagEvaluator handles errors gracefully.""" |
42 | | - mock_client = Mock() |
43 | | - mock_client.is_enabled.side_effect = requests.exceptions.ConnectionError( |
44 | | - "Connection error" |
45 | | - ) |
46 | | - |
47 | | - with patch( |
48 | | - "openfeature.contrib.provider.unleash.UnleashClient" |
49 | | - ) as mock_unleash_client: |
50 | | - mock_unleash_client.return_value = mock_client |
51 | | - |
52 | | - provider = UnleashProvider( |
53 | | - url="http://localhost:4242", app_name="test-app", api_token="test-token" |
54 | | - ) |
55 | | - provider.initialize() |
56 | | - |
57 | | - with pytest.raises(GeneralError) as exc_info: |
58 | | - provider.resolve_boolean_details("test_flag", True) |
59 | | - assert "Connection error" in str(exc_info.value) |
60 | | - |
61 | | - provider.shutdown() |
62 | | - |
63 | | - |
64 | 37 | @pytest.mark.parametrize( |
65 | 38 | "method_name, payload_value, expected_value, default_value", |
66 | 39 | [ |
@@ -195,66 +168,6 @@ def test_value_conversion_errors( |
195 | 168 | provider.shutdown() |
196 | 169 |
|
197 | 170 |
|
198 | | -@pytest.mark.parametrize( |
199 | | - "method_name, mock_side_effect, default_value, expected_error_message, expected_exception", |
200 | | - [ |
201 | | - ( |
202 | | - "resolve_string_details", |
203 | | - requests.exceptions.HTTPError( |
204 | | - "404 Client Error: Not Found", response=Mock(status_code=404) |
205 | | - ), |
206 | | - "default", |
207 | | - "Flag not found", |
208 | | - "FlagNotFoundError", |
209 | | - ), |
210 | | - ( |
211 | | - "resolve_boolean_details", |
212 | | - requests.exceptions.ConnectionError("Connection error"), |
213 | | - True, |
214 | | - "Connection error", |
215 | | - "GeneralError", |
216 | | - ), |
217 | | - ], |
218 | | -) |
219 | | -def test_general_errors( |
220 | | - method_name, |
221 | | - mock_side_effect, |
222 | | - default_value, |
223 | | - expected_error_message, |
224 | | - expected_exception, |
225 | | -): |
226 | | - """Test that FlagEvaluator handles general errors correctly.""" |
227 | | - mock_client = Mock() |
228 | | - |
229 | | - if method_name == "resolve_boolean_details": |
230 | | - mock_client.is_enabled.side_effect = mock_side_effect |
231 | | - else: |
232 | | - mock_client.get_variant.side_effect = mock_side_effect |
233 | | - |
234 | | - with patch( |
235 | | - "openfeature.contrib.provider.unleash.UnleashClient" |
236 | | - ) as mock_unleash_client: |
237 | | - mock_unleash_client.return_value = mock_client |
238 | | - |
239 | | - provider = UnleashProvider( |
240 | | - url="http://localhost:4242", app_name="test-app", api_token="test-token" |
241 | | - ) |
242 | | - provider.initialize() |
243 | | - |
244 | | - method = getattr(provider, method_name) |
245 | | - |
246 | | - if expected_exception == "FlagNotFoundError": |
247 | | - with pytest.raises(FlagNotFoundError) as exc_info: |
248 | | - method("non_existent_flag", default_value) |
249 | | - assert expected_error_message in str(exc_info.value) |
250 | | - else: |
251 | | - with pytest.raises(GeneralError) as exc_info: |
252 | | - method("test_flag", default_value) |
253 | | - assert expected_error_message in str(exc_info.value) |
254 | | - |
255 | | - provider.shutdown() |
256 | | - |
257 | | - |
258 | 171 | def test_edge_cases(): |
259 | 172 | """Test FlagEvaluator with edge cases and boundary conditions.""" |
260 | 173 | mock_client = Mock() |
@@ -295,47 +208,6 @@ def test_edge_cases(): |
295 | 208 | provider.shutdown() |
296 | 209 |
|
297 | 210 |
|
298 | | -@pytest.mark.parametrize( |
299 | | - "mock_side_effect, expected_error_message", |
300 | | - [ |
301 | | - ( |
302 | | - requests.exceptions.HTTPError( |
303 | | - "429 Too Many Requests", response=Mock(status_code=429) |
304 | | - ), |
305 | | - "HTTP error", |
306 | | - ), |
307 | | - ( |
308 | | - requests.exceptions.Timeout("Request timeout"), |
309 | | - "Unexpected error", |
310 | | - ), |
311 | | - ( |
312 | | - requests.exceptions.SSLError("SSL certificate error"), |
313 | | - "Unexpected error", |
314 | | - ), |
315 | | - ], |
316 | | -) |
317 | | -def test_network_errors(mock_side_effect, expected_error_message): |
318 | | - """Test that FlagEvaluator handles network errors correctly.""" |
319 | | - mock_client = Mock() |
320 | | - mock_client.is_enabled.side_effect = mock_side_effect |
321 | | - |
322 | | - with patch( |
323 | | - "openfeature.contrib.provider.unleash.UnleashClient" |
324 | | - ) as mock_unleash_client: |
325 | | - mock_unleash_client.return_value = mock_client |
326 | | - |
327 | | - provider = UnleashProvider( |
328 | | - url="http://localhost:4242", app_name="test-app", api_token="test-token" |
329 | | - ) |
330 | | - provider.initialize() |
331 | | - |
332 | | - with pytest.raises(GeneralError) as exc_info: |
333 | | - provider.resolve_boolean_details("test_flag", True) |
334 | | - assert expected_error_message in str(exc_info.value) |
335 | | - |
336 | | - provider.shutdown() |
337 | | - |
338 | | - |
339 | 211 | def test_context_without_targeting_key(): |
340 | 212 | """Test that FlagEvaluator works with context without targeting key.""" |
341 | 213 | mock_client = Mock() |
|
0 commit comments