-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
0ca0aec
commit 476f421
Showing
1 changed file
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from pathlib import Path | ||
|
||
from opera_rtc_s1_browse import auth | ||
|
||
|
||
def test_get_netrc(monkeypatch): | ||
with monkeypatch.context() as m: | ||
m.setattr(auth, 'system', lambda: 'Windows') | ||
assert auth.get_netrc() == Path.home() / '_netrc' | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr(auth, 'system', lambda: 'Linux') | ||
assert auth.get_netrc() == Path.home() / '.netrc' | ||
|
||
|
||
def test_find_creds_in_env(monkeypatch): | ||
with monkeypatch.context() as m: | ||
m.setenv('TEST_USERNAME', 'foo') | ||
m.setenv('TEST_PASSWORD', 'bar') | ||
assert auth.find_creds_in_env('TEST_USERNAME', 'TEST_PASSWORD') == ('foo', 'bar') | ||
|
||
with monkeypatch.context() as m: | ||
m.delenv('TEST_USERNAME', raising=False) | ||
m.delenv('TEST_PASSWORD', raising=False) | ||
assert auth.find_creds_in_env('TEST_USERNAME', 'TEST_PASSWORD') == (None, None) | ||
|
||
|
||
def test_find_creds_in_netrc(tmp_path, monkeypatch): | ||
with monkeypatch.context() as m: | ||
m.setattr(auth, 'get_netrc', lambda: tmp_path / '.netrc') | ||
(tmp_path / '.netrc').write_text('machine test login foo password bar') | ||
assert auth.find_creds_in_netrc('test') == ('foo', 'bar') | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr(auth, 'get_netrc', lambda: tmp_path / '.netrc') | ||
(tmp_path / '.netrc').write_text('') | ||
assert auth.find_creds_in_netrc('test') == (None, None) |