Files
Django/verify_fixes.py

50 lines
1.4 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
print('1. JWT Token 生成成功')
auth = JWTAuthentication()
request = Mock()
request.META = {'HTTP_AUTHORIZATION': f'Bearer {access}'}
request._request = request
validated_user, _ = auth.authenticate(request)
print(f' JWT 验证成功: {validated_user.UserName}')
# 2. yonghuid 兼容属性
print(f'2. yonghuid: {u.yonghuid}')
# 3. dashou_profile
dp = u.dashou_profile
print(f'3. dashou_profile: {dp}')
# 4. shoujihao_renzheng
print(f'4. shoujihao_renzheng: {u.shoujihao_renzheng}')
# 5. user_type
print(f'5. user_type: {u.user_type}')
# 6. User.query.get(UserUID=...)
u2 = User.query.get(UserUID=u.UserUID)
print(f'6. User.query.get(UserUID=...) OK: {u2.UserName}')
# 7. user.id
print(f'7. user.id: {u.id}, bool: {bool(u.id)}')
# 8. has_role
print(f'8. has_role(dashou): {u.has_role("dashou")}')
print()
print('所有兼容性测试通过!')