增加mock应用简单调试

main
RogerWork 11 months ago
parent 75642532e9
commit ac4be88ca0
  1. 3
      dingxin_toolbox_drf/settings.py
  2. 1
      dingxin_toolbox_drf/urls.py
  3. 0
      mock/__init__.py
  4. 3
      mock/admin.py
  5. 6
      mock/apps.py
  6. 0
      mock/migrations/__init__.py
  7. 3
      mock/models.py
  8. 3
      mock/tests.py
  9. 24
      mock/urls.py
  10. 27
      mock/views.py
  11. 11
      update/utils/get_version.py
  12. 8
      update/views.py

@ -26,7 +26,7 @@ SECRET_KEY = 'django-insecure-hfujy!ih1uvio_p^cfdj^%8juf_wdb@szu$t=aaacd)^(zf@b%
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ['*']
# Application definition # Application definition
@ -42,6 +42,7 @@ INSTALLED_APPS = [
'rest_framework.authtoken', # Token验证应用 'rest_framework.authtoken', # Token验证应用
'django_filters', 'django_filters',
'update', 'update',
'mock',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

@ -23,5 +23,6 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api-token-auth/', obtain_auth_token), path('api-token-auth/', obtain_auth_token),
path('update/', include('update.urls')), # cinema Update 备注 path('update/', include('update.urls')), # cinema Update 备注
path('', include('mock.urls')),
path('docs/', include_docs_urls(title='接口文档')), path('docs/', include_docs_urls(title='接口文档')),
] ]

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

@ -0,0 +1,6 @@
from django.apps import AppConfig
class MockConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'mock'

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

@ -0,0 +1,24 @@
"""
URL configuration for dingxin_toolbox_drf project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from mock.views import *
urlpatterns = [
# path('report/reportTicket/', report_ticket),
path('data/getCinemaInfo', get_cinema_info),
]

@ -0,0 +1,27 @@
from django.shortcuts import render
from django.http.response import JsonResponse
# Create your views here.
# 1、票房数据上报接口 POST /report/reportTicket
def report_ticket(request):
if request.method == 'POST':
print(request.headers)
print(request.body)
return JsonResponse({'status': 'success'})
# 数据下载
# 1、影片信息下载接口 GET /data/downloadFilmInfo
# 2、影院信息下载接口 GET /data/getCinemaInfo
def get_cinema_info(request):
print(request.headers)
print(request.body)
if request.method == 'GET':
print('getCinemaInfo')
print(request.headers)
print(request.body)
return JsonResponse({'status': 'success'})
# 3、影厅信息下载接口 GET /data/getScreenInfo

@ -4,6 +4,7 @@ from multiprocessing import cpu_count
from update.models import Cinema from update.models import Cinema
import queue import queue
import threading import threading
from django.utils import timezone
import datetime import datetime
@ -30,11 +31,11 @@ class GetVersion(object):
cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1 cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1
cinema_num = len(all_cinema_obj) cinema_num = len(all_cinema_obj)
self.th_num = cpu_num if cpu_num < cinema_num else cinema_num self.th_num = cpu_num if cpu_num < cinema_num else cinema_num
print(self.queue)
def main_process(self): def main_process(self):
print('main_process') print('main_process')
self.get_all_cinema() self.get_all_cinema()
while self.queue.qsize() > 0:
threads = [] threads = []
for i in range(self.th_num): for i in range(self.th_num):
t = threading.Thread(target=self.get_cinema_ver, args=(self.queue,)) t = threading.Thread(target=self.get_cinema_ver, args=(self.queue,))
@ -51,7 +52,6 @@ class GetVersion(object):
return return
else: else:
cinema_config = q.get() cinema_config = q.get()
print(cinema_config)
sql_str = "SELECT * FROM cinema_version;" sql_str = "SELECT * FROM cinema_version;"
ip = cinema_config.get('ip') ip = cinema_config.get('ip')
db_config = { db_config = {
@ -61,18 +61,17 @@ class GetVersion(object):
'database': 'cine', 'database': 'cine',
'connect_timeout': 5, 'connect_timeout': 5,
} }
print(db_config)
db_conn = pymysql.Connect(**db_config) db_conn = pymysql.Connect(**db_config)
db_cursor = db_conn.cursor(cursor=DictCursor) db_cursor = db_conn.cursor(cursor=DictCursor)
db_cursor.execute(sql_str) db_cursor.execute(sql_str)
res = db_cursor.fetchone() res = db_cursor.fetchone()
print(res)
update_data = { update_data = {
'sys_ver': res['server_version'], 'sys_ver': res['server_version'],
'client_ver': res['client_version'], 'client_ver': res['client_version'],
'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') # 'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
'update_time': timezone.now()
} }
print(update_data) print(ip, update_data, db_config)
cinema_obj = Cinema.objects.filter(ip=ip).update(**update_data) cinema_obj = Cinema.objects.filter(ip=ip).update(**update_data)

@ -1,6 +1,8 @@
from django.http import JsonResponse from django.http import JsonResponse
from django.db.models import Q from django.db.models import Q
from rest_framework import viewsets, permissions, status, filters from rest_framework import viewsets, permissions, status, filters
from rest_framework.filters import OrderingFilter
from update.models import Cinema from update.models import Cinema
from update.serializers import CinemaSerializer from update.serializers import CinemaSerializer
from rest_framework.views import APIView from rest_framework.views import APIView
@ -27,16 +29,18 @@ class CinemaViewSet(CacheResponseMixin, viewsets.ModelViewSet):
queryset = Cinema.objects.all() queryset = Cinema.objects.all()
serializer_class = CinemaSerializer serializer_class = CinemaSerializer
permission_classes = (permissions.IsAuthenticated,) permission_classes = (permissions.IsAuthenticated,)
filter_backends = (filters.SearchFilter, DjangoFilterBackend) filter_backends = (filters.SearchFilter, DjangoFilterBackend, OrderingFilter)
ordering_fields = ('ip', )
search_fields = ('sys_ver',) search_fields = ('sys_ver',)
# filter_fields = ('ip',) # filter_fields = ('ip',)
filterset_fields = ('ip',) filterset_fields = ('ip',)
GetVersion().main_process() GetVersion().main_process()
@action(methods=['get'], detail=False) @action(methods=['get'], detail=False)
@method_decorator(cache_page(60 * 1))
def refresh(self, request, *args, **kwargs): def refresh(self, request, *args, **kwargs):
GetVersion().main_process() GetVersion().main_process()
queryset = Cinema.objects.all() queryset = Cinema.objects.all().order_by('ip')
serializer = self.get_serializer(instance=queryset, many=True) serializer = self.get_serializer(instance=queryset, many=True)
return Response(serializer.data) return Response(serializer.data)

Loading…
Cancel
Save