Rev gateway tests

This commit is contained in:
Cyber MacGeddon 2025-07-13 09:05:06 +01:00
parent a96489b037
commit eed008530d
3 changed files with 30 additions and 39 deletions

View file

@ -10,37 +10,11 @@ import pulsar
from trustgraph.gateway.service import Api, run, default_pulsar_host, default_prometheus_url, default_timeout, default_port, default_api_token
# Patch async methods at module level to prevent coroutine warnings
async def mock_app_factory(self):
"""Mock app_factory that mimics the real behavior for tests"""
app = web.Application(
middlewares=[],
client_max_size=256 * 1024 * 1024
)
# Mock the real app_factory behavior that tests expect
if hasattr(self, 'config_receiver') and hasattr(self.config_receiver, 'start'):
await self.config_receiver.start()
# Handle custom endpoints
if hasattr(self, 'endpoints'):
for ep in self.endpoints:
if hasattr(ep, 'add_routes'):
ep.add_routes(app)
for ep in self.endpoints:
if hasattr(ep, 'start'):
await ep.start()
# Handle endpoint manager
if hasattr(self, 'endpoint_manager'):
if hasattr(self.endpoint_manager, 'add_routes'):
self.endpoint_manager.add_routes(app)
if hasattr(self.endpoint_manager, 'start'):
await self.endpoint_manager.start()
return app
# Store the original method before patching
_original_app_factory = Api.app_factory
Api.app_factory = mock_app_factory
# Replace with AsyncMock to prevent coroutine warnings during introspection
Api.app_factory = AsyncMock()
class TestApi:
@ -154,6 +128,9 @@ class TestApi:
api = Api()
# Temporarily restore the real app_factory for this test
api.app_factory = _original_app_factory.__get__(api, Api)
# Mock the dependencies
api.config_receiver = Mock()
api.config_receiver.start = AsyncMock()
@ -181,6 +158,9 @@ class TestApi:
api = Api()
# Temporarily restore the real app_factory for this test
api.app_factory = _original_app_factory.__get__(api, Api)
# Mock custom endpoints
mock_endpoint1 = Mock()
mock_endpoint1.add_routes = Mock()