## 还车坐标(实测结论:上游只认 GCJ02,WGS84 偏差约 500 米必被拒) - 新增 park_area.py:parkeArea 多边形判定 + 最近停车区吸附; 自动还车在发送前就对齐坐标,不再拿同一个「不在停车区」的点重试三次 - 入口统一 WGS84 -> GCJ02(routes.rental.to_upstream_coords); 手动还车 / 临时锁车 / 共享还车一并转换,本地订单起终点与楼栋标签随之修正 - is_disable 语义按实测纠正:1=启用、2=停用(原来判反,22 块启用区全被丢弃) - 停车区读取优先用用户凭据,避免全局 token 失效后吸附静默失效 - 修复「订单信息不存在」(204010) 被当成还车成功;状态兜底再按车牌确认 ## 前端 - 车辆卡片改为左右两栏:左「距你 N 米 / 步行 N 分钟」,右「电量 / 状态」; 未定位时左栏隐藏,380px 断点防止挤压换行 - 停用停车区不再绘制(原来还把启用区画成灰色) ## 测试 - 新增 tests/test_park_area.py(20 条);全量 121 pytest + 26 node 通过
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from flask import Flask
|
|
|
|
from routes import rental
|
|
|
|
|
|
class OrderControlTests(unittest.TestCase):
|
|
def setUp(self):
|
|
app = Flask(__name__)
|
|
app.secret_key = "test"
|
|
app.register_blueprint(rental.bp)
|
|
self.client = app.test_client()
|
|
|
|
def test_temporary_unlock_uses_record_open_without_creating_order(self):
|
|
with patch.object(rental, "get_current_user", return_value={"id": 7}), \
|
|
patch.object(rental, "request_with_user_auth", return_value={
|
|
"rtn_code": 0, "data": {"accepted": True}
|
|
}) as upstream:
|
|
response = self.client.post("/api/order/temp_unlock", json={"order_id": "9001"})
|
|
|
|
self.assertEqual(0, response.get_json()["rtn_code"])
|
|
upstream.assert_called_once_with(
|
|
7, "POST", "/record/open", data={"order_id": "9001"}
|
|
)
|
|
|
|
def test_temporary_lock_uses_return_location_and_does_not_finish_order(self):
|
|
upstream_responses = [
|
|
{"rtn_code": 0, "parkNoShow": False},
|
|
{"success": True},
|
|
{"rtn_code": 0, "data": {"accepted": True}},
|
|
]
|
|
with patch.object(rental, "get_current_user", return_value={"id": 7}), \
|
|
patch.object(rental, "get_user_display_name", return_value="tester"), \
|
|
patch.object(rental, "request_with_user_auth", side_effect=upstream_responses) as upstream:
|
|
response = self.client.post("/api/order/temp_lock", json={
|
|
"order_id": "9001", "code": "50001",
|
|
"latitude": 36.671, "longitude": 116.981,
|
|
})
|
|
|
|
self.assertEqual(0, response.get_json()["rtn_code"])
|
|
# 浏览器上报的是 WGS84,入口会先转成 GCJ02 再发给上游(实测上游只认 GCJ02)
|
|
exp_lat, exp_lng = rental.to_upstream_coords(36.671, 116.981)
|
|
self.assertFalse(exp_lng == 116.981) # 确实转过
|
|
self.assertEqual([
|
|
((7, "POST", "/record/checkLocation"), {
|
|
"data": {"longitude": exp_lng, "latitude": exp_lat,
|
|
"bicycleCode": "50001"}
|
|
}),
|
|
((7, "POST", "/project/coordinate"), {
|
|
"data": {"order_id": "9001", "code": "50001"}
|
|
}),
|
|
((7, "POST", "/record/close"), {
|
|
"data": {"order_id": "9001", "end_longitude": exp_lng,
|
|
"end_latitude": exp_lat}
|
|
}),
|
|
], [(call.args, call.kwargs) for call in upstream.call_args_list])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|