@@ -15,33 +15,47 @@ def client():
1515 c .oauth_config .shutdown_oauth = False
1616 return c
1717
18- # --- caplog-based tests ---
1918def test_handle_health_status_healthy (client , caplog ):
19+ ## Arrange
2020 client .check_health .return_value = True
21+
22+ ## Act
2123 with caplog .at_level ("WARNING" , logger = "ibind.client.ibkr_client" ):
2224 assert client .handle_health_status () is True
25+
26+ ## Assert
2327 # No warning should be logged
2428 assert not any ("IBKR connection is not healthy" in r .message for r in caplog .records )
2529 client .check_health .assert_called_once ()
2630 client .stop_tickler .assert_not_called ()
2731 client .oauth_init .assert_not_called ()
2832
2933def test_handle_health_status_not_healthy_no_oauth (client , caplog ):
34+ ## Arrange
3035 client .check_health .return_value = False
3136 client ._use_oauth = False
37+
38+ ## Act
3239 with caplog .at_level ("WARNING" , logger = "ibind.client.ibkr_client" ):
3340 assert client .handle_health_status () is False
41+
42+ ## Assert
3443 assert any ("IBKR connection is not healthy. Ensure authentication with the Gateway is re-established." in r .message for r in caplog .records )
3544 client .stop_tickler .assert_not_called ()
3645 client .oauth_init .assert_not_called ()
3746
3847def test_handle_health_status_not_healthy_oauth_success (client , caplog ):
48+ ## Arrange
3949 client .check_health .return_value = False
4050 client ._use_oauth = True
4151 client .stop_tickler .side_effect = None
4252 client .oauth_init .side_effect = None
53+
54+ ## Act
4355 with caplog .at_level ("WARNING" , logger = "ibind.client.ibkr_client" ):
4456 assert client .handle_health_status () is False
57+
58+ ## Assert
4559 assert any ("IBKR connection is not healthy. Attempting to re-establish OAuth authentication." in r .message for r in caplog .records )
4660 client .stop_tickler .assert_called_once_with (15 )
4761 client .oauth_init .assert_called_once_with (maintain_oauth = True , init_brokerage_session = True )
0 commit comments