Skip to content

Commit 5bf1982

Browse files
author
Hara
committed
add: テスト用に競技システムのモックを作成
1 parent 94dc38d commit 5bf1982

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/mock_official_interface.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""テスト用の競技システムモック.
2+
3+
@author: Claude
4+
"""
5+
import os
6+
7+
8+
class MockOfficialInterface:
9+
"""テスト用の競技システムモック."""
10+
11+
@classmethod
12+
def upload_snap(cls, img_path: str, maxAttempts: int = 3) -> bool:
13+
"""テスト用のアップロード関数(常に成功を返す).
14+
15+
Args:
16+
img_path (str): アップロードする画像のパス
17+
maxAttempts (int): 最大試行回数
18+
19+
Returns:
20+
success (bool): 常にTrue
21+
"""
22+
if not os.path.exists(img_path):
23+
print(f"画像ファイルが存在しません: {img_path}")
24+
return False
25+
26+
print(f"Mock: Image uploaded successfully from {img_path}")
27+
return True

tests/test_fastapi_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"""
66
from fastapi.testclient import TestClient
77
from src.server.fastapi_server import app
8+
from unittest.mock import patch
9+
from tests.mock_official_interface import MockOfficialInterface
810
import os
911

1012
# テスト用クライアントの生成
@@ -23,6 +25,7 @@ def test_upload_no_file():
2325
assert response.status_code == 422
2426

2527

28+
@patch('src.server.fastapi_server.OfficialInterface', MockOfficialInterface)
2629
def test_upload_real_image_file():
2730
# アップロードする実際の画像ファイルのパス
2831
image_path = "tests/test_data/img/test_data.JPEG"

0 commit comments

Comments
 (0)