-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from FacerAin/feat/test
Add test code and coverage
- Loading branch information
Showing
6 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
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
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
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,14 @@ | ||
import datetime | ||
|
||
|
||
def get_meal_info(query: str = ""): | ||
return """ | ||
If a user is looking for campus cafeterial menu information, use the link below. You should directly check the meal information from the link below. | ||
경희대학교 학생 식당: https://www.khu.ac.kr/kor/forum/list.do?type=RESTAURANT&category=INTL&page=1 | ||
경희대학교 제 2기숙사 식당: https://dorm2.khu.ac.kr/40/4050.kmc | ||
""" | ||
|
||
|
||
def get_today_date(query: str = ""): | ||
now = datetime.datetime.now() | ||
return str(now.strftime("%Y-%m-%d")) |
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,3 @@ | ||
[pytest] | ||
markers = | ||
live: For testing actual API interactions (deselect with '-m "not live"') |
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,44 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from app.agent import ExecutorAgent | ||
from app.agent.retriever import PineconeRetriever | ||
from app.main import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_completion(monkeypatch): | ||
def mockreturn(a, b): | ||
return "Hello" | ||
|
||
monkeypatch.setattr(ExecutorAgent, "run", mockreturn) | ||
req_body = {"query": "Hi"} | ||
response = client.post("/api/v1/chat/completion", json=req_body) | ||
assert response.status_code == 200 | ||
assert "answer" in response.json() | ||
assert "Hello" == response.json()["answer"] | ||
|
||
|
||
def test_similarity_search(monkeypatch): | ||
def mockreturn(a, b): | ||
return "Hello" | ||
|
||
monkeypatch.setattr(PineconeRetriever, "get_relevant_doc_string", mockreturn) | ||
response = client.get("/api/v1/chat/similarity-search?query=Hi") | ||
assert response.status_code == 200 | ||
assert isinstance(response.text, str) | ||
assert '"Hello"' == response.text | ||
|
||
|
||
@pytest.mark.live | ||
def test_live_completion(): | ||
req_body = {"query": "Hi"} | ||
response = client.post("/api/v1/chat/completion", json=req_body) | ||
assert response.status_code == 200 | ||
|
||
|
||
@pytest.mark.live | ||
def test_live_similarity_search(): | ||
response = client.get("/api/v1/chat/similarity-search?query=Hi") | ||
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,11 @@ | ||
import datetime | ||
|
||
from app.agent.tools import get_meal_info, get_today_date | ||
|
||
|
||
def test_get_today_date(): | ||
assert get_today_date() == str(datetime.datetime.now().strftime("%Y-%m-%d")) | ||
|
||
|
||
def test_get_meal_info(): | ||
assert "https://dorm2.khu.ac.kr/40/4050.kmc" in get_meal_info() |