Skip to content

Commit 74409bf

Browse files
authored
chore: add missing stateless provider tests (#531)
add missing stateless provider tests Signed-off-by: gruebel <anton.gruebel@gmail.com>
1 parent 837fef9 commit 74409bf

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

tests/test_client.py

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import time
3+
import types
34
import uuid
45
from concurrent.futures import ThreadPoolExecutor
56
from unittest.mock import MagicMock
@@ -242,7 +243,7 @@ def test_should_call_api_level_hooks(no_op_provider_client):
242243
api_hook.after.assert_called_once()
243244

244245

245-
# Requirement 1.7.5
246+
# Requirement 1.7.1, Requirement 1.7.3
246247
def test_should_define_a_provider_status_accessor(no_op_provider_client):
247248
# When
248249
status = no_op_provider_client.get_provider_status()
@@ -251,7 +252,23 @@ def test_should_define_a_provider_status_accessor(no_op_provider_client):
251252
assert status == ProviderStatus.READY
252253

253254

254-
# Requirement 1.7.6
255+
# Requirement 1.7.4
256+
def test_provider_should_return_error_status_if_failed():
257+
# Given
258+
provider = NoOpProvider()
259+
set_provider(provider)
260+
client = get_client()
261+
262+
provider.emit_provider_error(ProviderEventDetails(error_code=ErrorCode.GENERAL))
263+
264+
# When
265+
status = client.get_provider_status()
266+
267+
# Then
268+
assert status == ProviderStatus.ERROR
269+
270+
271+
# Requirement 1.7.6, Requirement 1.7.8
255272
@pytest.mark.asyncio
256273
async def test_should_shortcircuit_if_provider_is_not_ready(
257274
no_op_provider_client, monkeypatch
@@ -281,7 +298,7 @@ async def test_should_shortcircuit_if_provider_is_not_ready(
281298
spy_hook.finally_after.assert_called_once()
282299

283300

284-
# Requirement 1.7.7
301+
# Requirement 1.7.5, Requirement 1.7.7
285302
@pytest.mark.asyncio
286303
async def test_should_shortcircuit_if_provider_is_in_irrecoverable_error_state(
287304
no_op_provider_client, monkeypatch
@@ -311,6 +328,27 @@ async def test_should_shortcircuit_if_provider_is_in_irrecoverable_error_state(
311328
spy_hook.finally_after.assert_called_once()
312329

313330

331+
# Requirement 1.7.9
332+
def test_provider_should_return_not_ready_status_after_shutdown(monkeypatch):
333+
# Given
334+
provider = NoOpProvider()
335+
set_provider(provider)
336+
client = get_client()
337+
338+
def _shutdown(self) -> None:
339+
self._status = ProviderStatus.NOT_READY
340+
341+
monkeypatch.setattr(provider, "shutdown", types.MethodType(_shutdown, provider))
342+
343+
# When
344+
api.shutdown()
345+
346+
status = client.get_provider_status()
347+
348+
# Then
349+
assert status == ProviderStatus.NOT_READY
350+
351+
314352
@pytest.mark.asyncio
315353
async def test_should_run_error_hooks_if_provider_returns_resolution_with_error_code():
316354
# Given
@@ -482,6 +520,34 @@ def test_provider_event_late_binding():
482520
spy.provider_configuration_changed.assert_called_once_with(details)
483521

484522

523+
# Requirement 5.1.4, Requirement 5.1.5
524+
def test_provider_event_handler_exception():
525+
# Given
526+
provider = NoOpProvider()
527+
set_provider(provider)
528+
529+
spy = MagicMock()
530+
531+
client = get_client()
532+
client.add_handler(ProviderEvent.PROVIDER_ERROR, spy.provider_error)
533+
534+
# When
535+
provider.emit_provider_error(
536+
ProviderEventDetails(error_code=ErrorCode.GENERAL, message="some_error")
537+
)
538+
539+
# Then
540+
spy.provider_error.assert_called_once_with(
541+
EventDetails(
542+
flags_changed=None,
543+
message="some_error",
544+
error_code=ErrorCode.GENERAL,
545+
metadata={},
546+
provider_name="No-op Provider",
547+
)
548+
)
549+
550+
485551
def test_client_handlers_thread_safety():
486552
provider = NoOpProvider()
487553
set_provider(provider)

0 commit comments

Comments
 (0)