Skip to content

Commit c7770cd

Browse files
copilot review
1 parent 807802a commit c7770cd

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

cloudsmith_cli/cli/tests/test_webserver.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the webserver module."""
22

3+
from http.server import HTTPServer
34
from unittest.mock import MagicMock, PropertyMock, patch
45

56
import pytest
@@ -12,9 +13,12 @@ class TestAuthenticationWebServer:
1213

1314
def test_sso_access_token_initialized_to_none(self):
1415
"""Verify sso_access_token is initialized to None."""
15-
with patch.object(AuthenticationWebServer, "__init__", lambda *a, **kw: None):
16-
server = AuthenticationWebServer.__new__(AuthenticationWebServer)
17-
server.sso_access_token = None
16+
17+
def _fake_http_server_init(self, *args, **kwargs):
18+
self.socket = MagicMock()
19+
20+
with patch.object(HTTPServer, "__init__", _fake_http_server_init):
21+
server = AuthenticationWebServer(("localhost", 0), MagicMock())
1822
assert server.sso_access_token is None
1923

2024
def test_refresh_api_config_passes_sso_token(self):

cloudsmith_cli/core/keyring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def should_use_keyring():
1212
"""Check if keyring should be used based on CLOUDSMITH_NO_KEYRING env var."""
13-
env_value = os.environ.get("CLOUDSMITH_NO_KEYRING", "").lower()
13+
env_value = os.environ.get("CLOUDSMITH_NO_KEYRING", "").strip().lower()
1414
if env_value in ("1", "true", "yes"):
1515
return False
1616
return True

cloudsmith_cli/core/tests/test_keyring.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import getpass
22
import os
33
from datetime import datetime, timedelta, timezone
4-
from unittest.mock import patch
4+
from unittest.mock import ANY, patch
55

66
import keyring
77
import pytest
@@ -183,8 +183,6 @@ def test_get_refresh_token_when_error_raised(
183183

184184
@freeze_time("2024-06-01 10:00:00")
185185
def test_store_sso_tokens(self, mock_get_user, mock_set_password):
186-
refresh_attempted_at = datetime.utcnow().isoformat()
187-
188186
# Ensure keyring is enabled
189187
env = os.environ.copy()
190188
env.pop("CLOUDSMITH_NO_KEYRING", None)
@@ -201,7 +199,7 @@ def test_store_sso_tokens(self, mock_get_user, mock_set_password):
201199
mock_set_password.assert_any_call(
202200
"cloudsmith_cli-access_token_refresh_attempted_at-https://example.com",
203201
"test_user",
204-
refresh_attempted_at,
202+
ANY,
205203
)
206204
mock_set_password.assert_any_call(
207205
"cloudsmith_cli-refresh_token-https://example.com",
@@ -243,10 +241,3 @@ def test_returns_true_when_env_var_is_falsy(self, env_value):
243241
"""When CLOUDSMITH_NO_KEYRING is set to a falsy value, keyring should be used."""
244242
with patch.dict(os.environ, {"CLOUDSMITH_NO_KEYRING": env_value}):
245243
assert should_use_keyring() is True
246-
247-
def test_returns_true_when_env_var_not_set(self):
248-
"""When CLOUDSMITH_NO_KEYRING is not set at all, keyring should be used."""
249-
env = os.environ.copy()
250-
env.pop("CLOUDSMITH_NO_KEYRING", None)
251-
with patch.dict(os.environ, env, clear=True):
252-
assert should_use_keyring() is True

0 commit comments

Comments
 (0)