-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `/api/speech/token` endpoint * Re-introduce `/api/config` * Move env vars * Remove `AZURE_SUBSCRIPTION_ID` * Log error * Rename to `/api/speech`, remove `/api/config`
- Loading branch information
Showing
14 changed files
with
403 additions
and
161 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
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
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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
code/tests/functional/backend_api/tests/with_data/test_speech_token.py
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,61 @@ | ||
import pytest | ||
import requests | ||
from pytest_httpserver import HTTPServer | ||
from tests.functional.backend_api.app_config import AppConfig | ||
from tests.functional.backend_api.request_matching import ( | ||
RequestMatcher, | ||
verify_request_made, | ||
) | ||
|
||
pytestmark = pytest.mark.functional | ||
|
||
|
||
def test_speech_token_returned(app_url: str, app_config: AppConfig): | ||
# when | ||
response = requests.get(f"{app_url}/api/speech") | ||
|
||
# then | ||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"token": "speech-token", | ||
"region": app_config.get("AZURE_SPEECH_SERVICE_REGION"), | ||
} | ||
assert response.headers["Content-Type"] == "application/json" | ||
|
||
|
||
def test_speech_service_called_correctly( | ||
app_url: str, app_config: AppConfig, httpserver: HTTPServer | ||
): | ||
# when | ||
requests.get(f"{app_url}/api/speech") | ||
|
||
# then | ||
verify_request_made( | ||
mock_httpserver=httpserver, | ||
request_matcher=RequestMatcher( | ||
path="/sts/v1.0/issueToken", | ||
method="POST", | ||
headers={ | ||
"Ocp-Apim-Subscription-Key": app_config.get("AZURE_SPEECH_SERVICE_KEY") | ||
}, | ||
times=1, | ||
), | ||
) | ||
|
||
|
||
def test_failure_fetching_speech_token(app_url: str, httpserver: HTTPServer): | ||
# given | ||
httpserver.clear_all_handlers() # Clear default successful responses | ||
|
||
httpserver.expect_request( | ||
"/sts/v1.0/issueToken", | ||
method="POST", | ||
).respond_with_json({"error": "Bad request"}, status=400) | ||
|
||
# when | ||
response = requests.get(f"{app_url}/api/speech") | ||
|
||
# then | ||
assert response.status_code == 400 | ||
assert response.json() == {"error": "Failed to get speech token"} | ||
assert response.headers["Content-Type"] == "application/json" |
Oops, something went wrong.