Skip to content

Commit

Permalink
Apply monkeypatch fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-py authored and eladkal committed Jun 9, 2024
1 parent 81c5633 commit c47b3f1
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions tests/utils/test_log_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,29 +789,10 @@ def test_permissions_for_new_directories(tmp_path):
log_url = f"{worker_url}/log/{log_location}"


@pytest.fixture
def http_proxy():
_origin_http_proxy = os.getenv("http_proxy") or ""
os.environ["http_proxy"] = "http://proxy.example.com"
yield
os.environ["http_proxy"] = _origin_http_proxy


@pytest.fixture
def no_proxy():
_origin_no_proxy = os.getenv("no_proxy") or ""

def _set_no_proxy(values):
os.environ["no_proxy"] = values

yield _set_no_proxy
os.environ["no_proxy"] = _origin_no_proxy


@mock.patch("requests.adapters.HTTPAdapter.send")
@pytest.mark.usefixtures("http_proxy")
def test_fetch_logs_from_service_with_not_matched_no_proxy(mock_send, no_proxy):
no_proxy("localhost")
def test_fetch_logs_from_service_with_not_matched_no_proxy(mock_send, monkeypatch):
monkeypatch.setenv("http_proxy", "http://proxy.example.com")
monkeypatch.setenv("no_proxy", "localhost")

response = Response()
response.status_code = HTTPStatus.OK
Expand All @@ -828,9 +809,9 @@ def test_fetch_logs_from_service_with_not_matched_no_proxy(mock_send, no_proxy):


@mock.patch("requests.adapters.HTTPAdapter.send")
@pytest.mark.usefixtures("http_proxy")
def test_fetch_logs_from_service_with_cidr_no_proxy(mock_send, no_proxy):
no_proxy("10.0.0.0/8")
def test_fetch_logs_from_service_with_cidr_no_proxy(mock_send, monkeypatch):
monkeypatch.setenv("http_proxy", "http://proxy.example.com")
monkeypatch.setenv("no_proxy", "10.0.0.0/8")

response = Response()
response.status_code = HTTPStatus.OK
Expand Down

0 comments on commit c47b3f1

Please sign in to comment.