AutoRpa/rpa_selection/tests/test_mapping.py

80 lines
2.3 KiB
Python

from __future__ import annotations
from search_yaoex import map_yaoex_products
from search_ybm import map_ybm_products
def test_yaoex_field_mapping_and_price_passthrough():
products = [
{
"spuCode": "SPU1",
"shortName": "阿莫西林",
"spec": "0.25g",
"price": 88.5,
"deadLine": "13",
"vendorName": "[自营] 广东壹号药业有限公司",
"stockCount": "40",
}
]
candidates = map_yaoex_products(products, user_id="123456")
assert len(candidates) == 1
item = candidates[0]
assert item.sku_id == "SPU1"
assert item.name == "阿莫西林"
assert item.spec == "0.25g"
assert item.price == 88.5
assert item.expiry_raw == "13"
assert item.vendor_norm == "广东壹号药业有限公司"
assert item.stock == 40.0
assert item.mall_name == "1号药城"
assert item.extra["raw"]["spuCode"] == "SPU1"
assert item.extra["stockCountDesc"] == ""
def test_ybm_field_mapping_zero_stock_price_is_zero():
rows = [
{
"skuId": "fallback",
"productInfo": {
"skuId": "SKU9",
"showName": "头孢",
"spec": "0.5g",
"price": 120,
"fob": 110,
"nearEffect": "14个月",
"shopName": "昆山亿方药业有限公司",
"availableQty": 0,
},
}
]
candidates = map_ybm_products(rows)
assert len(candidates) == 1
item = candidates[0]
assert item.sku_id == "SKU9"
assert item.name == "头孢"
assert item.price == 0
assert item.stock == 0.0
assert item.expiry_raw == "14个月"
assert item.mall_name == "药帮忙"
assert item.extra["raw"]["skuId"] == "SKU9"
def test_ybm_uses_fob_when_price_empty():
rows = [
{
"productInfo": {
"skuId": "SKU8",
"showName": "头孢",
"spec": "0.5g",
"price": "",
"fob": 77,
"nearEffect": "18",
"shopName": "湖北亿昊药业有限公司",
"availableQty": 12,
}
}
]
item = map_ybm_products(rows)[0]
assert item.price == 77.0
assert item.stock == 12.0