-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
377 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
from typing import Optional, Text, TextIO | ||
from typing import Optional, Text, TextIO, Tuple | ||
|
||
class PypircPlugin: | ||
def devpiclient_get_password(self, url: Text, username: Text) -> Optional[Text]: ... | ||
|
||
def _find_password(fp: TextIO, url: Text, username: Text) -> Optional[Text]: ... | ||
|
||
class KeyringPlugin: | ||
def devpiclient_get_password(self, url: Text, username: Text) -> Optional[Text]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import sys | ||
import pytest | ||
|
||
|
||
try: | ||
import configparser | ||
except ImportError: # pragma: no cover | ||
# python2 compat | ||
import ConfigParser as configparser | ||
|
||
|
||
@pytest.fixture | ||
def unload_imports(): | ||
for mod in ('devpi_ext', 'devpi_ext.login'): | ||
try: | ||
del sys.modules[mod] | ||
except KeyError: | ||
continue | ||
|
||
|
||
@pytest.fixture | ||
def pypirc(monkeypatch, tmp_path): | ||
parser = configparser.ConfigParser() | ||
parser.read_dict( | ||
{ | ||
'distutils': {'index-servers': '\nfizz'}, | ||
'fizz': { | ||
'repository': 'http://fizz', | ||
'username': 'fizz', | ||
'password': 'fizz', | ||
}, | ||
} | ||
) | ||
pypirc = tmp_path / '.pypirc' | ||
with pypirc.open('w', encoding='utf-8') as fp: | ||
parser.write(fp) | ||
with monkeypatch.context() as m: | ||
m.setattr('os.path.expanduser', lambda *args: str(tmp_path)) | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
try: | ||
import builtins | ||
except ImportError: | ||
import __builtin__ as builtins | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def no_keyring_installed(monkeypatch): | ||
import_orig = builtins.__import__ | ||
|
||
def mocked_import(name, *args): | ||
if name == 'keyring': | ||
print('xoxoxo') | ||
raise ImportError() | ||
return import_orig(name, *args) | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr(builtins, '__import__', mocked_import) | ||
yield | ||
|
||
|
||
@pytest.mark.usefixtures('unload_imports', 'no_keyring_installed') | ||
def test_password_is_none_when_keyring_not_importable(): | ||
from devpi_ext import login | ||
|
||
assert login.KeyringPlugin().devpiclient_get_password('http://fizz', 'buzz') is None | ||
|
||
|
||
@pytest.mark.usefixtures('unload_imports') | ||
def test_password_is_none_when_keyring_misses_credentials(monkeypatch): | ||
monkeypatch.setattr('keyring.get_password', lambda service, user: None) | ||
from devpi_ext import login | ||
|
||
assert login.KeyringPlugin().devpiclient_get_password('http://fizz', 'buzz') is None | ||
|
||
|
||
@pytest.mark.usefixtures('unload_imports') | ||
def test_password_is_found_when_keyring_stores_credentials(monkeypatch): | ||
monkeypatch.setattr('keyring.get_password', lambda service, user: 'fuzz') | ||
from devpi_ext import login | ||
|
||
assert ( | ||
login.KeyringPlugin().devpiclient_get_password('http://fizz', 'buzz') == 'fuzz' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.