Skip to content

Commit fe0cad7

Browse files
taskingaijcL1ttleWave
authored andcommitted
test: add test for backend
1 parent 426ef3f commit fe0cad7

70 files changed

Lines changed: 3317 additions & 1449 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/test-backend.yml‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,19 @@ jobs:
111111
taskingai/taskingai-server:$IMAGE_TAG
112112
113113
- name: Wait for service to start
114-
run: sleep 10
115-
116-
- name: Install Dependencies
117-
working-directory: TaskingAI-Test
114+
env:
115+
ECR_REGISTRY: ${{ env.ECR_REGISTRY }}
116+
INFERENCE_PROVIDER_CREDENTIALS: ${{ secrets.INFERENCE_PROVIDER_CREDENTIALS }}
117+
PLUGIN_BUNDLE_CREDENTIALS: ${{ secrets.PLUGIN_BUNDLE_CREDENTIALS }}
118118
run: |
119-
echo "machine github.com login ${{ secrets.GH_PAT_TKHELPER }}" > ~/.netrc
120-
pip install -r requirements.txt
121-
122-
- name: Start API Service
123-
working-directory: TaskingAI-Test
124-
run: python ./common/api_service.py &
119+
echo "$INFERENCE_PROVIDER_CREDENTIALS" > .env
120+
echo "$PLUGIN_BUNDLE_CREDENTIALS" >> .env
121+
sleep 10
125122
126123
- name: Run WEB Tests
127-
working-directory: TaskingAI-Test
128-
run: bash ./community_app/run_test.sh
124+
working-directory: backend
125+
run: bash ./run_web_test.sh
129126

130127
- name: Run API Tests
131-
working-directory: TaskingAI-Test
132-
run: bash ./community_api/run_test.sh
128+
working-directory: backend
129+
run: bash ./run_api_test.sh

‎backend/pytest.ini‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[pytest]
2+
3+
markers =
4+
version(number): Version number of the test case
5+
test_id(id): Test case identifier
6+
api_test: mark a test as an api_test
7+
web_test: mark a test as a web_test
8+
9+
10+
log_cli = False
11+
12+
addopts = -W ignore::DeprecationWarning

‎backend/requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ numpy==1.26.3
2020
pytest==7.4.3
2121
pytest-asyncio==0.21.1
2222
pytest-ordering==0.6
23+
pytest-assume==2.4.3

‎backend/run_api_test.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export TEST_MODE=TASKINGAI_API_TEST
2+
3+
set -e
4+
parent_dir="$(dirname "$(pwd)")"
5+
export PYTHONPATH="${PYTHONPATH}:${parent_dir}"
6+
7+
echo "Starting tests..."
8+
pytest ./tests/services_tests -m "api_test" -q --tb=no
9+
echo "Tests completed."

‎backend/run_test.sh‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

‎backend/run_web_test.sh‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export TEST_MODE=TASKINGAI_WEB_TEST
2+
3+
set -e
4+
parent_dir="$(dirname "$(pwd)")"
5+
export PYTHONPATH="${PYTHONPATH}:${parent_dir}"
6+
echo "Starting tests..."
7+
pytest ./tests/services_tests -m "web_test or api_test"
8+
echo "Tests completed."
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
import aiohttp
22

33
from typing import Dict
4-
from tests.common.utils import ResponseWrapper, get_headers
5-
from tests.settings import HOST, WEB_SERVICE_PORT
6-
from app.config import CONFIG
4+
from backend.tests.common.utils import ResponseWrapper, get_headers
5+
from backend.tests.common.config import CONFIG
76

8-
BASE_URL = f"{HOST}:{WEB_SERVICE_PORT}{CONFIG.WEB_ROUTE_PREFIX}"
7+
ADMIN_BASE_URL = f"{CONFIG.WEB_BASE_URL}/admins"
98

109

1110
async def login(payload: Dict):
1211
async with aiohttp.ClientSession() as session:
13-
request_url = f"{BASE_URL}/admins/login"
12+
request_url = f"{ADMIN_BASE_URL}/login"
1413
response = await session.post(request_url, json=payload)
1514
return ResponseWrapper(response.status, await response.json())
1615

1716

1817
async def verify_token(token: str):
1918
headers = get_headers(token)
2019
async with aiohttp.ClientSession(headers=headers) as session:
21-
response = await session.post(f"{BASE_URL}/admins/verify_token")
20+
response = await session.post(f"{ADMIN_BASE_URL}/verify_token")
2221
return ResponseWrapper(response.status, await response.json())
2322

2423

2524
async def refresh_token(token: str):
2625
headers = get_headers(token)
2726
async with aiohttp.ClientSession(headers=headers) as session:
28-
response = await session.post(f"{BASE_URL}/admins/refresh_token")
27+
response = await session.post(f"{ADMIN_BASE_URL}/refresh_token")
2928
return ResponseWrapper(response.status, await response.json())
3029

3130

3231
async def logout(token: str):
3332
headers = get_headers(token)
3433
async with aiohttp.ClientSession(headers=headers) as session:
35-
response = await session.post(f"{BASE_URL}/admins/logout")
34+
response = await session.post(f"{ADMIN_BASE_URL}/logout")
3635
return ResponseWrapper(response.status, await response.json())
File renamed without changes.

0 commit comments

Comments
 (0)