import pytest from unittest.mock import AsyncMock, patch, MagicMock from app.crawler.dahuagov_spider import DahuagovSpider from app.crawler.base import PipelineConfig @pytest.mark.asyncio async def test_dahuagov_spider_attributes(): spider = DahuagovSpider() assert spider.name == "dahuagov" assert spider.source_code == "dahuagov" assert spider.source_name == "大化县政府网采购公告" @pytest.mark.asyncio async def test_dahuagov_spider_pipeline_config(): spider = DahuagovSpider() config = spider.get_pipeline_config() assert isinstance(config, PipelineConfig) assert config.filter_enabled is False assert config.notify_mode == "all" assert config.mark_sent is True @pytest.mark.asyncio async def test_dahuagov_spider_crawl(): spider = DahuagovSpider() html = """
""" mock_response = MagicMock() mock_response.status_code = 200 mock_response.text = html with patch("httpx.AsyncClient.get", AsyncMock(return_value=mock_response)): result = await spider.crawl() assert result.total_count == 2 assert len(result.announcements) == 2 assert result.success is True @pytest.mark.asyncio async def test_dahuagov_spider_crawl_empty(): spider = DahuagovSpider() mock_response = MagicMock() mock_response.status_code = 200 mock_response.text = "" with patch("httpx.AsyncClient.get", AsyncMock(return_value=mock_response)): result = await spider.crawl() assert result.total_count == 0 assert result.success is True