mirror of
https://github.com/benbusby/whoogle-search.git
synced 2025-11-01 19:18:19 -04:00
34 lines
909 B
Python
34 lines
909 B
Python
import types
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from app.services.http_client import HttpxClient
|
|
|
|
|
|
def test_httpxclient_follow_redirects_and_proxy(monkeypatch):
|
|
calls = []
|
|
|
|
class FakeClient:
|
|
def __init__(self, *args, **kwargs):
|
|
calls.append(kwargs)
|
|
def get(self, *args, **kwargs):
|
|
class R:
|
|
status_code = 200
|
|
text = ''
|
|
return R()
|
|
def close(self):
|
|
pass
|
|
|
|
monkeypatch.setattr(httpx, 'Client', FakeClient)
|
|
|
|
proxies = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'}
|
|
client = HttpxClient(proxies=proxies)
|
|
|
|
# Ensure the constructor attempted to set follow_redirects and one of proxy/proxies
|
|
assert len(calls) == 1
|
|
kwargs = calls[0]
|
|
assert kwargs.get('follow_redirects') is True
|
|
assert ('proxy' in kwargs) or ('proxies' in kwargs) or ('mounts' in kwargs)
|
|
|