Skip to content

Commit

Permalink
整理: e2e single API テスト vol 6 (#1155)
Browse files Browse the repository at this point in the history
* add: 副作用無しプリセット e2e テストを追加

* fix: 204スナップショット追加

* fix: lint

* fix: lint

* fix: プリセット複製を平易な記法に変更
  • Loading branch information
tarepan authored Apr 15, 2024
1 parent 0845bbb commit e5635cb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
13 changes: 9 additions & 4 deletions test/e2e/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
from pathlib import Path
from typing import Any

Expand All @@ -14,14 +15,18 @@


@pytest.fixture()
def app_params() -> dict[str, Any]:
def app_params(tmp_path: Path) -> dict[str, Any]:
cores = initialize_cores(use_gpu=False, enable_mock=True)
tts_engines = make_tts_engines_from_cores(cores)
latest_core_version = get_latest_core_version(versions=list(tts_engines.keys()))
setting_loader = SettingHandler(Path("./not_exist.yaml"))
preset_manager = PresetManager( # FIXME: impl MockPresetManager
preset_path=Path("./presets.yaml"),
)

# 隔離されたプリセットの生成
original_preset_path = Path("./presets.yaml")
preset_path = tmp_path / "presets.yaml"
shutil.copyfile(original_preset_path, preset_path)
preset_manager = PresetManager(preset_path)

return {
"tts_engines": tts_engines,
"cores": cores,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/e2e/single_api/__snapshots__/test_delete_preset.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_post_delete_preset_204
b''
# ---

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions test/e2e/single_api/test_add_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/add_preset API のテスト
"""

import pytest
from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


@pytest.mark.skip(reason="プリセット追加が他のテストに干渉するから")
def test_post_add_preset_200(client: TestClient) -> None:
def test_post_add_preset_200(
client: TestClient, snapshot_json: SnapshotAssertion
) -> None:
preset = {
"id": 9999,
"name": "test_preset",
Expand All @@ -22,3 +23,4 @@ def test_post_add_preset_200(client: TestClient) -> None:
}
response = client.post("/add_preset", params={}, json=preset)
assert response.status_code == 200
assert snapshot_json == response.json()
6 changes: 2 additions & 4 deletions test/e2e/single_api/test_delete_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
/delete_preset API のテスト
"""

import pytest
from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


@pytest.mark.skip(reason="プリセット削除が他のテストに干渉するから")
def test_post_delete_preset_204(
client: TestClient, snapshot_json: SnapshotAssertion
client: TestClient, snapshot: SnapshotAssertion
) -> None:
response = client.post("/delete_preset", params={"id": 1})
assert response.status_code == 204
assert snapshot_json == response.json()
assert snapshot == response.content


def test_post_delete_preset_422(
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/single_api/test_update_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/update_preset API のテスト
"""

import pytest
from fastapi.testclient import TestClient
from syrupy.assertion import SnapshotAssertion


@pytest.mark.skip(reason="プリセット変更が他のテストに干渉するから")
def test_post_update_preset_200(client: TestClient) -> None:
def test_post_update_preset_200(
client: TestClient, snapshot_json: SnapshotAssertion
) -> None:
preset = {
"id": 1,
"name": "test_preset",
Expand All @@ -23,6 +23,7 @@ def test_post_update_preset_200(client: TestClient) -> None:
}
response = client.post("/update_preset", params={}, json=preset)
assert response.status_code == 200
assert snapshot_json == response.json()


def test_post_update_preset_422(
Expand Down

0 comments on commit e5635cb

Please sign in to comment.