-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_api.py
51 lines (41 loc) · 1.43 KB
/
test_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
# FastAPI 서버 URL
BASE_URL = "http://127.0.0.1:8000"
# 테스트용 파일 경로
TEST_FILE_PATH = "data/hyplex.pdf"
# 1. PDF 업로드 테스트
def test_upload():
url = f"{BASE_URL}/upload"
try:
# 파일 열기 및 업로드 요청
with open(TEST_FILE_PATH, 'rb') as file:
files = {'file': file}
response = requests.post(url, files=files)
# 응답 확인
if response.status_code == 200:
print("Upload Response:", response.json())
else:
print(f"Upload Failed. Status Code: {response.status_code}, Response: {response.text}")
except FileNotFoundError:
print(f"File not found: {TEST_FILE_PATH}")
except Exception as e:
print(f"An error occurred during upload: {e}")
# 2. 검색 테스트
def test_search():
url = f"{BASE_URL}/search"
data = {"query": "example text"}
try:
# 검색 요청
response = requests.post(url, json=data)
# 응답 확인
if response.status_code == 200:
print("Search Response:", response.json())
else:
print(f"Search Failed. Status Code: {response.status_code}, Response: {response.text}")
except Exception as e:
print(f"An error occurred during search: {e}")
if __name__ == "__main__":
print("Testing PDF Upload:")
test_upload()
print("\nTesting Search:")
test_search()