Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestfwilliams committed Nov 16, 2023
1 parent 5745517 commit 538163d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest

from hyp3lib.utils import ESA_HOST, get_esa_credentials


def test_get_esa_credentials_env(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.setenv('ESA_USERNAME', 'foo')
m.setenv('ESA_PASSWORD', 'bar')
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text(f'machine {ESA_HOST} login netrc_username password netrc_password')

username, password = get_esa_credentials()
assert username == 'foo'
assert password == 'bar'


def test_get_esa_credentials_netrc(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.delenv('ESA_USERNAME', raising=False)
m.delenv('ESA_PASSWORD', raising=False)
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text(f'machine {ESA_HOST} login foo password bar')

username, password = get_esa_credentials()
assert username == 'foo'
assert password == 'bar'


def test_get_esa_credentials_missing(tmp_path, monkeypatch):
with monkeypatch.context() as m:
m.delenv('ESA_USERNAME', raising=False)
m.setenv('ESA_PASSWORD', 'env_password')
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text('')
msg = 'Please provide.*'
with pytest.raises(ValueError, match=msg):
get_esa_credentials()

with monkeypatch.context() as m:
m.setenv('ESA_USERNAME', 'env_username')
m.delenv('ESA_PASSWORD', raising=False)
m.setenv('HOME', str(tmp_path))
(tmp_path / '.netrc').write_text('')
msg = 'Please provide.*'
with pytest.raises(ValueError, match=msg):
get_esa_credentials()

0 comments on commit 538163d

Please sign in to comment.