Skip to content

Commit

Permalink
Merge pull request #22 from COSCUP/feat/add_test
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
106303551 authored Jul 31, 2024
2 parents 721a434 + 24d79da commit e8568e7
Show file tree
Hide file tree
Showing 11 changed files with 76,879 additions and 250 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ local_qdrant/
__pycache__/
vectorDB/qdrant_storage/
.python-version
.pytest_cache/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV POETRY_VERSION=1.7.1 \
POETRY_VIRTUALENVS_CREATE=1

RUN pip install "poetry==$POETRY_VERSION"
RUN poetry install --no-interaction --no-ansi --verbose \
RUN poetry install --no-interaction --no-ansi --verbose --without test\
&& rm -rf $POETRY_CACHE_DIR
RUN poetry env use 3.11

Expand Down
373 changes: 125 additions & 248 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ torch = {url = "https://download.pytorch.org/whl/cpu-cxx11-abi/torch-2.2.2%2Bcpu
sentence-transformers = "^3.0.1"


[tool.poetry.group.test.dependencies]
vcrpy = "^6.0.1"
pytest = "^8.2.2"
syrupy = "^4.6.1"
pytest-asyncio = "^0.23.7"
pytest-recording = "^0.13.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
addopts = --asyncio-mode=auto
markers =
vcr: Use vcrpy to record and replay HTTP interactions
2 changes: 1 addition & 1 deletion src/routers/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def askAPI(data: Query):
del vectorstore
del retriever

return answer
return {"result": answer}


@router.post(
Expand Down
52 changes: 52 additions & 0 deletions tests/__snapshots__/test_api.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# serializer version: 1
# name: test_askAPI
dict({
'result': '''
志工平台是 COSCUP(開放源碼用戶大會)的管理和組織志工的工具。它可以用於申請各式各樣的志工福利,以及記錄自己的志工經歷。在加入 COSCUP 志工過程中,所使用的平台是 COSCUP 為管理志工所開發的[志工服務平台](https://volunteer.coscup.org/)。

2022 年志工服務平台主要集中在解決志工登錄自動化和其他繁瑣的手工事務。透過「流程改善」,整理出規則的流程後,可以協助轉移到志工平台上完成。可能需要志工協助的部分包括社群議程軌等。

如何貢獻專案可以參考「[志工平台文件](https://volunteer.coscup.org/docs/)」。在進行以下操作前,請先準備好所需內容,以便在設定流程或之後行政組詢問時會用到。
Source:
https://github.com/COSCUP/COSCUP-Volunteer/blob/main/docs_dev/docs/announcement/pycontw_2023_sprints.zh-TW.md
https://github.com/COSCUP/COSCUP-Volunteer/blob/main/docs_dev/docs/about_coscup/team_leader_handbook.zh-TW.md
https://github.com/COSCUP/COSCUP-Volunteer/blob/main/docs_dev/docs/about_coscup/team_member_handbook.zh-TW.md

''',
})
# ---
# name: test_askAPI_empty_query
dict({
'message': 'empty query is not allowed',
})
# ---
# name: test_chatbot
dict({
'response_type': 'in_channel',
'text': '''
Question: 志工平台是什麼?

Answer:
志工平台是 COSCUP(開放源碼用戶大會)的管理和組織志工的工具。它可以用於申請各式各樣的志工福利,以及記錄自己的志工經歷。在加入 COSCUP 志工過程中,所使用的平台是 COSCUP 為管理志工所開發的[志工服務平台](https://volunteer.coscup.org/)。

2022 年志工服務平台主要集中在解決志工登錄自動化和其他繁瑣的手工事務。透過「流程改善」,整理出規則的流程後,可以協助轉移到志工平台上完成。可能需要志工協助的部分包括社群議程軌等。

如何貢獻專案可以參考「[志工平台文件](https://volunteer.coscup.org/docs/)」。在進行以下操作前,請先準備好所需內容,以便在設定流程或之後行政組詢問時會用到。
Source:
https://github.com/COSCUP/COSCUP-Volunteer/blob/main/docs_dev/docs/announcement/pycontw_2023_sprints.zh-TW.md
https://github.com/COSCUP/COSCUP-Volunteer/blob/main/docs_dev/docs/about_coscup/team_leader_handbook.zh-TW.md
https://github.com/COSCUP/COSCUP-Volunteer/blob/main/docs_dev/docs/about_coscup/team_member_handbook.zh-TW.md

''',
})
# ---
# name: test_health_check
dict({
'Status': 'OK',
})
# ---
# name: test_health_check_alternative
dict({
'Status': 'OK',
})
# ---
15,478 changes: 15,478 additions & 0 deletions tests/cassettes/test_api/test_askAPI.yaml

Large diffs are not rendered by default.

152 changes: 152 additions & 0 deletions tests/cassettes/test_api/test_askAPI_empty_query.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
interactions:
- request:
body: '{"query": ""}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '13'
content-type:
- application/json
host:
- test
user-agent:
- python-httpx/0.27.0
method: POST
uri: http://test/api/v1/ask
response:
body:
string: '{"message":"empty query is not allowed"}'
headers:
content-length:
- '40'
content-type:
- application/json
status:
code: 422
message: Unprocessable Entity
- request:
body: '{"query": ""}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '13'
content-type:
- application/json
host:
- test
user-agent:
- python-httpx/0.27.0
method: POST
uri: http://test/api/v1/ask
response:
body:
string: '{"message":"empty query is not allowed"}'
headers:
content-length:
- '40'
content-type:
- application/json
status:
code: 422
message: Unprocessable Entity
- request:
body: '{"query": ""}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '13'
content-type:
- application/json
host:
- test
user-agent:
- python-httpx/0.27.0
method: POST
uri: http://test/api/v1/ask
response:
body:
string: '{"message":"empty query is not allowed"}'
headers:
content-length:
- '40'
content-type:
- application/json
status:
code: 422
message: Unprocessable Entity
- request:
body: '{"query": ""}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '13'
content-type:
- application/json
host:
- test
user-agent:
- python-httpx/0.27.0
method: POST
uri: http://test/api/v1/ask
response:
body:
string: '{"message":"empty query is not allowed"}'
headers:
content-length:
- '40'
content-type:
- application/json
status:
code: 422
message: Unprocessable Entity
- request:
body: '{"query": ""}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
connection:
- keep-alive
content-length:
- '13'
content-type:
- application/json
host:
- test
user-agent:
- python-httpx/0.27.0
method: POST
uri: http://test/api/v1/ask
response:
body:
string: '{"message":"empty query is not allowed"}'
headers:
content-length:
- '40'
content-type:
- application/json
status:
code: 422
message: Unprocessable Entity
version: 1
Loading

0 comments on commit e8568e7

Please sign in to comment.