Files
Django/verify_fixes.py
2026-06-17 23:02:35 +08:00

54 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""验证所有兼容性修复"""
import os; os.environ['DJANGO_SETTINGS_MODULE']='a_long_dianjing.settings'
import django; django.setup()
from gvsdsdk.models import User
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework_simplejwt.authentication import JWTAuthentication
from unittest.mock import Mock
u = User.objects.filter(UserName__isnull=False).first()
print(f'用户: {u.UserName}, UserUID: {u.UserUID}')
# 1. JWT 认证
refresh = RefreshToken.for_user(u)
access = refresh.access_token
auth = JWTAuthentication()
request = Mock()
request.META = {'HTTP_AUTHORIZATION': f'Bearer {access}'}
request._request = request
validated_user, _ = auth.authenticate(request)
print(f'1. JWT: {validated_user.UserName}')
# 2. 兼容属性
print(f'2. yonghuid: {u.yonghuid}')
print(f' phone: {u.phone}')
print(f' avatar: {u.avatar}')
print(f' ip: {u.ip}')
print(f' last_login_time: {u.last_login_time}')
print(f' shoujihao_renzheng: {u.shoujihao_renzheng}')
print(f' zhifu: {u.zhifu}')
print(f' skzhanghao: {u.skzhanghao}')
# 3. ORM 查询
u2 = User.query.get(UserUID=u.UserUID)
print(f'3. User.query.get(UserUID=): {u2.UserName}')
u3 = User.query.filter(OpenID=u.OpenID).first()
print(f' User.query.filter(OpenID=): {u3.UserName}')
u4 = User.query.filter(Phone=u.Phone).first() if u.Phone else None
print(f' User.query.filter(Phone=): {u4.UserName if u4 else "N/A"}')
# 4. user_type
print(f'4. user_type: {u.user_type}')
# 5. has_role
print(f'5. has_role(dashou): {u.has_role("dashou")}')
# 6. dashou_profile
dp = u.dashou_profile
print(f'6. dashou_profile: {dp}')
print('\n所有测试通过!')