76 lines
3.2 KiB
Python
76 lines
3.2 KiB
Python
"""surugaya_common 共享契约回归测试:URL 构造与价格解析必须与迁移前字面量/行为一致。"""
|
|
|
|
from surugaya_common import browser_profile
|
|
from surugaya_common.parse_utils import format_japanese_price
|
|
from surugaya_common.urls import (
|
|
BASE_URL,
|
|
CARGO_DETAIL_URL,
|
|
MYPAGE_URL,
|
|
product_detail_url,
|
|
trade_detail_url,
|
|
)
|
|
|
|
|
|
class TestUrls:
|
|
def test_literals_match_pre_migration(self):
|
|
assert BASE_URL == "https://www.suruga-ya.jp"
|
|
assert CARGO_DETAIL_URL == "https://www.suruga-ya.jp/cargo/detail"
|
|
assert MYPAGE_URL == "https://www.suruga-ya.jp/pcmypage"
|
|
|
|
def test_product_detail_url(self):
|
|
assert product_detail_url("128001234") == "https://www.suruga-ya.jp/product/detail/128001234"
|
|
assert (
|
|
product_detail_url("128001234", tenpo_cd="400496")
|
|
== "https://www.suruga-ya.jp/product/detail/128001234?tenpo_cd=400496"
|
|
)
|
|
# 空字符串 tenpo_cd 与未提供等价(与迁移前 if tenpo_cd 判断一致)
|
|
assert product_detail_url("128001234", tenpo_cd="") == "https://www.suruga-ya.jp/product/detail/128001234"
|
|
assert (
|
|
product_detail_url("128001234", tenpo_cd="400496", branch_number="0003")
|
|
== "https://www.suruga-ya.jp/product/detail/128001234?tenpo_cd=400496&branch_number=0003"
|
|
)
|
|
assert (
|
|
product_detail_url("128001234", branch_number="0003")
|
|
== "https://www.suruga-ya.jp/product/detail/128001234?branch_number=0003"
|
|
)
|
|
|
|
def test_trade_detail_url(self):
|
|
assert (
|
|
trade_detail_url("T123456")
|
|
== "https://www.suruga-ya.jp/pcmypage/action_sell_search/detail?trade_code=T123456"
|
|
)
|
|
|
|
|
|
class TestFormatJapanesePrice:
|
|
def test_supported_formats(self):
|
|
assert format_japanese_price("600円 (税込)") == 600
|
|
assert format_japanese_price("1,250円") == 1250
|
|
assert format_japanese_price("¥ 3,000") == 3000
|
|
assert format_japanese_price("300") == 300
|
|
|
|
def test_empty_and_no_digit(self):
|
|
assert format_japanese_price(None) == 0
|
|
assert format_japanese_price("") == 0
|
|
assert format_japanese_price("税込") == 0
|
|
|
|
|
|
class TestBrowserProfile:
|
|
def test_fingerprint_consistency(self):
|
|
# UA / 语言 / 时区必须保持日语环境自洽,且与迁移前两仓字面量一致
|
|
assert browser_profile.DEFAULT_USER_AGENT == (
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
"Chrome/124.0.0.0 Safari/537.36"
|
|
)
|
|
assert browser_profile.LOCALE == "ja-JP"
|
|
assert browser_profile.TIMEZONE_ID == "Asia/Tokyo"
|
|
assert browser_profile.NAVIGATOR_LANGUAGES == ("ja-JP", "ja", "en-US", "en")
|
|
assert browser_profile.ACCEPT_LANGUAGE.startswith("ja-JP,ja;")
|
|
assert browser_profile.DEFAULT_PAGE_HEADERS["Accept-Language"] == browser_profile.ACCEPT_LANGUAGE
|
|
|
|
def test_stealth_launch_args_returns_copy(self):
|
|
args = browser_profile.stealth_launch_args()
|
|
assert "--disable-blink-features=AutomationControlled" in args
|
|
args.append("--extra")
|
|
assert "--extra" not in browser_profile.stealth_launch_args()
|