|
3 | 3 | import os
|
4 | 4 |
|
5 | 5 | from typing import TYPE_CHECKING
|
| 6 | +from unittest.mock import MagicMock |
6 | 7 |
|
7 | 8 | import pytest
|
8 | 9 |
|
@@ -222,18 +223,47 @@ def test_fail_keyring_should_be_unavailable(
|
222 | 223 |
|
223 | 224 |
|
224 | 225 | def test_get_http_auth_from_environment_variables(
|
225 |
| - environ: None, config: Config, with_simple_keyring: None |
| 226 | + environ: None, config: Config |
226 | 227 | ) -> None:
|
227 | 228 | os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar"
|
228 | 229 | os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz"
|
229 | 230 |
|
230 | 231 | manager = PasswordManager(config)
|
231 | 232 |
|
232 | 233 | auth = manager.get_http_auth("foo")
|
233 |
| - assert auth is not None |
| 234 | + assert auth == {"username": "bar", "password": "baz"} |
234 | 235 |
|
235 |
| - assert auth["username"] == "bar" |
236 |
| - assert auth["password"] == "baz" |
| 236 | + |
| 237 | +def test_get_http_auth_does_not_call_keyring_when_credentials_in_environment_variables( |
| 238 | + environ: None, config: Config |
| 239 | +) -> None: |
| 240 | + os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar" |
| 241 | + os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz" |
| 242 | + |
| 243 | + manager = PasswordManager(config) |
| 244 | + manager._keyring = MagicMock() |
| 245 | + |
| 246 | + auth = manager.get_http_auth("foo") |
| 247 | + assert auth == {"username": "bar", "password": "baz"} |
| 248 | + manager._keyring.get_password.assert_not_called() |
| 249 | + |
| 250 | + |
| 251 | +def test_get_http_auth_does_not_call_keyring_when_password_in_environment_variables( |
| 252 | + environ: None, config: Config |
| 253 | +) -> None: |
| 254 | + config.merge( |
| 255 | + { |
| 256 | + "http-basic": {"foo": {"username": "bar"}}, |
| 257 | + } |
| 258 | + ) |
| 259 | + os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz" |
| 260 | + |
| 261 | + manager = PasswordManager(config) |
| 262 | + manager._keyring = MagicMock() |
| 263 | + |
| 264 | + auth = manager.get_http_auth("foo") |
| 265 | + assert auth == {"username": "bar", "password": "baz"} |
| 266 | + manager._keyring.get_password.assert_not_called() |
237 | 267 |
|
238 | 268 |
|
239 | 269 | def test_get_pypi_token_with_env_var_positive(
|
|
0 commit comments