Skip to content

Commit

Permalink
Merge pull request #679 from garlic-os/patch-credentials-tests
Browse files Browse the repository at this point in the history
Fix credentials tests
  • Loading branch information
jlmaurer authored Aug 5, 2024
2 parents 8cc9722 + 62732f5 commit 077674f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
* [679](https://github.com/dbekaert/RAiDER/pull/679) - Fixed a bug causing test_updateTrue to falsely pass.

## [0.5.3]
### Fixed
* Updates dem-stitcher to 2.5.8 to ensure new (ARIA-managed) url for reading the Geoid EGM 2008. See this [issue](https://github.com/ACCESS-Cloud-Based-InSAR/dem-stitcher/issues/96).
Expand Down
10 changes: 5 additions & 5 deletions test/credentials/test_envVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ def test_envVars(
rc_path = rc_path.expanduser()
rc_path.unlink(missing_ok=True)

# Give the rc file mock contents
rc_path.write_text(template.format(uid=random_string(), key=random_string()))

test_uid = random_string()
test_key = random_string()

with monkeypatch.context() as mp:
mp.setenv(env_var_name_uid, test_uid)
mp.setenv(env_var_name_key, test_key)
credentials.check_api(model_name, None, None, './', update_rc_file=False)
credentials.check_api(model_name, None, None, './', update_rc_file=True)

expected_content = template.format(uid=test_uid, key=test_key)
actual_content = rc_path.read_text()
rc_path.unlink()

assert (
expected_content == actual_content,
f'{rc_path} was not updated correctly'
)
assert expected_content == actual_content, f'{rc_path} was not created correctly'
11 changes: 6 additions & 5 deletions test/credentials/test_updateTrue.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ def test_updateTrue(model_name, template):
return
rc_path = Path('./') / (hidden_ext + rc_filename)

# Give the rc file mock contents
rc_path.write_text(template.format(uid=random_string(), key=random_string()))

# Use check_api to update the rc file
test_uid = random_string()
test_key = random_string()
credentials.check_api(model_name, test_uid, test_key, './', update_rc_file=True)

# Check that the rc file was properly updated
expected_content = template.format(uid=test_uid, key=test_key)
actual_content = rc_path.read_text()
rc_path.unlink()

assert (
expected_content == actual_content,
f'{rc_path} was not updated correctly'
)
assert expected_content == actual_content, f'{rc_path} was not updated correctly'
4 changes: 2 additions & 2 deletions tools/RAiDER/models/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def check_api(model: str,
# one that belongs to this URL.
import netrc
rc_path.touch()
netrc_credentials = netrc.netrc(rc_path)
netrc_credentials.hosts[url] = (uid, None, key)
netrc_credentials = netrc.netrc(str(rc_path))
netrc_credentials.hosts[url] = (uid, '', key)
rc_path.write_text(str(netrc_credentials))
rc_path.chmod(0o000600)

Expand Down

0 comments on commit 077674f

Please sign in to comment.