@@ -19,7 +19,7 @@ def mock_uuid():
19
19
20
20
21
21
@pytest .mark .asyncio
22
- async def test_smartscraper (mock_api_key ):
22
+ async def test_smartscraper_with_url (mock_api_key ):
23
23
with aioresponses () as mocked :
24
24
mocked .post (
25
25
"https://api.scrapegraphai.com/v1/smartscraper" ,
@@ -38,6 +38,54 @@ async def test_smartscraper(mock_api_key):
38
38
assert "description" in response ["result" ]
39
39
40
40
41
+ @pytest .mark .asyncio
42
+ async def test_smartscraper_with_html (mock_api_key ):
43
+ with aioresponses () as mocked :
44
+ mocked .post (
45
+ "https://api.scrapegraphai.com/v1/smartscraper" ,
46
+ payload = {
47
+ "request_id" : str (uuid4 ()),
48
+ "status" : "completed" ,
49
+ "result" : {"description" : "Test content." },
50
+ },
51
+ )
52
+
53
+ async with AsyncClient (api_key = mock_api_key ) as client :
54
+ response = await client .smartscraper (
55
+ website_html = "<html><body><p>Test content</p></body></html>" ,
56
+ user_prompt = "Extract info" ,
57
+ )
58
+ assert response ["status" ] == "completed"
59
+ assert "description" in response ["result" ]
60
+
61
+
62
+ @pytest .mark .asyncio
63
+ async def test_smartscraper_with_headers (mock_api_key ):
64
+ with aioresponses () as mocked :
65
+ mocked .post (
66
+ "https://api.scrapegraphai.com/v1/smartscraper" ,
67
+ payload = {
68
+ "request_id" : str (uuid4 ()),
69
+ "status" : "completed" ,
70
+ "result" : {"description" : "Example domain." },
71
+ },
72
+ )
73
+
74
+ headers = {
75
+ "User-Agent" : "Mozilla/5.0" ,
76
+ "Cookie" : "session=123" ,
77
+ }
78
+
79
+ async with AsyncClient (api_key = mock_api_key ) as client :
80
+ response = await client .smartscraper (
81
+ website_url = "https://example.com" ,
82
+ user_prompt = "Describe this page." ,
83
+ headers = headers ,
84
+ )
85
+ assert response ["status" ] == "completed"
86
+ assert "description" in response ["result" ]
87
+
88
+
41
89
@pytest .mark .asyncio
42
90
async def test_get_credits (mock_api_key ):
43
91
with aioresponses () as mocked :
@@ -122,57 +170,43 @@ async def test_markdownify(mock_api_key):
122
170
123
171
124
172
@pytest .mark .asyncio
125
- async def test_get_markdownify (mock_api_key , mock_uuid ):
126
- with aioresponses () as mocked :
127
- mocked .get (
128
- f"https://api.scrapegraphai.com/v1/markdownify/{ mock_uuid } " ,
129
- payload = {
130
- "request_id" : mock_uuid ,
131
- "status" : "completed" ,
132
- "result" : "# Example Page\n \n This is markdown content." ,
133
- },
134
- )
135
-
136
- async with AsyncClient (api_key = mock_api_key ) as client :
137
- response = await client .get_markdownify (mock_uuid )
138
- assert response ["status" ] == "completed"
139
- assert response ["request_id" ] == mock_uuid
140
-
141
-
142
- @pytest .mark .asyncio
143
- async def test_localscraper (mock_api_key ):
173
+ async def test_markdownify_with_headers (mock_api_key ):
144
174
with aioresponses () as mocked :
145
175
mocked .post (
146
- "https://api.scrapegraphai.com/v1/localscraper " ,
176
+ "https://api.scrapegraphai.com/v1/markdownify " ,
147
177
payload = {
148
178
"request_id" : str (uuid4 ()),
149
179
"status" : "completed" ,
150
- "result" : { "extracted_info" : "Test content" } ,
180
+ "result" : "# Example Page \n \n This is markdown content." ,
151
181
},
152
182
)
153
183
184
+ headers = {
185
+ "User-Agent" : "Mozilla/5.0" ,
186
+ "Cookie" : "session=123" ,
187
+ }
188
+
154
189
async with AsyncClient (api_key = mock_api_key ) as client :
155
- response = await client .localscraper (
156
- user_prompt = "Extract info" ,
157
- website_html = "<html><body><p>Test content</p></body></html>" ,
190
+ response = await client .markdownify (
191
+ website_url = "https://example.com" , headers = headers
158
192
)
159
193
assert response ["status" ] == "completed"
160
- assert "extracted_info " in response ["result" ]
194
+ assert "# Example Page " in response ["result" ]
161
195
162
196
163
197
@pytest .mark .asyncio
164
- async def test_get_localscraper (mock_api_key , mock_uuid ):
198
+ async def test_get_markdownify (mock_api_key , mock_uuid ):
165
199
with aioresponses () as mocked :
166
200
mocked .get (
167
- f"https://api.scrapegraphai.com/v1/localscraper /{ mock_uuid } " ,
201
+ f"https://api.scrapegraphai.com/v1/markdownify /{ mock_uuid } " ,
168
202
payload = {
169
203
"request_id" : mock_uuid ,
170
204
"status" : "completed" ,
171
- "result" : { "extracted_info" : "Test content" } ,
205
+ "result" : "# Example Page \n \n This is markdown content." ,
172
206
},
173
207
)
174
208
175
209
async with AsyncClient (api_key = mock_api_key ) as client :
176
- response = await client .get_localscraper (mock_uuid )
210
+ response = await client .get_markdownify (mock_uuid )
177
211
assert response ["status" ] == "completed"
178
212
assert response ["request_id" ] == mock_uuid
0 commit comments