Skip to content

Commit c34fc7c

Browse files
committed
Refactor web app for consistent style and improved error handling
Standardized string quoting to double quotes, improved formatting, and enhanced error handling throughout the Flask web app, i18n, and websocket handler modules. Updated test cases and main entry points for consistency. No functional changes, but code is now more readable and maintainable.
1 parent 82e184a commit c34fc7c

File tree

13 files changed

+783
-772
lines changed

13 files changed

+783
-772
lines changed

tests/test_web_app.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ def load_web_app(monkeypatch, **env):
3737

3838

3939
def test_voices_endpoint_returns_data(monkeypatch):
40-
module = load_web_app(monkeypatch, REQUIRE_API_KEY='false', TTSFM_API_KEY=None)
40+
module = load_web_app(monkeypatch, REQUIRE_API_KEY="false", TTSFM_API_KEY=None)
4141
client = module.app.test_client()
42-
response = client.get('/api/voices')
42+
response = client.get("/api/voices")
4343
assert response.status_code == 200
4444
payload = response.get_json()
45-
assert payload['count'] == len(payload['voices'])
45+
assert payload["count"] == len(payload["voices"])
4646

4747

4848
def test_combine_audio_chunks_uses_format_hint(monkeypatch):
49-
load_web_app(monkeypatch, REQUIRE_API_KEY='false', TTSFM_API_KEY=None)
49+
load_web_app(monkeypatch, REQUIRE_API_KEY="false", TTSFM_API_KEY=None)
5050

5151
from ttsfm import audio as audio_module
5252

@@ -82,17 +82,20 @@ def from_wav(cls, buffer):
8282
assert DummyAudioSegment.formats == ["wav", "wav"]
8383

8484

85-
@pytest.mark.parametrize('header_name, header_value', [
86-
('Authorization', 'Bearer super-secret'),
87-
('X-API-Key', 'super-secret'),
88-
])
85+
@pytest.mark.parametrize(
86+
"header_name, header_value",
87+
[
88+
("Authorization", "Bearer super-secret"),
89+
("X-API-Key", "super-secret"),
90+
],
91+
)
8992
def test_api_key_hash_verification(monkeypatch, header_name, header_value):
90-
module = load_web_app(monkeypatch, REQUIRE_API_KEY='true', TTSFM_API_KEY='super-secret')
93+
module = load_web_app(monkeypatch, REQUIRE_API_KEY="true", TTSFM_API_KEY="super-secret")
9194
client = module.app.test_client()
9295

93-
denied = client.post('/api/validate-text', json={'text': 'hello'})
96+
denied = client.post("/api/validate-text", json={"text": "hello"})
9497
assert denied.status_code == 401
9598

9699
headers = {header_name: header_value}
97-
response = client.post('/api/validate-text', json={'text': 'hello'}, headers=headers)
100+
response = client.post("/api/validate-text", json={"text": "hello"}, headers=headers)
98101
assert response.status_code == 200

0 commit comments

Comments
 (0)