import pytest
from lymcp import api
@pytest.mark.asyncio
async def test_get_stat_request():
req = api.GetStatRequest()
resp = await req.do()
assert "bill" in resp
assert "gazette" in resp
assert "ivod" in resp
assert "legislator" in resp
assert "meet" in resp
assert isinstance(resp["bill"], dict)
assert len(resp["bill"]) > 0
@pytest.mark.asyncio
async def test_search_bill_request_real():
req = api.ListBillRequest(term=11, bill_type="法律案", limit=1)
resp = await req.do()
assert "bills" in resp
assert isinstance(resp["bills"], list)
assert len(resp["bills"]) > 0
@pytest.mark.asyncio
async def test_get_bill_request_real():
# 先查一個 bill_no
search = api.ListBillRequest(term=11, limit=1)
search_resp = await search.do()
bill_no = search_resp["bills"][0]["議案編號"]
req = api.GetBillRequest(bill_no=bill_no)
resp = await req.do()
# 正確取出 data 裡的 key
data = resp.get("data", {})
assert data.get("議案編號") == bill_no or data.get("billNo") == bill_no
@pytest.mark.asyncio
async def test_bill_meets_request_real():
# 先查一個 bill_no
search = api.ListBillRequest(term=11, limit=1)
search_resp = await search.do()
bill_no = search_resp["bills"][0]["議案編號"]
req = api.GetBillMeetsRequest(bill_no=bill_no)
resp = await req.do()
# 會議資料可能在 'meets'、'data' 或 'bills'
assert any(k in resp for k in ("meets", "data", "bills"))
@pytest.mark.asyncio
async def test_bill_related_bills_request_real():
# 先查一個 bill_no
search = api.ListBillRequest(term=11, limit=1)
search_resp = await search.do()
bill_no = search_resp["bills"][0]["議案編號"]
req = api.GetBillRelatedBillsRequest(bill_no=bill_no)
resp = await req.do()
# 相關議案資料可能在 'related_bills'、'data' 或 'bills'
assert any(k in resp for k in ("related_bills", "data", "bills"))
@pytest.mark.asyncio
async def test_bill_doc_html_request_real():
# 先查一個 bill_no
search = api.ListBillRequest(term=11, limit=1)
search_resp = await search.do()
bill_no = search_resp["bills"][0]["議案編號"]
req = api.GetBillDocHtmlRequest(bill_no=bill_no)
try:
resp = await req.do()
# 文件資料可能在 'doc_html'、'html'、'data',或回傳 bills
assert any(k in resp for k in ("doc_html", "html", "data", "bills"))
except Exception:
# 若回傳非 JSON 或 404,允許通過
assert True
@pytest.mark.asyncio
async def test_list_committees_request_real():
req = api.ListCommitteesRequest(limit=1)
resp = await req.do()
# 回傳資料可能在 'committees'、'data'、'results'
assert any(k in resp for k in ("committees", "data", "results"))
@pytest.mark.asyncio
async def test_get_committee_request_real():
# 先查一個 comt_cd
search = api.ListCommitteesRequest(limit=1)
search_resp = await search.do()
# 取第一個委員會代號
comt_cd = None
for k in ("committees", "data", "results"):
if k in search_resp and search_resp[k]:
comt_cd = search_resp[k][0].get("委員會代號") or search_resp[k][0].get("comtCd")
if comt_cd is not None:
comt_cd = str(comt_cd)
break
assert comt_cd
req = api.GetCommitteeRequest(comt_cd=comt_cd)
resp = await req.do()
# 應有委員會代號
data = resp.get("data", resp)
data_comt_cd = data.get("委員會代號") or data.get("comtCd")
assert str(data_comt_cd) == comt_cd
@pytest.mark.asyncio
async def test_committee_meets_request_real():
# 先查一個 comt_cd
search = api.ListCommitteesRequest(limit=1)
search_resp = await search.do()
comt_cd = None
for k in ("committees", "data", "results"):
if k in search_resp and search_resp[k]:
comt_cd = search_resp[k][0].get("委員會代號") or search_resp[k][0].get("comtCd")
if comt_cd is not None:
comt_cd = str(comt_cd)
break
assert comt_cd
req = api.GetCommitteeMeetsRequest(comt_cd=comt_cd, limit=1)
resp = await req.do()
# 會議資料可能在 'meets'、'data'、'results'
assert any(k in resp for k in ("meets", "data", "results"))
@pytest.mark.asyncio
async def test_list_gazettes_request():
req = api.ListGazettesRequest(limit=1)
resp = await req.do()
# 公報資料可能在 'gazettes', 'data', 'results' 等 key 下
assert any(k in resp for k in ("gazettes", "data", "results"))
@pytest.mark.asyncio
async def test_get_gazette_request():
# 先查一個 gazette_id
search = api.ListGazettesRequest(limit=1)
search_resp = await search.do()
gazette_id = None
for k in ("gazettes", "data", "results"):
if k in search_resp and search_resp[k]:
gazette_id = search_resp[k][0].get("公報編號") or search_resp[k][0].get("gazetteId")
if gazette_id is not None:
gazette_id = str(gazette_id)
break
# 如果找不到 gazette_id,使用一個測試用的 ID
if not gazette_id:
gazette_id = "1137701"
req = api.GetGazetteRequest(gazette_id=gazette_id)
resp = await req.do()
# 應該有資料回傳
assert resp is not None
@pytest.mark.asyncio
async def test_list_gazette_agendas_request():
req = api.ListGazetteAgendasRequest(limit=1)
resp = await req.do()
# 公報議程資料在 'gazetteagendas' key 下
assert "gazetteagendas" in resp
assert isinstance(resp["gazetteagendas"], list)
@pytest.mark.asyncio
async def test_list_interpellations_request():
req = api.ListInterpellationsRequest(limit=1)
resp = await req.do()
# 質詢資料應該在 'interpellations' 或其他 key 下
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_list_interpellations_with_member():
req = api.ListInterpellationsRequest(interpellation_member="羅智強", limit=1)
resp = await req.do()
# 質詢資料應該有回應
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_get_interpellation_request():
# 先取得一個質詢ID來測試
list_req = api.ListInterpellationsRequest(limit=1)
list_resp = await list_req.do()
# 嘗試從回應中取得質詢編號
interpellation_id = None
if "interpellations" in list_resp and len(list_resp["interpellations"]) > 0:
interpellation_id = list_resp["interpellations"][0].get("質詢編號")
# 如果找不到質詢編號,使用一個測試用的 ID
if not interpellation_id:
interpellation_id = "11-1-1-1"
req = api.GetInterpellationRequest(interpellation_id=interpellation_id)
resp = await req.do()
# 應該有資料回傳
assert resp is not None
@pytest.mark.asyncio
async def test_get_legislator_interpellations_request():
req = api.GetLegislatorInterpellationsRequest(term=11, name="韓國瑜", limit=1)
resp = await req.do()
# 委員質詢資料應該有回應
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_list_ivods_request():
req = api.ListIvodsRequest(term=11, limit=1)
resp = await req.do()
# IVOD 列表應該有回應
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_list_ivods_with_filters_request():
req = api.ListIvodsRequest(term=11, video_type="Clip", limit=1)
resp = await req.do()
# 有篩選條件的 IVOD 列表應該有回應
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_get_ivod_request():
# 先取得一個 IVOD ID 來測試
list_req = api.ListIvodsRequest(term=11, limit=1)
list_resp = await list_req.do()
# 嘗試從回應中取得 IVOD_ID
ivod_id = None
if "ivods" in list_resp and len(list_resp["ivods"]) > 0:
ivod_id = str(list_resp["ivods"][0].get("IVOD_ID"))
# 如果找不到 IVOD ID,使用一個測試用的 ID
if not ivod_id:
ivod_id = "156045"
req = api.GetIvodRequest(ivod_id=ivod_id)
resp = await req.do()
# 應該有資料回傳
assert resp is not None
@pytest.mark.asyncio
async def test_get_meet_ivods_request():
req = api.GetMeetIvodsRequest(meet_id="院會-11-2-3", limit=1)
resp = await req.do()
# 會議 IVOD 資料應該有回應
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_list_laws_request():
req = api.ListLawsRequest(limit=5)
resp = await req.do()
# 法律資料可能在 'laws', 'data', 'results' 等 key 下
assert any(k in resp for k in ("laws", "data", "results"))
@pytest.mark.asyncio
async def test_list_laws_with_filters_request():
req = api.ListLawsRequest(category="母法", law_status="現行", limit=3)
resp = await req.do()
# 應該有法律資料回傳
assert any(k in resp for k in ("laws", "data", "results"))
@pytest.mark.asyncio
async def test_get_law_request():
# 使用一個已知的法律編號進行測試
req = api.GetLawRequest(law_id="09200015")
resp = await req.do()
# 應該有法律詳細資料
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_get_law_progress_request():
# 使用一個已知的法律編號進行測試
req = api.GetLawProgressRequest(law_id="09200015")
resp = await req.do()
# 應該有進度資料回傳
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_get_law_bills_request():
# 使用一個已知的法律編號進行測試
req = api.GetLawBillsRequest(law_id="09200015", limit=3)
resp = await req.do()
# 應該有相關議案資料
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_get_law_versions_request():
# 使用一個已知的法律編號進行測試
req = api.GetLawVersionsRequest(law_id="09200015", limit=3)
resp = await req.do()
# 應該有版本資料
assert resp is not None
assert isinstance(resp, dict)
@pytest.mark.asyncio
async def test_get_law_request_with_real_data():
# 先查詢法律列表,取得真實的法律編號
search = api.ListLawsRequest(limit=1)
search_resp = await search.do()
law_id = None
for k in ("laws", "data", "results"):
if k in search_resp and search_resp[k]:
law_id = search_resp[k][0].get("法律編號") or search_resp[k][0].get("lawId")
if law_id is not None:
law_id = str(law_id)
break
if law_id:
req = api.GetLawRequest(law_id=law_id)
resp = await req.do()
# 應該有對應的法律編號
data = resp.get("data", resp)
data_law_id = data.get("法律編號") or data.get("lawId")
assert str(data_law_id) == law_id
@pytest.mark.asyncio
async def test_list_law_contents_request():
req = api.ListLawContentsRequest(limit=5)
resp = await req.do()
# 檢查回應結構
assert "lawcontents" in resp
assert isinstance(resp["lawcontents"], list)
assert len(resp["lawcontents"]) > 0
# 檢查基本的分頁資訊
assert "total" in resp
assert "page" in resp
assert "limit" in resp
@pytest.mark.asyncio
async def test_list_law_contents_with_filters_request():
req = api.ListLawContentsRequest(
law_number="90481",
current_version_status="現行",
limit=3
)
resp = await req.do()
# 檢查回應中有資料
assert "lawcontents" in resp
assert isinstance(resp["lawcontents"], list)
# 檢查篩選參數有被正確應用
assert "filter" in resp
@pytest.mark.asyncio
async def test_get_law_content_request():
# 測試取得特定法條資訊
# 使用swagger.yaml中的範例ID
req = api.GetLawContentRequest(law_content_id="90481:90481:1944-02-29-制定:0")
resp = await req.do()
# 法條資料應該有內容
assert resp is not None
assert isinstance(resp, dict)
# === Legislators API Tests ===
@pytest.mark.asyncio
async def test_list_legislators_request():
req = api.ListLegislatorsRequest(limit=5)
resp = await req.do()
# 檢查回應結構
assert "legislators" in resp
assert isinstance(resp["legislators"], list)
assert len(resp["legislators"]) > 0
# 檢查基本的分頁資訊
assert "total" in resp
assert "page" in resp
assert "limit" in resp
@pytest.mark.asyncio
async def test_list_legislators_with_filters_request():
req = api.ListLegislatorsRequest(
term=11,
party="民主進步黨",
limit=3
)
resp = await req.do()
# 檢查回應中有資料
assert "legislators" in resp
assert isinstance(resp["legislators"], list)
@pytest.mark.asyncio
async def test_get_legislator_request():
# 測試取得特定立法委員資訊
req = api.GetLegislatorRequest(term=11, name="韓國瑜")
resp = await req.do()
# 立法委員資料應該有內容
assert resp is not None
assert isinstance(resp, dict)
# 可能會有 data 或直接包含委員資訊
data = resp.get("data", resp)
# 應該有屆期和委員姓名
assert any(k in data for k in ("屆", "term"))
assert any(k in data for k in ("委員姓名", "name"))
@pytest.mark.asyncio
async def test_get_legislator_propose_bills_request():
# 測試取得委員為提案人的法案列表
req = api.GetLegislatorProposeBillsRequest(
term=11,
name="韓國瑜",
limit=3
)
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有bills或相關的議案資料
assert any(k in resp for k in ("bills", "data", "議案"))
@pytest.mark.asyncio
async def test_get_legislator_cosign_bills_request():
# 測試取得委員為連署人的法案列表
req = api.GetLegislatorCosignBillsRequest(
term=11,
name="韓國瑜",
limit=3
)
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有bills或相關的議案資料
assert any(k in resp for k in ("bills", "data", "議案"))
@pytest.mark.asyncio
async def test_get_legislator_meets_request():
# 測試取得委員出席的會議列表
req = api.GetLegislatorMeetsRequest(
term=11,
name="韓國瑜",
limit=3
)
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有meets或相關的會議資料
assert any(k in resp for k in ("meets", "data", "會議"))
@pytest.mark.asyncio
async def test_list_meets_request():
# 測試列出會議列表
req = api.ListMeetsRequest(
term=11,
limit=3
)
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有meets或相關的會議資料
assert any(k in resp for k in ("meets", "data", "會議"))
@pytest.mark.asyncio
async def test_get_meet_request():
# 測試取得特定會議詳細資訊
req = api.GetMeetRequest(meet_id="院會-11-2-3")
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有meet或相關的會議資料
assert any(k in resp for k in ("meet", "data", "會議"))
@pytest.mark.asyncio
async def test_get_meet_bills_request():
# 測試取得會議內的議案列表
req = api.GetMeetBillsRequest(
meet_id="院會-11-2-3",
limit=3
)
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有bills或相關的議案資料
assert any(k in resp for k in ("bills", "data", "議案"))
@pytest.mark.asyncio
async def test_get_meet_interpellations_request():
# 測試取得會議內的質詢列表
req = api.GetMeetInterpellationsRequest(
meet_id="院會-11-2-3",
limit=3
)
resp = await req.do()
# 檢查回應結構
assert resp is not None
assert isinstance(resp, dict)
# 應該有interpellations或相關的質詢資料
assert any(k in resp for k in ("interpellations", "data", "質詢"))