1515
1616class ProductSchema (BaseModel ):
1717 """Test schema for product data"""
18+
1819 title : str
1920 description : str
2021 price : float
2122
2223
2324class CompanySchema (BaseModel ):
2425 """Test schema for company data"""
26+
2527 name : str
2628 description : str
2729 website : str
@@ -34,222 +36,215 @@ class CompanySchema(BaseModel):
3436 "data" : {
3537 "title" : "Test Page" ,
3638 "description" : "This is a test page" ,
37- "content" : "Mock content from the page"
38- }
39+ "content" : "Mock content from the page" ,
40+ },
3941}
4042
4143MOCK_SEARCHSCRAPER_RESPONSE = {
4244 "status" : "completed" ,
4345 "request_id" : "456e7890-e89b-12d3-a456-426614174001" ,
4446 "data" : [
4547 {"title" : "Result 1" , "url" : "https://example1.com" },
46- {"title" : "Result 2" , "url" : "https://example2.com" }
47- ]
48+ {"title" : "Result 2" , "url" : "https://example2.com" },
49+ ],
4850}
4951
5052MOCK_MARKDOWNIFY_RESPONSE = {
5153 "status" : "completed" ,
5254 "request_id" : "789e0123-e89b-12d3-a456-426614174002" ,
53- "data" : "# Test Page\n \n This is a test page in markdown format."
55+ "data" : "# Test Page\n \n This is a test page in markdown format." ,
5456}
5557
5658MOCK_STATUS_RESPONSE = {
5759 "status" : "completed" ,
5860 "request_id" : "123e4567-e89b-12d3-a456-426614174000" ,
59- "data" : {"result" : "Mock result data" }
61+ "data" : {"result" : "Mock result data" },
6062}
6163
6264MOCK_FEEDBACK_RESPONSE = {
6365 "status" : "success" ,
64- "message" : "Feedback submitted successfully"
66+ "message" : "Feedback submitted successfully" ,
6567}
6668
67- api_key = "sgai-c0811976-dac7-441c-acb6-7cd72643449c" # its an invalid api key
69+ api_key = "sgai-c0811976-dac7-441c-acb6-7cd72643449c" # its an invalid api key
6870# ============================================================================
6971# SYNC CLIENT TESTS
7072# ============================================================================
7173
72- @patch ('scrapegraph_py.client.Client._make_request' )
74+
75+ @patch ("scrapegraph_py.client.Client._make_request" )
7376def test_smartscraper_basic_mocked (mock_request ):
7477 """Test basic smartscraper with mocked API call"""
7578 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
76-
79+
7780 with Client (api_key = api_key ) as client :
7881 response = client .smartscraper (
7982 website_url = "https://example.com" ,
80- user_prompt = "Extract the title and description of this page"
83+ user_prompt = "Extract the title and description of this page" ,
8184 )
8285 assert response ["status" ] == "completed"
8386 assert "request_id" in response
8487 assert "data" in response
8588
8689
87- @patch (' scrapegraph_py.client.Client._make_request' )
90+ @patch (" scrapegraph_py.client.Client._make_request" )
8891def test_smartscraper_with_schema_mocked (mock_request ):
8992 """Test smartscraper with output schema"""
9093 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
91-
94+
9295 with Client (api_key = api_key ) as client :
9396 response = client .smartscraper (
9497 website_url = "https://example.com" ,
9598 user_prompt = "Extract company information" ,
96- output_schema = CompanySchema
99+ output_schema = CompanySchema ,
97100 )
98101 assert response ["status" ] == "completed"
99102 assert "request_id" in response
100103
101104
102- @patch (' scrapegraph_py.client.Client._make_request' )
105+ @patch (" scrapegraph_py.client.Client._make_request" )
103106def test_smartscraper_with_headers_mocked (mock_request ):
104107 """Test smartscraper with custom headers"""
105108 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
106-
109+
107110 headers = {
108111 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
109112 }
110-
113+
111114 with Client (api_key = api_key ) as client :
112115 response = client .smartscraper (
113116 website_url = "https://example.com" ,
114117 user_prompt = "Extract page information" ,
115- headers = headers
118+ headers = headers ,
116119 )
117120 assert response ["status" ] == "completed"
118121 assert "request_id" in response
119122
120123
121- @patch (' scrapegraph_py.client.Client._make_request' )
124+ @patch (" scrapegraph_py.client.Client._make_request" )
122125def test_smartscraper_with_cookies_mocked (mock_request ):
123126 """Test smartscraper with cookies"""
124127 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
125-
128+
126129 cookies = {"session" : "test123" , "user" : "testuser" }
127-
130+
128131 with Client (api_key = api_key ) as client :
129132 response = client .smartscraper (
130133 website_url = "https://example.com" ,
131134 user_prompt = "Extract page information" ,
132- cookies = cookies
135+ cookies = cookies ,
133136 )
134137 assert response ["status" ] == "completed"
135138 assert "request_id" in response
136139
137140
138- @patch (' scrapegraph_py.client.Client._make_request' )
141+ @patch (" scrapegraph_py.client.Client._make_request" )
139142def test_smartscraper_with_scrolls_mocked (mock_request ):
140143 """Test smartscraper with scrolls"""
141144 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
142-
145+
143146 with Client (api_key = api_key ) as client :
144147 response = client .smartscraper (
145148 website_url = "https://example.com" ,
146149 user_prompt = "Extract page information" ,
147- number_of_scrolls = 3
150+ number_of_scrolls = 3 ,
148151 )
149152 assert response ["status" ] == "completed"
150153 assert "request_id" in response
151154
152155
153-
154- @patch ('scrapegraph_py.client.Client._make_request' )
156+ @patch ("scrapegraph_py.client.Client._make_request" )
155157def test_get_smartscraper_status_mocked (mock_request ):
156158 """Test getting smartscraper status"""
157159 mock_request .return_value = MOCK_STATUS_RESPONSE
158-
160+
159161 with Client (api_key = api_key ) as client :
160162 response = client .get_smartscraper ("123e4567-e89b-12d3-a456-426614174000" )
161163 assert response ["status" ] == "completed"
162164 assert "request_id" in response
163165
164166
165- @patch (' scrapegraph_py.client.Client._make_request' )
167+ @patch (" scrapegraph_py.client.Client._make_request" )
166168def test_searchscraper_basic_mocked (mock_request ):
167169 """Test basic searchscraper"""
168170 mock_request .return_value = MOCK_SEARCHSCRAPER_RESPONSE
169-
171+
170172 with Client (api_key = api_key ) as client :
171- response = client .searchscraper (
172- user_prompt = "Search for programming tutorials"
173- )
173+ response = client .searchscraper (user_prompt = "Search for programming tutorials" )
174174 assert response ["status" ] == "completed"
175175 assert "request_id" in response
176176 assert "data" in response
177177
178178
179- @patch (' scrapegraph_py.client.Client._make_request' )
179+ @patch (" scrapegraph_py.client.Client._make_request" )
180180def test_searchscraper_with_num_results_mocked (mock_request ):
181181 """Test searchscraper with num_results parameter"""
182182 mock_request .return_value = MOCK_SEARCHSCRAPER_RESPONSE
183-
183+
184184 with Client (api_key = api_key ) as client :
185185 response = client .searchscraper (
186- user_prompt = "Search for tutorials" ,
187- num_results = 5
186+ user_prompt = "Search for tutorials" , num_results = 5
188187 )
189188 assert response ["status" ] == "completed"
190189 assert "request_id" in response
191190
192191
193- @patch (' scrapegraph_py.client.Client._make_request' )
192+ @patch (" scrapegraph_py.client.Client._make_request" )
194193def test_searchscraper_with_schema_mocked (mock_request ):
195194 """Test searchscraper with output schema"""
196195 mock_request .return_value = MOCK_SEARCHSCRAPER_RESPONSE
197-
196+
198197 with Client (api_key = api_key ) as client :
199198 response = client .searchscraper (
200- user_prompt = "Search for products" ,
201- output_schema = ProductSchema
199+ user_prompt = "Search for products" , output_schema = ProductSchema
202200 )
203201 assert response ["status" ] == "completed"
204202 assert "request_id" in response
205203
206204
207- @patch (' scrapegraph_py.client.Client._make_request' )
205+ @patch (" scrapegraph_py.client.Client._make_request" )
208206def test_get_searchscraper_status_mocked (mock_request ):
209207 """Test getting searchscraper status"""
210208 mock_request .return_value = MOCK_STATUS_RESPONSE
211-
209+
212210 with Client (api_key = api_key ) as client :
213211 response = client .get_searchscraper ("456e7890-e89b-12d3-a456-426614174001" )
214212 assert response ["status" ] == "completed"
215213 assert "request_id" in response
216214
217215
218- @patch (' scrapegraph_py.client.Client._make_request' )
216+ @patch (" scrapegraph_py.client.Client._make_request" )
219217def test_markdownify_basic_mocked (mock_request ):
220218 """Test basic markdownify"""
221219 mock_request .return_value = MOCK_MARKDOWNIFY_RESPONSE
222-
220+
223221 with Client (api_key = api_key ) as client :
224222 response = client .markdownify ("https://example.com" )
225223 assert response ["status" ] == "completed"
226224 assert "request_id" in response
227225 assert "data" in response
228226
229227
230- @patch (' scrapegraph_py.client.Client._make_request' )
228+ @patch (" scrapegraph_py.client.Client._make_request" )
231229def test_markdownify_with_headers_mocked (mock_request ):
232230 """Test markdownify with custom headers"""
233231 mock_request .return_value = MOCK_MARKDOWNIFY_RESPONSE
234-
232+
235233 headers = {
236234 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
237235 }
238-
236+
239237 with Client (api_key = api_key ) as client :
240- response = client .markdownify (
241- "https://example.com" ,
242- headers = headers
243- )
238+ response = client .markdownify ("https://example.com" , headers = headers )
244239 assert response ["status" ] == "completed"
245240 assert "request_id" in response
246241
247242
248- @patch (' scrapegraph_py.client.Client._make_request' )
243+ @patch (" scrapegraph_py.client.Client._make_request" )
249244def test_get_markdownify_status_mocked (mock_request ):
250245 """Test getting markdownify status"""
251246 mock_request .return_value = MOCK_STATUS_RESPONSE
252-
247+
253248 with Client (api_key = api_key ) as client :
254249 response = client .get_markdownify ("789e0123-e89b-12d3-a456-426614174002" )
255250 assert response ["status" ] == "completed"
@@ -260,43 +255,44 @@ def test_get_markdownify_status_mocked(mock_request):
260255# ASYNC CLIENT TESTS
261256# ============================================================================
262257
258+
263259@pytest .mark .asyncio
264- @patch (' scrapegraph_py.async_client.AsyncClient._make_request' )
260+ @patch (" scrapegraph_py.async_client.AsyncClient._make_request" )
265261async def test_async_smartscraper_basic_mocked (mock_request ):
266262 """Test basic async smartscraper"""
267263 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
268-
264+
269265 async with AsyncClient (api_key = api_key ) as client :
270266 response = await client .smartscraper (
271267 website_url = "https://example.com" ,
272- user_prompt = "Extract async page information"
268+ user_prompt = "Extract async page information" ,
273269 )
274270 assert response ["status" ] == "completed"
275271 assert "request_id" in response
276272
277273
278274@pytest .mark .asyncio
279- @patch (' scrapegraph_py.async_client.AsyncClient._make_request' )
275+ @patch (" scrapegraph_py.async_client.AsyncClient._make_request" )
280276async def test_async_smartscraper_with_schema_mocked (mock_request ):
281277 """Test async smartscraper with output schema"""
282278 mock_request .return_value = MOCK_SMARTSCRAPER_RESPONSE
283-
279+
284280 async with AsyncClient (api_key = api_key ) as client :
285281 response = await client .smartscraper (
286282 website_url = "https://example.com" ,
287283 user_prompt = "Extract company data" ,
288- output_schema = CompanySchema
284+ output_schema = CompanySchema ,
289285 )
290286 assert response ["status" ] == "completed"
291287 assert "request_id" in response
292288
293289
294290@pytest .mark .asyncio
295- @patch (' scrapegraph_py.async_client.AsyncClient._make_request' )
291+ @patch (" scrapegraph_py.async_client.AsyncClient._make_request" )
296292async def test_async_searchscraper_basic_mocked (mock_request ):
297293 """Test basic async searchscraper"""
298294 mock_request .return_value = MOCK_SEARCHSCRAPER_RESPONSE
299-
295+
300296 async with AsyncClient (api_key = api_key ) as client :
301297 response = await client .searchscraper (
302298 user_prompt = "Search for async programming tutorials"
@@ -306,11 +302,11 @@ async def test_async_searchscraper_basic_mocked(mock_request):
306302
307303
308304@pytest .mark .asyncio
309- @patch (' scrapegraph_py.async_client.AsyncClient._make_request' )
305+ @patch (" scrapegraph_py.async_client.AsyncClient._make_request" )
310306async def test_async_markdownify_basic_mocked (mock_request ):
311307 """Test basic async markdownify"""
312308 mock_request .return_value = MOCK_MARKDOWNIFY_RESPONSE
313-
309+
314310 async with AsyncClient (api_key = api_key ) as client :
315311 response = await client .markdownify ("https://example.com" )
316312 assert response ["status" ] == "completed"
@@ -321,6 +317,7 @@ async def test_async_markdownify_basic_mocked(mock_request):
321317# CLIENT INITIALIZATION TESTS
322318# ============================================================================
323319
320+
324321def test_client_context_manager_mocked ():
325322 """Test client context manager"""
326323 with Client (api_key = api_key ) as client :
@@ -354,4 +351,4 @@ async def test_async_concurrent_requests_mocked():
354351 async with AsyncClient (api_key = api_key ) as client :
355352 # This test verifies the async client can handle multiple requests
356353 # In a real scenario, you'd mock the requests
357- assert client .api_key == api_key
354+ assert client .api_key == api_key
0 commit comments