Files
starRiverProperty/scripts/test-env/stub-person-service.py
反编译工作区 ffbc8614b4 fix(test): hardcode PersonFeignClient url to local stub for test env, add Ribbon comp-org route
- PersonFeignClient: add url=http://127.0.0.1:33011 to bypass Ribbon/Consul discovery
- application.properties: add ninca-common-component-organization.ribbon.listOfServers
- Add stub-person-service.py for simulating component-organization person/detail
  Returns PersonResult with floorList and organizationIds for policy testing
NOTE: PersonFeignClient url change is test-only, revert before production

Former-commit-id: ff9a9ed68ec81fc2de68cc74cd22edcf38b510cb
2026-05-03 14:44:53 +08:00

42 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Stub: PersonResult format — floorList is a top-level field in data"""
from http.server import HTTPServer, BaseHTTPRequestHandler
import json, sys
PERSON_DATA = {
"id": "1072908835884208128", "businessId": "2524639890ba4f2cba9ba1a4eeaa4015",
"personCode": "PC001", "name": "秦夏", "userName": "qinxia", "phone": "13666667067",
"organizationIds": ["488b8ad049bb43408a6fbcc50bcb89ac"],
"organizationNames": ["广发基金"],
"labelIds": [], "labelNames": [],
"floorList": ["605560541473144832", "605560541657694208", "605560542911791104"],
"defaultFloor": "605560541473144832",
"status": 0, "isDel": 0
}
class PersonStub(BaseHTTPRequestHandler):
def log_message(self, f, *a): print(f"[stub] {a}", file=sys.stderr)
def do_POST(self):
body_len = int(self.headers.get('Content-Length', 0))
body = json.loads(self.rfile.read(body_len)) if body_len > 0 else {}
if '/detail' in self.path:
resp = {"code": "00000000", "success": True, "message": "success", "data": PERSON_DATA}
else:
resp = {"code": "00000000", "success": True, "data": {"total": 0, "datas": []}}
self._json(resp)
def do_GET(self):
self._json({"status": "UP"})
def _json(self, data):
resp = json.dumps(data, ensure_ascii=False).encode()
self.send_response(200)
self.send_header('Content-Type', 'application/json;charset=utf-8')
self.send_header('Content-Length', str(len(resp)))
self.end_headers()
self.wfile.write(resp)
port = int(sys.argv[1]) if len(sys.argv) > 1 else 33011
HTTPServer(('127.0.0.1', port), PersonStub).serve_forever()