29 lines
1.3 KiB
Python
29 lines
1.3 KiB
Python
|
|
from election_data.donations import download_url, parse_summary
|
||
|
|
|
||
|
|
HEADER = (
|
||
|
|
"序號,擬參選人,選舉名稱,申報序號,個人捐贈收入,營利事業捐贈收入,政黨捐贈收入,人民團體捐贈收入,"
|
||
|
|
"匿名捐贈收入,其他收入,收入小計,人事費用支出,宣傳支出,租用宣傳車輛支出,租用競選辦事處支出,集會支出,"
|
||
|
|
"交通旅運支出,雜支支出,返還捐贈支出,繳庫支出,公共關係費用支出,支出小計\n"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_parse_summary_reads_totals_and_breakdown() -> None:
|
||
|
|
row = (
|
||
|
|
"1,王小明,111年測試市長選舉,首次申報,100.00,200.00,0.00,0.00,1.00,0.00,301.00,"
|
||
|
|
"10,250,0,20,5,0,0,0,0,0,285.00\n"
|
||
|
|
)
|
||
|
|
[c] = parse_summary(HEADER + row)
|
||
|
|
assert c.name == "王小明"
|
||
|
|
assert c.income == 301
|
||
|
|
assert c.spending == 285
|
||
|
|
assert c.incomeBreakdown["business"] == 200
|
||
|
|
assert c.spendingBreakdown["advertising"] == 250
|
||
|
|
assert c.spendingBreakdown["offices"] == 20
|
||
|
|
|
||
|
|
|
||
|
|
def test_download_url_encodes_chinese_names() -> None:
|
||
|
|
url = download_url("111年直轄市市長選舉", "桃園市")
|
||
|
|
assert url.startswith("https://ardata.cy.gov.tw/api/v1/Search/download?")
|
||
|
|
assert "ElectionArea=%E6%A1%83%E5%9C%92%E5%B8%82" in url
|
||
|
|
assert "DownloadType=3" in url
|