Initial commit: TradeMate 外贸小助手 MVP
项目结构: - backend/ Python FastAPI 后端 - uni-app/ uni-app跨端前端 - docs/ 设计文档 - docker-compose.yml Docker编排 - nginx/scripts/systemd 运维配置 已完成功能: - 用户认证 (JWT) - 智能翻译 + 回复建议 - 营销素材生成 - 客户管理 + 沉默检测 - 报价单管理 - 产品库管理 - 汇率换算 - 推送通知 (uni-push) - WhatsApp Webhook框架 - Celery定时任务
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import pytest
|
||||
from app.core.security import (
|
||||
hash_password,
|
||||
verify_password,
|
||||
create_access_token,
|
||||
create_refresh_token,
|
||||
decode_token,
|
||||
)
|
||||
|
||||
|
||||
class TestSecurity:
|
||||
def test_hash_password(self):
|
||||
pwd = "test123456"
|
||||
hashed = hash_password(pwd)
|
||||
assert hashed != pwd
|
||||
assert verify_password(pwd, hashed)
|
||||
|
||||
def test_verify_password_wrong(self):
|
||||
pwd = "test123456"
|
||||
hashed = hash_password(pwd)
|
||||
assert not verify_password("wrongpassword", hashed)
|
||||
|
||||
def test_create_access_token(self):
|
||||
data = {"sub": "test-user-id", "tier": "free"}
|
||||
token = create_access_token(data)
|
||||
assert token is not None
|
||||
assert isinstance(token, str)
|
||||
|
||||
def test_decode_token_valid(self):
|
||||
data = {"sub": "test-user-id", "tier": "pro"}
|
||||
token = create_access_token(data)
|
||||
decoded = decode_token(token)
|
||||
assert decoded is not None
|
||||
assert decoded["sub"] == "test-user-id"
|
||||
assert decoded["tier"] == "pro"
|
||||
|
||||
def test_decode_token_invalid(self):
|
||||
decoded = decode_token("invalid-token")
|
||||
assert decoded is None
|
||||
|
||||
def test_create_refresh_token(self):
|
||||
data = {"sub": "test-user-id"}
|
||||
token = create_refresh_token(data)
|
||||
assert token is not None
|
||||
decoded = decode_token(token)
|
||||
assert decoded is not None
|
||||
assert decoded["type"] == "refresh"
|
||||
Reference in New Issue
Block a user