diff --git a/aikido_zen/background_process/commands/sync_data_test.py b/aikido_zen/background_process/commands/sync_data_test.py index 1f1899ea..ad89f1ff 100644 --- a/aikido_zen/background_process/commands/sync_data_test.py +++ b/aikido_zen/background_process/commands/sync_data_test.py @@ -16,6 +16,7 @@ def setup_connection_manager(): connection_manager.conf.blocked_uids = ["user1", "user2"] connection_manager.conf.last_updated_at = 200 connection_manager.statistics.requests = {"total": 0} # Initialize total requests + connection_manager.middleware_installed = False return connection_manager @@ -38,6 +39,7 @@ def test_process_sync_data_initialization(setup_connection_manager): }, }, "reqs": 10, # Total requests to be added + "middleware_installed": False, } result = process_sync_data(connection_manager, data, None) @@ -63,6 +65,7 @@ def test_process_sync_data_initialization(setup_connection_manager): # Check that the return value is correct assert result["routes"] == dict(connection_manager.routes.routes) assert result["config"] == connection_manager.conf + assert connection_manager.middleware_installed == False def test_process_sync_data_with_last_updated_at_below_zero(setup_connection_manager): @@ -85,6 +88,7 @@ def test_process_sync_data_with_last_updated_at_below_zero(setup_connection_mana }, }, "reqs": 10, # Total requests to be added + "middleware_installed": True, } result = process_sync_data(connection_manager, data, None) @@ -106,7 +110,7 @@ def test_process_sync_data_with_last_updated_at_below_zero(setup_connection_mana # Check that the total requests were updated assert connection_manager.statistics.requests["total"] == 10 - + assert connection_manager.middleware_installed == True # Check that the return value is correct assert result == {} @@ -154,6 +158,7 @@ def test_process_sync_data_existing_route(setup_connection_manager): # Check that the total requests were updated assert connection_manager.statistics.requests["total"] == 20 # 5 + 15 + assert connection_manager.middleware_installed == False # Check that the return value is correct assert result["routes"] == dict(connection_manager.routes.routes) diff --git a/aikido_zen/middleware/init_test.py b/aikido_zen/middleware/init_test.py index 5a30e9ec..dea1e69a 100644 --- a/aikido_zen/middleware/init_test.py +++ b/aikido_zen/middleware/init_test.py @@ -56,12 +56,14 @@ def test_with_context_with_cache(): thread_cache.config.blocked_uids = ["123"] assert get_current_context().executed_middleware == False + assert thread_cache.middleware_installed == False assert should_block_request() == { "block": True, "trigger": "user", "type": "blocked", } assert get_current_context().executed_middleware == True + assert thread_cache.middleware_installed == True thread_cache.config.blocked_uids = [] assert should_block_request() == {"block": False} @@ -69,6 +71,7 @@ def test_with_context_with_cache(): thread_cache.config.blocked_uids = ["23", "234", "456"] assert should_block_request() == {"block": False} assert get_current_context().executed_middleware == True + assert thread_cache.middleware_installed == True def test_cache_comms_with_endpoints(): @@ -88,11 +91,13 @@ def test_cache_comms_with_endpoints(): } ] assert get_current_context().executed_middleware == False + assert thread_cache.middleware_installed == False with patch("aikido_zen.background_process.comms.get_comms") as mock_get_comms: mock_get_comms.return_value = None # Set the return value of get_comms assert should_block_request() == {"block": False} assert get_current_context().executed_middleware == True + assert thread_cache.middleware_installed == True with patch("aikido_zen.background_process.comms.get_comms") as mock_get_comms: mock_comms = MagicMock()