-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a pytest that mocks the clients and runs the entire api (#11)
* feat: Add a pytest that runs the entire api, mocks the clients, and verifies a request doesn't crash * Ignore input types to mocked functions * Minor
- Loading branch information
1 parent
2926978
commit 1c06985
Showing
2 changed files
with
90 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
from typing import Any | ||
|
||
from pytest_cases import parametrize_with_cases | ||
from pytest_cases import parametrize, parametrize_with_cases | ||
|
||
from emma_experience_hub.api.clients.simbot import SimbotActionPredictionClient | ||
from emma_experience_hub.api.controllers import SimBotController | ||
from emma_experience_hub.common.settings import SimBotSettings | ||
from emma_experience_hub.datamodels.simbot import SimBotRequest | ||
from tests.fixtures.clients import ( | ||
mock_policy_response_goto_room, | ||
mock_policy_response_search, | ||
mock_policy_response_toggle_computer, | ||
) | ||
from tests.fixtures.simbot_api_requests import SimBotRequestCases | ||
|
||
|
||
@parametrize_with_cases("request_body", cases=SimBotRequestCases) | ||
@parametrize_with_cases("request_body", cases=SimBotRequestCases.case_without_previous_actions) | ||
@parametrize( | ||
"mock_policy_responses", | ||
[ | ||
mock_policy_response_toggle_computer, | ||
mock_policy_response_goto_room, | ||
mock_policy_response_search, | ||
], | ||
) | ||
def test_simbot_api( | ||
request_body: dict[str, Any], | ||
simbot_settings: SimBotSettings, | ||
mock_feature_extraction_response: Any, | ||
mock_policy_responses: Any, | ||
) -> None: | ||
"""Test the SimBot API.""" | ||
simbot_request = SimBotRequest.parse_obj(request_body) | ||
controller = SimBotController.from_simbot_settings(simbot_settings) | ||
controller.handle_request_from_simbot_arena(simbot_request) | ||
response = controller.handle_request_from_simbot_arena(simbot_request) | ||
assert response.actions[0].raw_output is not None | ||
assert response.actions[0].raw_output == SimbotActionPredictionClient.generate() # type: ignore[call-arg] |
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