AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
tests: regression tests for issue #817 — Arabic/non-Latin topics UnicodeEncodeError (#1234)
Bhumika Gurav3c9d7dd57fd4
diff --git a/changelog.d/817.fixed.md b/changelog.d/817.fixed.mdnew file mode 100644index 00000000..ddca6827--- /dev/null+++ b/changelog.d/817.fixed.md@@ -0,0 +1 @@+Added regression tests for issue #817: Arabic-script (and other non-Latin) topics no longer risk UnicodeEncodeError on TikTok and Instagram (ScrapeCreators) searches. Tests lock in the existing percent-encoding fix in `http.request()` and cover the TikTok and Instagram search paths end-to-end.diff --git a/tests/test_http_v3.py b/tests/test_http_v3.pyindex 0339465a..28db8b8f 100644--- a/tests/test_http_v3.py+++ b/tests/test_http_v3.py@@ -3,6 +3,7 @@ import threadingimport urllib.errorimport unittestimport time+from urllib.parse import parse_qs, unquote, urlsplitfrom unittest.mock import patch, MagicMockfrom lib import http@@ -230,6 +231,41 @@ class TestParamsEncoding(unittest.TestCase):self.assertIn("count=25", sent_url)self.assertIn("raw=True", sent_url)+ @patch("lib.http.urllib.request.urlopen")+ def test_arabic_query_param_is_percent_encoded(self, mock_urlopen):+ mock_urlopen.return_value = _mock_response()+ arabic_topic = "اسعار التمريض المنزلي"+ http.get("https://api.scrapecreators.com/v1/tiktok/search/keyword",+ params={"query": arabic_topic})+ sent_url = self._sent_url(mock_urlopen)+ sent_url.encode("ascii")+ self.assertIn("%D8%A7", sent_url)+ self.assertEqual(parse_qs(urlsplit(sent_url).query)["query"], [arabic_topic])++ @patch("lib.http.urllib.request.urlopen")+ def test_cjk_query_param_is_percent_encoded(self, mock_urlopen):+ mock_urlopen.return_value = _mock_response()+ http.get("https://api.example.com/search", params={"q": "人工智能"})+ sent_url = self._sent_url(mock_urlopen)+ sent_url.encode("ascii")+ self.assertEqual(parse_qs(urlsplit(sent_url).query)["q"], ["人工智能"])++ @patch("lib.http.urllib.request.urlopen")+ def test_non_ascii_in_base_url_path_is_percent_encoded(self, mock_urlopen):+ mock_urlopen.return_value = _mock_response()+ http.get("https://api.example.com/search/العربية")+ sent_url = self._sent_url(mock_urlopen)+ sent_url.encode("ascii")+ self.assertEqual(unquote(urlsplit(sent_url).path), "/search/العربية")++ @patch("lib.http.urllib.request.urlopen")+ def test_non_ascii_in_raw_url_query_string_is_percent_encoded(self, mock_urlopen):+ mock_urlopen.return_value = _mock_response()+ http.get("https://api.example.com/search?q=العربية")+ sent_url = self._sent_url(mock_urlopen)+ sent_url.encode("ascii")+ self.assertEqual(parse_qs(urlsplit(sent_url).query)["q"], ["العربية"])+class TestDNSResolutionRetry(unittest.TestCase):"""DNS resolution failures (gaierror) must retry with exponential backoff.diff --git a/tests/test_instagram_sc.py b/tests/test_instagram_sc.pyindex c26e33bc..6751c127 100644--- a/tests/test_instagram_sc.py+++ b/tests/test_instagram_sc.py@@ -2,6 +2,7 @@import osimport unittest+from urllib.parse import parse_qs, urlsplitfrom unittest.mock import MagicMock, patch# Add lib to path@@ -250,5 +251,34 @@ class TestTranscriptTimeoutConfig(unittest.TestCase):kwargs = mock_http_get.call_args.kwargsself.assertEqual(kwargs["timeout"], 30.0)+class TestInstagramArabicTopicEncoding(unittest.TestCase):+ """Regression for issue #817 across the Instagram search path."""++ def _sent_url(self, mock_urlopen) -> str:+ return mock_urlopen.call_args[0][0].full_url++ @patch("lib.http.urllib.request.urlopen")+ def test_arabic_topic_returns_success_with_ascii_encoded_url(self, mock_urlopen):+ resp = MagicMock()+ resp.__enter__ = MagicMock(return_value=resp)+ resp.__exit__ = MagicMock(return_value=False)+ resp.read.return_value = b'{"reels": []}'+ resp.status = 200+ mock_urlopen.return_value = resp++ topic = "اسعار التمريض المنزلي السعودية"+ result = instagram.search_instagram(+ topic,+ "2026-06-01",+ "2026-07-13",+ depth="quick",+ token="dummy-key",+ )+ self.assertNotIn("error", result)+ sent_url = self._sent_url(mock_urlopen)+ sent_url.encode("ascii")+ self.assertEqual(parse_qs(urlsplit(sent_url).query)["query"], [topic])++if __name__ == "__main__":unittest.main()diff --git a/tests/test_tiktok.py b/tests/test_tiktok.pyindex f871d37f..feb6a54f 100644--- a/tests/test_tiktok.py+++ b/tests/test_tiktok.py@@ -1,4 +1,6 @@import unittest+from urllib.parse import parse_qs, urlsplit+from unittest.mock import MagicMock, patchfrom lib.tiktok import _parse_items@@ -238,5 +240,35 @@ class TestTikTokEnrichWithComments(unittest.TestCase):self.assertIn("top_comments", by_id["mid"])self.assertNotIn("top_comments", by_id["low"])+class TestTikTokArabicTopicEncoding(unittest.TestCase):+ """Regression for issue #817 across the TikTok search path."""++ def _sent_url(self, mock_urlopen) -> str:+ return mock_urlopen.call_args[0][0].full_url++ @patch("lib.http.urllib.request.urlopen")+ def test_arabic_topic_returns_success_with_ascii_encoded_url(self, mock_urlopen):+ from lib.tiktok import search_tiktok+ resp = MagicMock()+ resp.__enter__ = MagicMock(return_value=resp)+ resp.__exit__ = MagicMock(return_value=False)+ resp.read.return_value = b'{"search_item_list": []}'+ resp.status = 200+ mock_urlopen.return_value = resp++ topic = "اسعار التمريض المنزلي السعودية"+ result = search_tiktok(+ topic,+ "2026-06-01",+ "2026-07-13",+ depth="quick",+ token="dummy-key",+ )+ self.assertNotIn("error", result)+ sent_url = self._sent_url(mock_urlopen)+ sent_url.encode("ascii")+ self.assertEqual(parse_qs(urlsplit(sent_url).query)["query"], [topic])++if __name__ == "__main__":unittest.main()