Skip to content

Commit 25d16e2

Browse files
committed
tests/_internal/remotes(fix) Clear env tokens in authentication tests
why: Tests for is_authenticated=False were failing because tokens from environment variables (GITHUB_TOKEN, GITLAB_TOKEN, etc.) were being detected. what: - Add monkeypatch to clear token env vars in test_*_is_authenticated_without_token - Fix test_gitlab_search_requires_auth to clear GITLAB_TOKEN/GL_TOKEN - Add pytest import to test_gitea.py
1 parent b2f1d3f commit 25d16e2

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

tests/_internal/remotes/test_gitea.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import json
66
import typing as t
77

8+
import pytest
9+
810
from vcspull._internal.remotes.base import ImportMode, ImportOptions
911
from vcspull._internal.remotes.gitea import GiteaImporter
1012

@@ -104,8 +106,14 @@ def test_gitea_importer_service_name() -> None:
104106
assert importer.service_name == "Gitea"
105107

106108

107-
def test_gitea_importer_is_authenticated_without_token() -> None:
109+
def test_gitea_importer_is_authenticated_without_token(
110+
monkeypatch: pytest.MonkeyPatch,
111+
) -> None:
108112
"""Test is_authenticated returns False without token."""
113+
# Clear environment variables that could provide a token
114+
monkeypatch.delenv("CODEBERG_TOKEN", raising=False)
115+
monkeypatch.delenv("GITEA_TOKEN", raising=False)
116+
monkeypatch.delenv("FORGEJO_TOKEN", raising=False)
109117
importer = GiteaImporter(token=None)
110118
assert importer.is_authenticated is False
111119

tests/_internal/remotes/test_github.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,13 @@ def test_github_fetch_search(
310310
assert repos[0].stars == 1000
311311

312312

313-
def test_github_importer_is_authenticated_without_token() -> None:
313+
def test_github_importer_is_authenticated_without_token(
314+
monkeypatch: pytest.MonkeyPatch,
315+
) -> None:
314316
"""Test is_authenticated returns False without token."""
317+
# Clear environment variables that could provide a token
318+
monkeypatch.delenv("GITHUB_TOKEN", raising=False)
319+
monkeypatch.delenv("GH_TOKEN", raising=False)
315320
importer = GitHubImporter(token=None)
316321
assert importer.is_authenticated is False
317322

tests/_internal/remotes/test_gitlab.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ def test_gitlab_fetch_group(
5252
assert repos[0].name == "group-project"
5353

5454

55-
def test_gitlab_search_requires_auth() -> None:
55+
def test_gitlab_search_requires_auth(
56+
monkeypatch: pytest.MonkeyPatch,
57+
) -> None:
5658
"""Test GitLab search raises error without authentication."""
5759
from vcspull._internal.remotes.base import AuthenticationError
5860

61+
# Clear environment variables that could provide a token
62+
monkeypatch.delenv("GITLAB_TOKEN", raising=False)
63+
monkeypatch.delenv("GL_TOKEN", raising=False)
5964
importer = GitLabImporter(token=None)
6065
options = ImportOptions(mode=ImportMode.SEARCH, target="test")
6166
with pytest.raises(AuthenticationError, match="requires authentication"):
@@ -88,8 +93,13 @@ def test_gitlab_search_with_auth(
8893
assert repos[0].name == "search-result"
8994

9095

91-
def test_gitlab_importer_is_authenticated_without_token() -> None:
96+
def test_gitlab_importer_is_authenticated_without_token(
97+
monkeypatch: pytest.MonkeyPatch,
98+
) -> None:
9299
"""Test is_authenticated returns False without token."""
100+
# Clear environment variables that could provide a token
101+
monkeypatch.delenv("GITLAB_TOKEN", raising=False)
102+
monkeypatch.delenv("GL_TOKEN", raising=False)
93103
importer = GitLabImporter(token=None)
94104
assert importer.is_authenticated is False
95105

0 commit comments

Comments
 (0)