Partially finished the unit test for file handler
Unit test coverage / pytest (push) Failing after 3h4m2s

This commit is contained in:
2025-05-13 18:00:01 +08:00
parent 44b6a8c3f1
commit 98fc52fc26
2 changed files with 94 additions and 3 deletions
+9 -1
View File
@@ -153,6 +153,11 @@ class StreamingFileHandler(FileHandler):
def __init__(self):
super().__init__()
# This method MUST NOT be static.
# For testing purpose, we will mock this method and inject a mock connection.
async def _get_connection(self, rabbitmq_url, loop):
return await connect_robust(rabbitmq_url, loop=loop)
async def download_file(
self, loop, rabbitmq_url, file_info, message_data, output_dir
) -> (int, int):
@@ -185,7 +190,10 @@ class StreamingFileHandler(FileHandler):
)
async def wrap_rabbit_mq_calls() -> tuple[int, int] | None:
connection = await connect_robust(rabbitmq_url, loop=loop)
# Here the normal mock doesn't work since this method
# is async and will be run in another loop,
# out of the scope of method mock.
connection = await self._get_connection(rabbitmq_url, loop=loop)
try:
_file_size = 0
_eof = IN_PROGRESS