Skip to content

Commit 8d22fc0

Browse files
authored
V0.2.2 fix: webshare provider respects page param in search_params (#4)
fix: webshare provider respects `page` param in search_params Previously, `list_proxies()` would ignore the `page` parameter and fetch all available pages. Now fetches only the specified page when `page` is provided. This also bumps pyproject.toml configurations for poetry changes. Fixes #3
1 parent ddcc822 commit 8d22fc0

6 files changed

Lines changed: 81 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
python-version: ${{ matrix.python-version }}
2222

2323
- name: Install Poetry
24-
run: curl -sSL https://install.python-poetry.org | python3 -
24+
run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.3 python3 -
2525

2626
- name: Configure Poetry to create virtualenvs in project root
2727
run: poetry config virtualenvs.in-project true

proxyproviders/providers/webshare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _fetch_proxies(self) -> List[Proxy]:
9292

9393
all_proxies.extend([self._convert_to_proxy(proxy) for proxy in proxy_data])
9494

95-
if data.get("next") is None: # no more pages
95+
if "page" in self.search_params or data.get("next") is None:
9696
break
9797

9898
return all_proxies

proxyproviders/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version information for proxyproviders package."""
22

3-
__version__ = "0.2.1"
3+
__version__ = "0.2.2"

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

5+
[tool.poetry]
6+
name = "proxyproviders"
7+
version = "0.2.2"
8+
description = "A unified interface for different proxy providers"
9+
authors = ["David Teather <contact.davidteather@gmail.com>"]
10+
11+
[tool.poetry.dependencies]
12+
python = ">=3.9"
13+
514
[project]
615
name = "proxyproviders"
7-
version = "0.2.1"
16+
version = "0.2.2"
817
description = "A unified interface for different proxy providers"
918
readme = "README.md"
1019
authors = [{ name = "David Teather", email = "contact.davidteather@gmail.com" }]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.2.1
2+
current_version = 0.2.2
33

44
[bumpversion:file:setup.cfg]
55
search = version = {current_version}

tests/providers/test_webshare.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,73 @@ def test_bad_proxy_format_response(mock_webshare):
182182
mock_webshare._fetch_proxies()
183183

184184

185+
@responses.activate
186+
def test_fetch_proxies_specific_page_stops_after_one_request():
187+
"""
188+
Regression test: When 'page' is in search_params, _fetch_proxies() must
189+
make exactly one API call and return only that page's results, even if the
190+
response contains a 'next' URL indicating further pages exist.
191+
"""
192+
provider = Webshare(
193+
api_key="test-api-key", search_params={"page": 2, "page_size": 25}
194+
)
195+
196+
responses.add(
197+
responses.GET,
198+
"https://proxy.webshare.io/api/v2/proxy/list",
199+
json={
200+
"results": [
201+
{
202+
"id": "1",
203+
"username": "user1",
204+
"password": "pass1",
205+
"proxy_address": "192.168.1.1",
206+
"port": 8080,
207+
"country_code": "US",
208+
"city_name": "New York",
209+
"created_at": "2023-05-10T12:34:56",
210+
}
211+
],
212+
"next": "https://proxy.webshare.io/api/v2/proxy/list?page=3&page_size=25",
213+
},
214+
status=200,
215+
)
216+
217+
proxies = provider._fetch_proxies()
218+
219+
assert len(responses.calls) == 1
220+
assert len(proxies) == 1
221+
assert proxies[0].proxy_address == "192.168.1.1"
222+
223+
224+
@responses.activate
225+
def test_fetch_proxies_specific_page_sends_correct_params():
226+
"""
227+
Regression test: Verify the page value from search_params is forwarded
228+
to the API verbatim (not overridden by the internal loop counter).
229+
"""
230+
provider = Webshare(
231+
api_key="test-api-key", search_params={"page": 5, "page_size": 10}
232+
)
233+
234+
responses.add(
235+
responses.GET,
236+
"https://proxy.webshare.io/api/v2/proxy/list",
237+
json={
238+
"results": [],
239+
"next": "https://proxy.webshare.io/api/v2/proxy/list?page=6&page_size=10",
240+
},
241+
status=200,
242+
)
243+
244+
provider._fetch_proxies()
245+
246+
assert len(responses.calls) == 1
247+
request_url = responses.calls[0].request.url
248+
assert "page=5" in request_url
249+
assert "page_size=10" in request_url
250+
251+
185252
@responses.activate
186253
def test_invalid_proxy_timestamp(mock_webshare):
187254
"""

0 commit comments

Comments
 (0)