+
First paragraph of the article.
+
Second paragraph with more content.
+
+
+ '''
+ mock_get.return_value = mock_response
+
+ content = fetch_news_detail("https://example.com/article")
+
+ self.assertIn("First paragraph of the article.", content)
+ self.assertIn("Second paragraph with more content.", content)
+
+ @patch('plugins_func.functions.get_news.requests.get')
+ def test_fetch_news_detail_failure(self, mock_get):
+ """Test news detail fetching failure."""
+ # Mock failed response
+ mock_get.side_effect = Exception("Network error")
+
+ content = fetch_news_detail("https://invalid-url.com/article")
+
+ self.assertEqual(content, "Unable to fetch detailed content")
+
+ @patch('plugins_func.functions.get_news.fetch_news_from_rss')
+ @patch('core.utils.cache.manager.cache_manager')
+ def test_get_news_success(self, mock_cache_manager, mock_fetch_rss):
+ """Test successful news plugin execution."""
+ # Mock cache miss
+ mock_cache_manager.get.return_value = None
+
+ # Mock news data
+ news_items = [
+ {
+ "title": "Breaking News Title",
+ "link": "https://example.com/news1",
+ "description": "This is breaking news content",
+ "pubDate": "Mon, 01 Jan 2024 12:00:00 GMT"
+ },
+ {
+ "title": "Another News Title",
+ "link": "https://example.com/news2",
+ "description": "This is another news content",
+ "pubDate": "Tue, 02 Jan 2024 12:00:00 GMT"
+ }
+ ]
+ mock_fetch_rss.return_value = news_items
+
+ from plugins_func.register import ActionResponse, Action
+
+ result = get_news(self.mock_conn, "world", False, "en_US")
+
+ self.assertIsInstance(result, ActionResponse)
+ self.assertEqual(result.action, Action.REQLLM)
+ self.assertIsNotNone(result.result)
+ self.assertIn("Breaking News Title", result.result)
+
+ # Verify cache was set
+ mock_cache_manager.set.assert_called_once()
+
+ @patch('core.utils.cache.manager.cache_manager')
+ def test_get_news_cache_hit(self, mock_cache_manager):
+ """Test news plugin with cache hit."""
+ # Mock cache hit
+ cached_report = "Cached news report"
+ mock_cache_manager.get.return_value = cached_report
+
+ from plugins_func.register import ActionResponse, Action
+
+ result = get_news(self.mock_conn, "world", False, "en_US")
+
+ self.assertIsInstance(result, ActionResponse)
+ self.assertEqual(result.action, Action.REQLLM)
+ self.assertEqual(result.result, cached_report)
+
+ @patch('plugins_func.functions.get_news.fetch_news_detail')
+ def test_get_news_detail_success(self, mock_fetch_detail):
+ """Test news plugin detail mode."""
+ # Mock last news link
+ self.mock_conn.last_news_link = {
+ "link": "https://example.com/article",
+ "title": "Test Article Title"
+ }
+
+ # Mock detail content
+ mock_fetch_detail.return_value = "Detailed article content with full text."
+
+ from plugins_func.register import ActionResponse, Action
+
+ result = get_news(self.mock_conn, None, True, "en_US")
+
+ self.assertIsInstance(result, ActionResponse)
+ self.assertEqual(result.action, Action.REQLLM)
+ self.assertIn("Test Article Title", result.result)
+ self.assertIn("Detailed article content", result.result)
+
+ def test_get_news_detail_no_previous_news(self):
+ """Test news plugin detail mode without previous news."""
+ # No last_news_link attribute
+ from plugins_func.register import ActionResponse, Action
+
+ result = get_news(self.mock_conn, None, True, "en_US")
+
+ self.assertIsInstance(result, ActionResponse)
+ self.assertEqual(result.action, Action.REQLLM)
+ self.assertIn("no recently queried news", result.result)
+
+ @patch('plugins_func.functions.get_news.fetch_news_from_rss')
+ @patch('core.utils.cache.manager.cache_manager')
+ def test_get_news_no_items(self, mock_cache_manager, mock_fetch_rss):
+ """Test news plugin with no news items."""
+ # Mock cache miss
+ mock_cache_manager.get.return_value = None
+
+ # Mock empty news data
+ mock_fetch_rss.return_value = []
+
+ from plugins_func.register import ActionResponse, Action
+
+ result = get_news(self.mock_conn, "world", False, "en_US")
+
+ self.assertIsInstance(result, ActionResponse)
+ self.assertEqual(result.action, Action.REQLLM)
+ self.assertIn("no news information could be retrieved", result.result)
+
+ @patch('plugins_func.functions.get_news.fetch_news_from_rss')
+ @patch('core.utils.cache.manager.cache_manager')
+ def test_get_news_category_mapping(self, mock_cache_manager, mock_fetch_rss):
+ """Test news plugin with different categories."""
+ # Mock cache miss
+ mock_cache_manager.get.return_value = None
+
+ # Mock news data
+ news_items = [{"title": "Tech News", "link": "#", "description": "Tech content", "pubDate": "Now"}]
+ mock_fetch_rss.return_value = news_items
+
+ from plugins_func.register import ActionResponse, Action
+
+ # Test technology category
+ result = get_news(self.mock_conn, "technology", False, "en_US")
+ self.assertIsInstance(result, ActionResponse)
+
+ # Test business category
+ result = get_news(self.mock_conn, "business", False, "en_US")
+ self.assertIsInstance(result, ActionResponse)
+
+ # Test sports category
+ result = get_news(self.mock_conn, "sports", False, "en_US")
+ self.assertIsInstance(result, ActionResponse)
+
+ @patch('plugins_func.functions.get_news.fetch_news_from_rss')
+ @patch('core.utils.cache.manager.cache_manager')
+ def test_get_news_source_rotation(self, mock_cache_manager, mock_fetch_rss):
+ """Test news plugin source rotation functionality."""
+ # Mock cache miss
+ mock_cache_manager.get.return_value = None
+
+ # Mock first source failure, second source success
+ mock_fetch_rss.side_effect = [[], [{"title": "News from second source", "link": "#", "description": "Content", "pubDate": "Now"}]]
+
+ from plugins_func.register import ActionResponse, Action
+
+ result = get_news(self.mock_conn, "world", False, "en_US")
+
+ self.assertIsInstance(result, ActionResponse)
+ self.assertEqual(result.action, Action.REQLLM)
+ self.assertIn("News from second source", result.result)
+
+ # Verify multiple sources were tried
+ self.assertGreaterEqual(mock_fetch_rss.call_count, 2)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html
index 30d68073a..437a0d86d 100644
--- a/main/xiaozhi-server/test/test_page.html
+++ b/main/xiaozhi-server/test/test_page.html
@@ -1,34 +1,34 @@
-
+