Refactor cache service and fix async issues (#1512)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-09 22:55:56 -03:00 committed by GitHub
commit 67bccdc753
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 466 additions and 171 deletions

View file

@ -28,9 +28,7 @@ async def test_successful_get_request(api_request):
respx.get(url).mock(return_value=Response(200, json=mock_response))
# Making the request
result = await api_request.make_request(
client=httpx.AsyncClient(), method=method, url=url
)
result = await api_request.make_request(client=httpx.AsyncClient(), method=method, url=url)
# Assertions
assert result.data["status_code"] == 200
@ -46,9 +44,7 @@ async def test_failed_request(api_request):
respx.get(url).mock(return_value=Response(404))
# Making the request
result = await api_request.make_request(
client=httpx.AsyncClient(), method=method, url=url
)
result = await api_request.make_request(client=httpx.AsyncClient(), method=method, url=url)
# Assertions
assert result.data["status_code"] == 404
@ -60,14 +56,10 @@ async def test_timeout(api_request):
# Mocking a timeout
url = "https://example.com/api/timeout"
method = "GET"
respx.get(url).mock(
side_effect=httpx.TimeoutException(message="Timeout", request=None)
)
respx.get(url).mock(side_effect=httpx.TimeoutException(message="Timeout", request=None))
# Making the request
result = await api_request.make_request(
client=httpx.AsyncClient(), method=method, url=url, timeout=1
)
result = await api_request.make_request(client=httpx.AsyncClient(), method=method, url=url, timeout=1)
# Assertions
assert result.data["status_code"] == 408
@ -106,7 +98,6 @@ def test_directory_component_build_with_multithreading(
# Arrange
directory_component = data.DirectoryComponent()
path = os.path.dirname(os.path.abspath(__file__))
types = ["py"]
depth = 1
max_concurrency = 2
load_hidden = False
@ -123,7 +114,6 @@ def test_directory_component_build_with_multithreading(
# Act
directory_component.build(
path,
types,
depth,
max_concurrency,
load_hidden,
@ -134,9 +124,7 @@ def test_directory_component_build_with_multithreading(
# Assert
mock_resolve_path.assert_called_once_with(path)
mock_retrieve_file_paths.assert_called_once_with(
path, types, load_hidden, recursive, depth
)
mock_retrieve_file_paths.assert_called_once_with(path, load_hidden, recursive, depth)
mock_parallel_load_records.assert_called_once_with(
mock_retrieve_file_paths.return_value, silent_errors, max_concurrency
)