tfse-admin-api-v0.2/Test/TestRoute.py

80 lines
2.7 KiB
Python

from flask import Blueprint, request
from Test.TestImpl import CompanyAuthImpl, CompanyIndexImpl
from Utils.ErrorUtil import ReturnConditionCheckFailed
from common.APIAuth import api_secret
test_route = Blueprint('test', __name__)
@test_route.route('/enterprise_certification', methods=['POST'])
@api_secret
def enterprise_certification():
"""测试用企业认证"""
try:
company_auth = CompanyAuthImpl()
company_auth.cid = request.json['cid']
company_auth.VerifyInfo().name = request.json['company']
company_auth.VerifyInfo().code = request.json['code']
company_auth.VerifyInfo().legal_person = request.json['legal_person']
info = company_auth.enterprise_certification()
return info
except ReturnConditionCheckFailed as e:
e.log_error()
return {"info": e.failed_info}, e.status_code
except KeyError:
return {"info": "参数异常"}, 400
@test_route.route('/change_verified', methods=['GET'])
@api_secret
def change_verified():
"""企业认证状态修改"""
try:
company_auth = CompanyAuthImpl()
company_auth.cid = request.args['cid']
company_auth.change_verified()
return {"info": "执行成功"}, 200
except ReturnConditionCheckFailed as e:
e.log_error()
return {"info": e.failed_info}, e.status_code
except KeyError:
return {"info": "参数异常"}, 400
@test_route.route('/generate_rid_information', methods=['POST'])
@api_secret
def generate_information():
"""根据rid生成企业主页信息"""
try:
company_index = CompanyIndexImpl()
company_index.rid = request.json['rid']
company_index.project = request.json['project']
info = company_index.generate_homepage()
return info
except ReturnConditionCheckFailed as e:
e.log_error()
return {"info": e.failed_info}, e.status_code
except KeyError:
return {"info": "参数异常"}, 400
@test_route.route('/new_company', methods=['POST'])
@api_secret
def new_company_route():
"""新增一家测试企业"""
try:
company_auth = CompanyAuthImpl()
company_auth.email = request.json['email']
company_auth.name = request.json['company']
company_auth.VerifyInfo().name = request.json['company']
company_auth.VerifyInfo().code = request.json['code']
company_auth.VerifyInfo().legal_person = request.json['legal_person']
company_auth.company_register()
info = company_auth.enterprise_certification()
return info
except ReturnConditionCheckFailed as e:
e.log_error()
return {"info": e.failed_info}, e.status_code
except KeyError:
return {"info": "参数异常"}, 400