-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
from unittest.mock import AsyncMock, Mock, patch | ||
from uuid import uuid4 | ||
|
||
import pytest | ||
from sanic import Sanic | ||
from sanic_testing import TestManager | ||
|
||
sanitized_name = __name__.replace(".", "_") | ||
|
||
|
||
@pytest.fixture | ||
def app(): | ||
app_instance = Sanic(sanitized_name) | ||
os.environ["WEAVIATE_URL"] = "http://localhost:8080" | ||
os.environ["OPENAI_API_KEY"] = "OPENAI_API_KEY" | ||
TestManager(app_instance) | ||
|
||
from ask_astro.rest.controllers.get_request import on_get_request | ||
|
||
app_instance.add_route(on_get_request, "/requests/<request_id:uuid>") | ||
|
||
return app_instance | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_on_get_request_error(app): | ||
with patch( | ||
"ask_astro.rest.controllers.get_request.firestore_client", new_callable=AsyncMock | ||
) as mock_firestore, patch( | ||
"ask_astro.rest.controllers.on_post_request", new_callable=AsyncMock | ||
) as mock_on_post_request, patch( | ||
"google.cloud.firestore.AsyncClient" | ||
) as mock_async_client: | ||
mock_on_post_request.async_return_value = {} | ||
mock_firestore.async_return_value = {} | ||
mock_async_client.async_return_value = {} | ||
|
||
request_id = uuid4() | ||
mock_data = {"title": "Sample Question"} | ||
|
||
mock_get = AsyncMock() | ||
mock_get.exists = True | ||
mock_get.to_dict.return_value = mock_data | ||
|
||
mock_document = Mock() | ||
mock_document.get.return_value = mock_get | ||
|
||
mock_collection = Mock() | ||
mock_collection.document.return_value = mock_document | ||
|
||
mock_firestore.collection.return_value = mock_collection | ||
|
||
request, response = await app.asgi_client.get(f"/requests/{request_id}") | ||
|
||
assert response.status == 500 | ||
assert response.json == {"error": "Internal Server Error"} |