Description
auth/twitch_auth.py sits at 60% coverage, the only module below the 80% target. The two core HTTP methods are not tested at the urllib.request.urlopen level — tests mock manager._post at a higher level, leaving the actual HTTP machinery uncovered.
Missing tests
_post()
- Sends correct
Content-Type: application/x-www-form-urlencoded header
- URL-encodes the request body
- Parses JSON response correctly
_validate_with_twitch()
- Returns
True on HTTP 200
- Returns
False on HTTPError (401)
- Sets
Authorization: OAuth <token> header
Example
def test_validate_with_twitch_returns_true_on_200(tmp_path):
manager = _make_manager(tmp_path)
fake_resp = MagicMock()
fake_resp.__enter__ = lambda s: s
fake_resp.__exit__ = MagicMock(return_value=False)
fake_resp.status = 200
with patch("urllib.request.urlopen", return_value=fake_resp):
assert manager._validate_with_twitch("valid_tok") is True
def test_validate_with_twitch_returns_false_on_401(tmp_path):
import urllib.error
manager = _make_manager(tmp_path)
with patch("urllib.request.urlopen", side_effect=urllib.error.HTTPError(None, 401, "Unauthorized", {}, None)):
assert manager._validate_with_twitch("bad_tok") is False
Also note
_wait_for_code() and login() require a real callback server and can be marked # pragma: no cover or tested with a threaded mock server.
Identified by
🧪 [Tech] Tester
Description
auth/twitch_auth.pysits at 60% coverage, the only module below the 80% target. The two core HTTP methods are not tested at theurllib.request.urlopenlevel — tests mockmanager._postat a higher level, leaving the actual HTTP machinery uncovered.Missing tests
_post()Content-Type: application/x-www-form-urlencodedheader_validate_with_twitch()Trueon HTTP 200FalseonHTTPError(401)Authorization: OAuth <token>headerExample
Also note
_wait_for_code()andlogin()require a real callback server and can be marked# pragma: no coveror tested with a threaded mock server.Identified by
🧪
[Tech] Tester