Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理: e2e single API テスト vol 4 #1149

Merged
merged 5 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

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

24 changes: 24 additions & 0 deletions test/e2e/single_api/test_add_preset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
/add_preset API のテスト
"""

import pytest
from fastapi.testclient import TestClient


@pytest.mark.skip(reason="プリセット追加が他のテストに干渉するから")
Copy link
Member

@Hiroshiba Hiroshiba Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほどです!

いろんな迂回策がありそうですが、引数にしてる(=fixture)のclientのtearDownとして登録されてるプリセットの削除とかを実行すると良い気がしました!
client fixtureを定義してるとこでclientをreturnではなくyieldで返して、その後にクリーンナップ処理を書けば良いはず…?
https://docs.pytest.org/en/6.2.x/fixture.html#teardown-cleanup-aka-fixture-finalization

def test_post_add_preset_200(client: TestClient) -> None:
preset = {
"id": 9999,
"name": "test_preset",
"speaker_uuid": "123-456-789-234",
"style_id": 9999,
"speedScale": 1,
"pitchScale": 1,
"intonationScale": 1,
"volumeScale": 1,
"prePhonemeLength": 10,
"postPhonemeLength": 10,
}
response = client.post("/add_preset", params={}, json=preset)
assert response.status_code == 200
24 changes: 24 additions & 0 deletions test/e2e/single_api/test_delete_preset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
/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
) -> None:
response = client.post("/delete_preset", params={"id": 1})
assert response.status_code == 204
assert snapshot_json == response.json()


def test_post_delete_preset_422(
client: TestClient, snapshot_json: SnapshotAssertion
) -> None:
response = client.post("/delete_preset", params={"id": 4040000000})
assert response.status_code == 422
assert snapshot_json == response.json()
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""
プリセットAPIのテスト
/presets API のテスト
"""

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


def test_プリセット一覧を取得できる(
client: TestClient, snapshot_json: SnapshotAssertion
) -> None:
def test_get_presets_200(client: TestClient, snapshot_json: SnapshotAssertion) -> None:
response = client.get("/presets")
assert response.status_code == 200
assert snapshot_json == response.json()
45 changes: 45 additions & 0 deletions test/e2e/single_api/test_update_preset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
/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:
preset = {
"id": 1,
"name": "test_preset",
"speaker_uuid": "123-456-789-234",
"style_id": 9999,
"speedScale": 1,
"pitchScale": 1,
"intonationScale": 1,
"volumeScale": 1,
"prePhonemeLength": 10,
"postPhonemeLength": 10,
}
response = client.post("/update_preset", params={}, json=preset)
assert response.status_code == 200


def test_post_update_preset_422(
client: TestClient, snapshot_json: SnapshotAssertion
) -> None:
preset = {
"id": 4040000000,
"name": "Nessie",
"speaker_uuid": "404-404-404-404",
"style_id": 404,
"speedScale": 404,
"pitchScale": 404,
"intonationScale": 404,
"volumeScale": 404,
"prePhonemeLength": 404,
"postPhonemeLength": 404,
}
response = client.post("/update_preset", params={}, json=preset)
assert response.status_code == 422
assert snapshot_json == response.json()
Loading