-
Notifications
You must be signed in to change notification settings - Fork 205
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
Hiroshiba
merged 5 commits into
VOICEVOX:master
from
tarepan:refactor/add_single_api_v4
Mar 29, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
test/e2e/single_api/__snapshots__/test_delete_preset/test_post_delete_preset_422.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
test/e2e/single_api/__snapshots__/test_update_preset/test_post_update_preset_422.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
""" | ||
/add_preset API のテスト | ||
""" | ||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
@pytest.mark.skip(reason="プリセット追加が他のテストに干渉するから") | ||
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 |
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,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() |
6 changes: 2 additions & 4 deletions
6
test/e2e/single_api/test_preset_api.py → test/e2e/single_api/test_presets.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 |
---|---|---|
@@ -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() |
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,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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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