Skip to content

auth/twitch_auth.py at 60% coverage — _post and _validate_with_twitch untested #57

@FlorentPoinsaut

Description

@FlorentPoinsaut

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority — noticeable but not blockingtestingTest coverage and quality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions