Skip to content

Commit 2544ba8

Browse files
authored
Merge pull request #921 from ScrapeGraphAI/codebeaver/pre/beta-920
Pre/beta - Unit Tests
2 parents 948164f + 4ce6d1b commit 2544ba8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_scrape_do.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import urllib.parse
2+
import pytest
3+
from unittest.mock import patch, Mock
4+
from scrapegraphai.docloaders.scrape_do import scrape_do_fetch
5+
6+
7+
def test_scrape_do_fetch_without_proxy():
8+
"""
9+
Test scrape_do_fetch function using API mode (without proxy).
10+
11+
This test verifies that:
12+
1. The function correctly uses the API mode when use_proxy is False.
13+
2. The correct URL is constructed with the token and encoded target URL.
14+
3. The function returns the expected response text.
15+
"""
16+
token = "test_token"
17+
target_url = "https://example.com"
18+
encoded_url = urllib.parse.quote(target_url)
19+
expected_response = "Mocked API response"
20+
21+
with patch("requests.get") as mock_get:
22+
mock_response = Mock()
23+
mock_response.text = expected_response
24+
mock_get.return_value = mock_response
25+
26+
result = scrape_do_fetch(token, target_url, use_proxy=False)
27+
28+
expected_url = f"http://api.scrape.do?token={token}&url={encoded_url}"
29+
mock_get.assert_called_once_with(expected_url)
30+
31+
assert result == expected_response

0 commit comments

Comments
 (0)