Skip to content

Commit 51427f6

Browse files
committed
update tests
1 parent 9a6c930 commit 51427f6

File tree

3 files changed

+72
-38
lines changed

3 files changed

+72
-38
lines changed

tests/proxy/test_proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
from unittest.mock import patch, Mock
3-
from src.oxylabs.proxy import Proxy
3+
from oxylabs.proxy import ProxyClient
44

55
class TestProxyGet(unittest.TestCase):
66
@patch('requests.Session')
@@ -40,7 +40,7 @@ def test_proxy_get_with_timeout(self, MockSession):
4040
session_instance.get.return_value = mock_response
4141

4242
# Initialize the Proxy with credentials
43-
proxy = Proxy("wsapiuman", "A1705pdVe9hil")
43+
proxy = ProxyClient("wsapiuman", "A1705pdVe9hil")
4444

4545
# Customize headers (optional)
4646
proxy.add_user_agent_header("desktop_chrome")

tests/sources/ecommerce/test_wayfair.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
2-
from src.oxylabs.sources.ecommerce import Ecommerce, EcommerceAsync
3-
from src.oxylabs.utils.types import user_agent_type
2+
from oxylabs.sources.ecommerce import Ecommerce, EcommerceAsync
3+
from oxylabs.utils.types import user_agent_type
44

55
class TestWayfairSearchSync(unittest.TestCase):
66
def test_wayfair_search_sync(self):

tests/sources/serp/test_bing.py

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,116 @@
11
import unittest
2-
from src.oxylabs.sources.serp import SERP, SERPAsync
3-
from src.oxylabs.utils.types import user_agent_type
2+
from oxylabs.utils.types import user_agent_type
3+
from oxylabs.internal import AsyncClient, RealtimeClient
44

55
class TestBingSearchSync(unittest.TestCase):
6+
"""
7+
Test case for synchronous Bing search.
8+
9+
This test case tests the functionality of the synchronous Bing search
10+
in the RealtimeClient class. It uses a mock response to simulate the
11+
behavior of the Bing search.
12+
"""
13+
614
def test_bing_search_sync(self):
715
"""
8-
Tests synchronous SERP's Bing search functionality to ensure it returns
9-
expected results.
16+
Test the synchronous Bing search.
1017
11-
Mocks the response from the _get_resp method to simulate SERP
12-
processing and validates that the method handles the search query
13-
correctly and returns the correct mock response.
18+
This test creates a RealtimeClient and sets its _get_resp method to a
19+
lambda function that returns a mock response. It then calls the
20+
scrape_search method with a query and checks that the returned result
21+
contains the mock response.
1422
"""
15-
serp = SERP('user', 'pass')
23+
client = RealtimeClient('user', 'pass')
1624
query = "nike"
17-
opts = {"domain": "com", "limit": 10}
18-
serp._get_resp = lambda payload, config: {"mocked_response": "search_results"}
25+
client._get_resp = lambda payload, config: {"mocked_response": "search_results"}
1926

20-
result = serp.bing.scrape_search(query, opts)
27+
result = client.serp.bing.scrape_search(query, domain="com", limit=10)
2128
self.assertIn("mocked_response", result)
2229
self.assertEqual(result["mocked_response"], "search_results")
2330

2431
class TestBingUrlSync(unittest.TestCase):
32+
"""
33+
Test case for synchronous Bing URL scraping.
34+
35+
This test case tests the functionality of the synchronous Bing URL scraping
36+
in the RealtimeClient class. It uses a mock response to simulate the
37+
behavior of the Bing URL scraping.
38+
"""
39+
2540
def test_bing_url_sync(self):
2641
"""
27-
Tests the SERP's Bing URL scraping functionality in a synchronous
28-
manner.
42+
Test the synchronous Bing URL scraping.
2943
30-
Mocks the _get_resp method to return controlled responses, ensuring
31-
that the method correctly processes the URL and user agent type,
32-
returning the expected data.
44+
This test creates a RealtimeClient and sets its _get_resp method to a
45+
lambda function that returns a mock response. It then calls the
46+
scrape_url method with a URL and checks that the returned result
47+
contains the mock response.
3348
"""
34-
serp = SERP('user', 'pass')
49+
50+
client = RealtimeClient('user', 'pass')
3551
url = "https://www.bing.com/search?q=nike"
3652
opts = {"user_agent_type": user_agent_type.DESKTOP}
37-
serp._get_resp = lambda payload, config: {"mocked_response": "url_results"}
53+
client._get_resp = lambda payload, config: {"mocked_response": "url_results"}
3854

