Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions backend/app/admin/tests/api_v1/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
# -*- coding: utf-8 -*-
from starlette.testclient import TestClient

from backend.core.conf import settings


def test_logout(client: TestClient, token_headers: dict[str, str]) -> None:
response = client.post(f'{settings.FASTAPI_API_V1_PATH}/auth/logout', headers=token_headers)
response = client.post('/auth/logout', headers=token_headers)
assert response.status_code == 200
assert response.json()['code'] == 200
23 changes: 17 additions & 6 deletions backend/app/admin/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Dict, Generator
from typing import Generator

import pytest

from starlette.testclient import TestClient

from backend.app.admin.tests.utils.db_mysql import override_get_db
from backend.app.admin.tests.utils.get_headers import get_token_headers
from backend.core.conf import settings
from backend.database.db_mysql import get_db
from backend.main import app

# 重载数据库
app.dependency_overrides[get_db] = override_get_db


# Test user
# Test data
PYTEST_USERNAME = 'admin'
PYTEST_PASSWORD = '123456'
PYTEST_BASE_URL = f'http://testserver{settings.FASTAPI_API_V1_PATH}'


@pytest.fixture(scope='module')
def client() -> Generator:
with TestClient(app) as c:
with TestClient(app, base_url=PYTEST_BASE_URL) as c:
yield c


@pytest.fixture(scope='module')
def token_headers(client: TestClient) -> Dict[str, str]:
return get_token_headers(client=client, username=PYTEST_USERNAME, password=PYTEST_PASSWORD)
def token_headers(client: TestClient) -> dict[str, str]:
params = {
'username': PYTEST_USERNAME,
'password': PYTEST_PASSWORD,
}
response = client.post('/auth/login/swagger', params=params)
response.raise_for_status()
token_type = response.json()['token_type']
access_token = response.json()['access_token']
headers = {'Authorization': f'{token_type} {access_token}'}
return headers
4 changes: 1 addition & 3 deletions backend/app/admin/tests/utils/db_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from backend.core.conf import settings
from backend.database.db_mysql import create_engine_and_session

