Skip to content

Commit

Permalink
chore(FasterRunner): upgrade django version from 2.2.28 to 4.1, repla…
Browse files Browse the repository at this point in the history
…ce mysqlclient by pymysql (#171)

* chore(FasterRunner): upgrade django version from 2.2.28 to 4.1, replace mysqlclient by pymysql

* fix(requirements): add drf-yasg deps

* fix(requirements): add drf-yasg deps

* fix(requirements): add pymysql

* fix: collect static cannot import name 'ugettext_lazy'
  • Loading branch information
lihuacai168 authored Feb 15, 2024
1 parent 709ac6d commit 6a57313
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 23 deletions.
6 changes: 6 additions & 0 deletions FasterRunner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pymysql

# 替换mysqlclient
pymysql.version_info = (1, 4, 6, "final", 0) # 修改版本号为兼容版本
pymysql.install_as_MySQLdb()

2 changes: 1 addition & 1 deletion FasterRunner/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def authenticate(self, request):
supplied using JWT-based authentication. Otherwise returns `None`.
"""
# jwt_value = request.query_params.get("token", None)
jwt_value = request.META.get('HTTP_AUTHORIZATION', None)
jwt_value = request.headers.get('authorization', None)
try:
payload = jwt_decode_handler(jwt_value)
except jwt.ExpiredSignature:
Expand Down
11 changes: 10 additions & 1 deletion FasterRunner/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
# @File: __init__.py.py
# @Time : 2019/6/14 17:05
# @Email: [email protected]
# @Software: PyCharm
# @Software: PyCharm

# 兼容已经移除的方法
import django
from django.utils.encoding import smart_str
django.utils.encoding.smart_text = smart_str

from django.utils.translation import gettext_lazy
django.utils.translation.ugettext = gettext_lazy
django.utils.translation.ugettext_lazy = gettext_lazy
1 change: 0 additions & 1 deletion FasterRunner/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = False

Expand Down
15 changes: 7 additions & 8 deletions FasterRunner/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.conf.urls import url
from django.urls import path, include, re_path
from rest_framework.routers import DefaultRouter

Expand Down Expand Up @@ -47,21 +46,21 @@
urlpatterns = [
path(r"login", obtain_jwt_token),
path('admin/', admin.site.urls),
url(r'^docs/', schema_view, name="docs"),
url(r'^accounts/', include('rest_framework.urls',)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework_api_auth')),
# re_path(r'^docs/', schema_view, name="docs"),
path('accounts/', include('rest_framework.urls',)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework_api_auth')),
path('api/user/', include('fastuser.urls')),
path('api/fastrunner/', include('fastrunner.urls')),
path('api/system/', include(system_router.urls)),

# 执行定时任务
# TODO 需要增加触发检验,暂时关闭触发入口
# re_path(r'^run_all_auto_case/$', run_all_auto_case.run_all_auto_case, name='run_all_auto_case'),
re_path(r'^get_report_url/$', run_all_auto_case.get_report_url, name='get_report_url'),
path('get_report_url/', run_all_auto_case.get_report_url, name='get_report_url'),

# swagger
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),

]
4 changes: 2 additions & 2 deletions fastrunner/utils/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def process_response(self, request, response):
else:
user = request.user

ip: str = request.META.get("HTTP_X_FORWARDED_FOR", request.META.get("REMOTE_ADDR"))
ip: str = request.headers.get("x-forwarded-for", request.META.get("REMOTE_ADDR"))
# 前端请求头没传project,就默认为0
project = request.META.get("HTTP_PROJECT", 0)
project = request.headers.get("project", 0)

url: str = request.path
# 去除测试报告页字体相关的访问
Expand Down
4 changes: 3 additions & 1 deletion fastuser/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class UserAdmin(BaseUserAdmin):
)
filter_horizontal = ('groups',)

@admin.display(
description='所属分组'
)
def belong_groups(self, obj):
return ", ".join([g.name for g in obj.groups.all()])

belong_groups.short_description = '所属分组'
4 changes: 2 additions & 2 deletions fastuser/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.urls import path,re_path
from django.urls import path
from fastuser import views
from fastrunner.views import timer_task

Expand All @@ -23,5 +23,5 @@
# path('register/', views.RegisterView.as_view()),
path('login/', views.LoginView.as_view()),
path('list/', views.UserView.as_view()),
re_path(r'^auto_run_testsuite_pk/$', timer_task.auto_run_testsuite_pk, name='auto_run_testsuite_pk'),
path('auto_run_testsuite_pk/', timer_task.auto_run_testsuite_pk, name='auto_run_testsuite_pk'),
]
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ contextvars==2.4
coreapi==2.3.3
coreschema==0.0.4
DingtalkChatbot==1.3.0
Django==2.2.28
Django==4.1
django-celery-beat
django-cors-headers==2.4.0
django-cors-headers==4.3.1
django-jsonfield==1.4.0
django-model-utils==4.0.0
django-rest-swagger==2.2.0
django-simpleui==2020.7
django-simpleui==2023.12.12
django-utils-six==2.0
djangorestframework~=3.8.2
djangorestframework==3.14.0
djangorestframework-jwt==1.11.0
drf-yasg==1.17.1
drf-yasg==1.21.7
packaging==23.2
har2case==0.3.1
# HttpRunner==1.5.15
idna==2.8
Expand All @@ -34,9 +35,8 @@ Jinja2==2.10.3
# kombu
loguru==0.5.1
MarkupSafe==1.1.1
mysqlclient==2.0.1
#mysqlclient==2.0.1
openapi-codec==1.3.2
packaging==20.4
PyJWT==1.7.1
pyparsing==2.4.7
python-dotenv==0.10.3
Expand Down Expand Up @@ -71,3 +71,4 @@ django-log-request-id~=2.0.0
gevent==22.10.2
django-filter~=2.4.0
django-auth-ldap==2.3.0
pymysql==1.1.0

0 comments on commit 6a57313

Please sign in to comment.