39-
result = serp.bing.scrape_url(url, opts)
55+
result = client.serp.bing.scrape_url(url, opts)
4056
self.assertIn("mocked_response", result)
4157
self.assertEqual(result["mocked_response"], "url_results")
4258

59+
4360
class TestBingSearchAsync(unittest.IsolatedAsyncioTestCase):
61+
"""
62+
Test case for asynchronous Bing search.
63+
64+
This test case tests the functionality of the asynchronous Bing search
65+
in the AsyncClient class. It uses a mock response to simulate the
66+
behavior of the Bing search.
67+
"""
68+
4469
async def test_bing_search_async(self):
4570
"""
46-
Asynchronously tests SERP's Bing search to validate the async
47-
API handling.
71+
Test the asynchronous Bing search.
4872
49-
Uses a mocked asynchronous response to verify that the search query
50-
processing is handled correctly and that the async functionality
51-
returns expected results.
73+
This test creates an AsyncClient and sets its _get_resp method to a
74+
mock function that returns a mock response. It then calls the
75+
scrape_search method with a query and checks that the returned result
76+
contains the mock response.
5277
"""
53-
serp_async = SERPAsync('user', 'pass')
78+
client = AsyncClient('user', 'pass')
5479
query = "nike"
5580
opts = {"domain": "com", "limit": 10}
5681
async def mock_get_resp(payload, config):
5782
return {"mocked_response": "async_search_results"}
58-
serp_async._get_resp = mock_get_resp
83+
client._get_resp = mock_get_resp
5984

60-
result = await serp_async.bing_async.scrape_search(query, opts)
85+
result = await client.serp.bing.scrape_search(query, opts)
6186
self.assertIn("mocked_response", result)
6287
self.assertEqual(result["mocked_response"], "async_search_results")
6388

6489
class TestBingUrlAsync(unittest.IsolatedAsyncioTestCase):
90+
"""
91+
Test case for asynchronous Bing URL scraping.
92+
93+
This test case tests the functionality of the asynchronous Bing URL scraping
94+
in the AsyncClient class. It uses a mock response to simulate the
95+
behavior of the Bing URL scraping.
96+
"""
97+
6598
async def test_bing_url_async(self):
6699
"""
67-
Asynchronously tests SERP's Bing URL scraping functionality.
100+
Test the asynchronous Bing URL scraping.
68101
69-
Mocks the _get_resp method to provide controlled async responses,
70-
verifying that the URL and user agent options are processed correctly
71-
and yield expected outcomes.
102+
This test creates an AsyncClient and sets its _get_resp method to a
103+
mock function that returns a mock response. It then calls the
104+
scrape_url method with a URL and checks that the returned result
105+
contains the mock response.
72106
"""
73-
serp_async = SERPAsync('user', 'pass')
107+
client = AsyncClient('user', 'pass')
74108
url = "https://www.bing.com/search?q=nike"
75109
opts = {"user_agent_type": user_agent_type.DESKTOP}
76110
async def mock_get_resp(payload, config):
77111
return {"mocked_response": "async_url_results"}
78-
serp_async._get_resp = mock_get_resp
112+
client._get_resp = mock_get_resp
79113

80-
result = await serp_async.bing_async.scrape_url(url, opts)
114+
result = await client.serp.bing.scrape_url(url, opts)
81115
self.assertIn("mocked_response", result)
82116
self.assertEqual(result["mocked_response"], "async_url_results")

0 commit comments

Comments
 (0)