完成自定义返回值的功能

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')) mock_data = get_overtime_ticket_status_tmp.get_json(cinema_obj, kwargs.get('request'))
else: else:
mock_data = get_overtime_ticket_status_tmp.get(cinema_obj, kwargs.get('request')) mock_data = get_overtime_ticket_status_tmp.get(cinema_obj, kwargs.get('request'))
print('mock_data', mock_data)
if mock_data is not None: if mock_data is not None:
print("this is none")
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
else: else:
return bypass(kwargs.get('request')) return bypass(kwargs.get('request'))
@ -45,24 +43,14 @@ def mock(_ip, _api, **kwargs):
def bypass(_r): def bypass(_r):
print('bypass') print('bypass')
print(_r.method, _r.path)
print(_r.GET)
print(_r.POST)
if _r.method == 'GET': if _r.method == 'GET':
req_url = ZZ_URL + _r.path req_url = ZZ_URL + _r.path
req_params = dict(_r.GET) req_params = dict(_r.GET)
print(req_url)
print(req_params)
response_dara = requests.get(req_url, params=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}) return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False})
if _r.method == 'POST': if _r.method == 'POST':
req_url = ZZ_URL + _r.path req_url = ZZ_URL + _r.path
req_params = dict(_r.GET) req_params = dict(_r.GET)
req_data = dict(_r.POST) 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) 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}) 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 * from mock.cinema_sql import *
ZZ_URL = 'https://zzcs.yinghezhong.com' ZZ_URL = 'https://zzcs.yinghezhong.com'
mock_config = dict()
json_data = dict()
# 用于将前端的接口名转换成后端的 # 用于将前端的接口名转换成后端的
api_dict = { api_dict = {
@ -38,7 +40,8 @@ def report_ticket(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.reportTicket is True: 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') return mock_service.mock(ip, 'reportTicket')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -50,7 +53,8 @@ def report_film_schedule(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.reportFilmSchedule is True: 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') return mock_service.mock(ip, 'reportFilmSchedule')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -62,7 +66,8 @@ def upload_screen_seat_info(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.uploadScreenSeatInfo is True: 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') return mock_service.mock(ip, 'uploadScreenSeatInfo')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -74,6 +79,8 @@ def download_film_info(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.downloadFilmInfo is True: if mock_service_switch.downloadFilmInfo is True:
if customer_json := json_data.get('downloadFilmInfo'):
return customer_json
return mock_service.mock(ip, 'downloadFilmInfo') return mock_service.mock(ip, 'downloadFilmInfo')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -84,6 +91,8 @@ def get_cinema_info(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.getCinemaInfo is True: if mock_service_switch.getCinemaInfo is True:
if customer_json := json_data.get('getCinemaInfo'):
return customer_json
return mock_service.mock(ip, 'getCinemaInfo') return mock_service.mock(ip, 'getCinemaInfo')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -94,6 +103,8 @@ def get_screen_info(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.getScreenInfo is True: if mock_service_switch.getScreenInfo is True:
if customer_json := json_data.get('getScreenInfo'):
return customer_json
return mock_service.mock(ip, 'getScreenInfo') return mock_service.mock(ip, 'getScreenInfo')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -106,8 +117,8 @@ def get_overtime_ticket_status(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.getOvertimeTicketStatus is True: if mock_service_switch.getOvertimeTicketStatus is True:
r = mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) if customer_json := json_data.get('getOvertimeTicketStatus'):
print('r', r) return customer_json
return mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) return mock_service.mock(ip, 'getOvertimeTicketStatus', request=request)
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -119,6 +130,8 @@ def valid_error(request):
ip = request.META.get('REMOTE_ADDR') ip = request.META.get('REMOTE_ADDR')
mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() mock_service_switch = ZZMockModel.objects.filter(ip=ip).first()
if mock_service_switch.validError is True: if mock_service_switch.validError is True:
if customer_json := json_data.get('validError'):
return customer_json
return mock_service.mock(ip, 'validError') return mock_service.mock(ip, 'validError')
else: else:
return mock_service.bypass(request) return mock_service.bypass(request)
@ -228,11 +241,15 @@ def set_overtime_config(request):
@csrf_exempt @csrf_exempt
def enable_mock(request): def enable_mock(request):
ip = request.GET.get('ip') ip = request.GET.get('ip')
req_mock_config = json.loads(request.body)['mock_config'] req = json.loads(request.body)
mock_config = dict() req_mock_config = req['mock_config']
req_json_data = req['json_data']
for k, v in req_mock_config.items(): for k, v in req_mock_config.items():
mock_config[api_dict[k]] = v mock_config[api_dict[k]] = v
for k, v in req_json_data.items():
json_data[api_dict[k]] = v
print(mock_config) print(mock_config)
print(json_data)
server_ip = get_local_ip() server_ip = get_local_ip()
current_host = db(ip, GET_ZZ_PLATFORM_HOST_SQL)['data'][0]['cinema_common_info_val'] 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': if current_host == 'https://zzcs.yinghezhong.com' or current_host == 'https://dy.yinghezhong.com':

Loading…
Cancel
Save