Skip to content

Commit

Permalink
add auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestfwilliams committed May 29, 2024
1 parent 0ca0aec commit 476f421
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_auth.py
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)

0 comments on commit 476f421

Please sign in to comment.