Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/test_wlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

import io
import os
import warnings
from abc import ABC
from typing import ClassVar
from unittest.mock import patch
from urllib.parse import urlencode

import responses
from requests import Response
from urllib3.exceptions import InsecureRequestWarning
from urllib3.util.retry import Retry

from wlc import (
Expand Down Expand Up @@ -248,6 +251,33 @@ def test_should_verify_ssl(self) -> None:
)
self.assertEqual(Weblate.should_verify_ssl("http://example.com/api/"), True)

def test_insecure_warning_is_not_suppressed(self) -> None:
response = Response()
response.status_code = 200
weblate = Weblate(url="https://localhost/api/")

def request(*_args: object, **_kwargs: object) -> Response:
warnings.warn("insecure", InsecureRequestWarning, stacklevel=2)
warnings.warn("unrelated", UserWarning, stacklevel=2)
return response

with (
patch.object(weblate.session, "request", side_effect=request),
warnings.catch_warnings(record=True) as caught,
):
warnings.simplefilter("always")
weblate.invoke_request("GET", weblate.url)
warnings.warn("insecure afterward", InsecureRequestWarning, stacklevel=1)

self.assertEqual(
[(warning.category, str(warning.message)) for warning in caught],
[
(InsecureRequestWarning, "insecure"),
(UserWarning, "unrelated"),
(InsecureRequestWarning, "insecure afterward"),
],
)

def test_paginated_listing_uses_params_only_for_first_request(self) -> None:
"""The API-provided next URL already includes query parameters."""
query = "language:en AND state:<translated"
Expand Down
4 changes: 0 additions & 4 deletions wlc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import json
import logging
from collections.abc import Collection, Iterator, Mapping
from ipaddress import ip_address
from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar
Expand Down Expand Up @@ -300,9 +299,6 @@ def invoke_request(
headers["Authorization"] = f"Token {self.key}"
verify_ssl = self.should_verify_ssl(path)

# Disable insecure warnings for localhost
if not verify_ssl:
logging.captureWarnings(True)
json_data: RequestPayload | None
if files:
# multipart/form upload
Expand Down
Loading