39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""city service 单元测试(回归 haveChild 尾部逗号导致恒为元组/恒 truthy 的 bug)。"""
|
|
import json
|
|
|
|
from modules.city import service as city_service
|
|
from modules.city.models import City
|
|
from modules.city.repository import city_repo
|
|
|
|
|
|
def _resp_body(resp):
|
|
return json.loads(resp.body)
|
|
|
|
|
|
def test_get_city_list_have_child_is_bool(fake_request, sqlite_db):
|
|
city_repo.create(
|
|
city_code="100000", area_code="100000", parent_code="0", zip_code="000000",
|
|
level=1, parent_id=0, name="北京市", short_name="北京", full_name="北京市",
|
|
pinyin="beijing", lng="116.4", lat="39.9",
|
|
)
|
|
fake_request.query_params = {"parent_id": 0}
|
|
|
|
resp = city_service.get_city_list(fake_request)
|
|
data = _resp_body(resp)["data"]
|
|
assert isinstance(data, list) and len(data) == 1
|
|
assert data[0]["haveChild"] is True
|
|
|
|
|
|
def test_get_city_list_leaf_have_child_false(fake_request, sqlite_db):
|
|
city_repo.create(
|
|
city_code="100000", area_code="100000", parent_code="0", zip_code="000000",
|
|
level=4, parent_id=0, name="某街道", short_name="街道", full_name="某街道",
|
|
pinyin="jiedao", lng="116.4", lat="39.9",
|
|
)
|
|
fake_request.query_params = {"parent_id": 0}
|
|
|
|
resp = city_service.get_city_list(fake_request)
|
|
data = _resp_body(resp)["data"]
|
|
assert isinstance(data, list) and len(data) == 1
|
|
assert data[0]["haveChild"] is False
|