TEST_SQLALCHEMY_DATABASE_URL = (
_, test_async_db_session = create_engine_and_session(
f'mysql+asyncmy://{settings.MYSQL_USER}:{settings.MYSQL_PASSWORD}@{settings.MYSQL_HOST}:'
f'{settings.MYSQL_PORT}/{settings.MYSQL_DATABASE}_test?charset={settings.MYSQL_CHARSET}'
)

_, test_async_db_session = create_engine_and_session(TEST_SQLALCHEMY_DATABASE_URL)


async def override_get_db() -> AsyncSession:
"""session 生成器"""
Expand Down
17 changes: 0 additions & 17 deletions backend/app/admin/tests/utils/get_headers.py

This file was deleted.

60 changes: 30 additions & 30 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,59 @@ readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.10,<3.13"
dependencies = [
"alembic>=1.13.0",
"alembic>=1.14.0",
"asgiref>=3.8.0",
"asyncmy==0.2.9",
"bcrypt==4.0.1",
"casbin==1.34.0",
"casbin_async_sqlalchemy_adapter==1.4.0",
"asyncmy>=0.2.9",
"bcrypt>=4.2.0",
"casbin>=1.36.0",
"casbin_async_sqlalchemy_adapter>=1.6.0",
"celery==5.3.6",
"cryptography==41.0.7",
"fast-captcha==0.3.2",
"cryptography>=43.0.0",
"fast-captcha>=0.3.2",
"fastapi[all]==0.111.0",
"fastapi-limiter==0.1.6",
"fastapi-limiter>=0.1.6",
"fastapi-pagination==0.12.13",
"gunicorn==21.2.0",
"httpx==0.25.2",
"itsdangerous==2.1.2",
"loguru==0.7.2",
"msgspec==0.18.5",
"passlib==1.7.4",
"path==15.1.2",
"phonenumbers==8.13.27",
"psutil==5.9.6",
"pydantic==2.9.1",
"pytest==7.2.2",
"pytest-pretty==1.2.0",
"python-jose==3.3.0",
"redis[hiredis]==5.1.0",
"SQLAlchemy==2.0.30",
"itsdangerous>=2.2.0",
"loguru>=0.7.2",
"msgspec>=0.18.6",
"passlib>=1.7.4",
"path==17.0.0",
"phonenumbers>=8.13.0",
"psutil>=6.0.0",
"pydantic>=2.9.1",
"python-jose>=3.3.0",
"redis[hiredis]>=5.2.0",
"SQLAlchemy>=2.0.30",
"user-agents==2.2.0",
"uvicorn[standard]==0.29.0",
"XdbSearchIP==1.0.2",
"XdbSearchIP>=1.0.2",
"fastapi_oauth20>=0.0.1a2",
"flower==2.0.1",
"flower>=2.0.0",
"sqlalchemy-crud-plus==1.6.0",
"jinja2==3.1.4",
"aiofiles==24.1.0",
"jinja2>=3.1.4",
"aiofiles>=24.1.0",
# When celery version < 6.0.0
# https://github.com/celery/celery/issues/7874
"celery-aio-pool==0.1.0rc6",
"celery-aio-pool==0.1.0rc7",
"asgi-correlation-id>=4.3.3",
"python-socketio[asyncio]>=5.11.4",
]

[dependency-groups]
dev = [
"pytest>=8.0.0",
"pytest-sugar>=1.0.0",
]
lint = [
"ruff>=0.7.0",
"pre-commit>=4.0.0",
]
server = [
"gunicorn==21.2.0",
"supervisor>=4.2.5",
"wait-for-it>=2.2.2",
]

[tool.uv]
package = false
python-downloads = "manual"
default-groups = ['lint']
default-groups = ["dev", "lint"]
33 changes: 16 additions & 17 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# This file was autogenerated by uv via the following command:
# uv export --directory backend -o requirements.txt --no-hashes
aiofiles==24.1.0
alembic==1.13.3
alembic==1.14.0
amqp==5.2.0
annotated-types==0.7.0
anyio==4.6.0
asgi-correlation-id==4.3.3
asgiref==3.8.1
async-timeout==4.0.3 ; python_full_version < '3.11.3'
asyncmy==0.2.9
attrs==24.2.0
bcrypt==4.0.1
bcrypt==4.2.0
bidict==0.23.1
billiard==4.2.1
casbin==1.34.0
casbin-async-sqlalchemy-adapter==1.4.0
casbin==1.36.3
casbin-async-sqlalchemy-adapter==1.6.0
celery==5.3.6
celery-aio-pool==0.1.0rc6
celery-aio-pool==0.1.0rc7
certifi==2024.8.30
cffi==1.17.1
cffi==1.17.1 ; platform_python_implementation != 'PyPy'
cfgv==3.4.0
click==8.1.7
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
colorama==0.4.6 ; sys_platform == 'win32' or platform_system == 'Windows'
cryptography==41.0.7
cryptography==43.0.3
distlib==0.3.9
dnspython==2.7.0
ecdsa==0.19.0
Expand All @@ -40,7 +39,6 @@ fastapi-pagination==0.12.13
filelock==3.16.1
flower==2.0.1
greenlet==3.1.1 ; platform_machine == 'AMD64' or platform_machine == 'WIN32' or platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'ppc64le' or platform_machine == 'win32' or platform_machine == 'x86_64'
gunicorn==21.2.0
h11==0.14.0
hiredis==3.0.0
httpcore==1.0.6
Expand All @@ -50,37 +48,37 @@ humanize==4.11.0
identify==2.6.1
idna==3.10
iniconfig==2.0.0
itsdangerous==2.1.2
itsdangerous==2.2.0
jinja2==3.1.4
kombu==5.4.2
loguru==0.7.2
mako==1.3.5
markdown-it-py==3.0.0
markupsafe==3.0.1
mdurl==0.1.2
msgspec==0.18.5
msgspec==0.18.6
nodeenv==1.9.1
orjson==3.10.7
packaging==24.1
passlib==1.7.4
path==15.1.2
path==17.0.0
phonenumbers==8.13.27
pillow==10.4.0
platformdirs==4.3.6
pluggy==1.5.0
pre-commit==4.0.1
prometheus-client==0.21.0
prompt-toolkit==3.0.48
psutil==5.9.6
psutil==6.1.0
pyasn1==0.6.1
pycparser==2.22
pycparser==2.22 ; platform_python_implementation != 'PyPy'
pydantic==2.9.1
pydantic-core==2.23.3
pydantic-extra-types==2.9.0
pydantic-settings==2.5.2
pygments==2.18.0
pytest==7.2.2
pytest-pretty==1.2.0
pytest==8.3.3
pytest-sugar==1.0.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-engineio==4.9.1
Expand All @@ -89,7 +87,7 @@ python-multipart==0.0.12
python-socketio==5.11.4
pytz==2024.2
pyyaml==6.0.2
redis==5.1.0
redis==5.2.0
rich==13.9.2
rsa==4.9
ruff==0.7.2
Expand All @@ -101,6 +99,7 @@ sniffio==1.3.1
sqlalchemy==2.0.30
sqlalchemy-crud-plus==1.6.0
starlette==0.37.2
termcolor==2.5.0
tomli==2.0.2 ; python_full_version < '3.11'
tornado==6.4.1
typer==0.12.5
Expand Down
Loading