完成自定义返回值的功能

main
roger_mac 11 months ago
parent 9ffc3c764e
commit 20f74288d4
  1. 12
      mock/utils/mock_service.py
  2. 31
      mock/views.py

@ -32,9 +32,7 @@ def mock(_ip, _api, **kwargs):
mock_data = get_overtime_ticket_status_tmp.get_json(cinema_obj, kwargs.get('request'))
else:
mock_data = get_overtime_ticket_status_tmp.get(cinema_obj, kwargs.get('request'))
print('mock_data', mock_data)
if mock_data is not None:
print("this is none")
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
else:
return bypass(kwargs.get('request'))
@ -45,24 +43,14 @@ def mock(_ip, _api, **kwargs):
def bypass(_r):
print('bypass')
print(_r.method, _r.path)
print(_r.GET)
print(_r.POST)
if _r.method == 'GET':
req_url = ZZ_URL + _r.path
req_params = dict(_r.GET)
print(req_url)
print(req_params)
response_dara = requests.get(req_url, params=req_params)
print(response_dara.json())
return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False})
if _r.method == 'POST':
req_url = ZZ_URL + _r.path
req_params = dict(_r.GET)
req_data = dict(_r.POST)
print(req_url)
print(req_params)
print(req_data)
response_dara = requests.post(req_url, params=req_params, data=req_data)
print(response_dara.json())
return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False})

@ -16,6 +16,8 @@ from mock.mock_templates import *
from mock.cinema_sql import *
ZZ_URL = 'https://zzcs.yinghezhong.com'
mock_config = dict()
json_data = dict()
# 用于将前端的接口名转换成后端的
api_dict = {
@ -38,7 +40,8 @@ def report_ticket(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.reportTicket is True:
mock_service.bypass(request)
if customer_json := json_data.get('reportTicket'):
return customer_json
return mock_service.mock(ip, 'reportTicket')
else:
return mock_service.bypass(request)
@ -50,7 +53,8 @@ def report_film_schedule(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.reportFilmSchedule is True:
mock_service.bypass(request)
if customer_json := json_data.get('reportFilmSchedule'):
return customer_json
return mock_service.mock(ip, 'reportFilmSchedule')
else:
return mock_service.bypass(request)
@ -62,7 +66,8 @@ def upload_screen_seat_info(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.uploadScreenSeatInfo is True:
mock_service.bypass(request)
if customer_json := json_data.get('uploadScreenSeatInfo'):
return customer_json
return mock_service.mock(ip, 'uploadScreenSeatInfo')
else:
return mock_service.bypass(request)
@ -74,6 +79,8 @@ def download_film_info(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.downloadFilmInfo is True:
if customer_json := json_data.get('downloadFilmInfo'):
return customer_json
return mock_service.mock(ip, 'downloadFilmInfo')
else:
return mock_service.bypass(request)
@ -84,6 +91,8 @@ def get_cinema_info(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.getCinemaInfo is True:
if customer_json := json_data.get('getCinemaInfo'):
return customer_json
return mock_service.mock(ip, 'getCinemaInfo')
else:
return mock_service.bypass(request)
@ -94,6 +103,8 @@ def get_screen_info(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.getScreenInfo is True:
if customer_json := json_data.get('getScreenInfo'):
return customer_json
return mock_service.mock(ip, 'getScreenInfo')
else:
return mock_service.bypass(request)
@ -106,8 +117,8 @@ def get_overtime_ticket_status(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.getOvertimeTicketStatus is True:
r = mock_service.mock(ip, 'getOvertimeTicketStatus', request=request)
print('r', r)
if customer_json := json_data.get('getOvertimeTicketStatus'):
return customer_json
return mock_service.mock(ip, 'getOvertimeTicketStatus', request=request)
else:
return mock_service.bypass(request)
@ -119,6 +130,8 @@ def valid_error(request):
ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.validError is True:
if customer_json := json_data.get('validError'):
return customer_json
return mock_service.mock(ip, 'validError')
else:
return mock_service.bypass(request)
@ -228,11 +241,15 @@ def set_overtime_config(request):
@csrf_exempt
def enable_mock(request):
ip = request.GET.get('ip')
req_mock_config = json.loads(request.body)['mock_config']
mock_config = dict()
req = json.loads(request.body)
req_mock_config = req['mock_config']
req_json_data = req['json_data']
for k, v in req_mock_config.items():
mock_config[api_dict[k]] = v
for k, v in req_json_data.items():
json_data[api_dict[k]] = v
print(mock_config)
print(json_data)
server_ip = get_local_ip()
current_host = db(ip, GET_ZZ_PLATFORM_HOST_SQL)['data'][0]['cinema_common_info_val']
if current_host == 'https://zzcs.yinghezhong.com' or current_host == 'https://dy.yinghezhong.com':

Loading…
Cancel
Save