Skip to content

Commit

Permalink
Merge branch 'patch-credentials-tests' into linting
Browse files Browse the repository at this point in the history
  • Loading branch information
garlic-os committed Aug 1, 2024
2 parents 78a2f45 + 089a769 commit 0a7438e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions test/credentials/test_envVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +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'
6 changes: 5 additions & 1 deletion test/credentials/test_updateTrue.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +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'
2 changes: 1 addition & 1 deletion tools/RAiDER/models/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def check_api(
import netrc

rc_path.touch()
netrc_credentials = netrc.netrc(rc_path)
netrc_credentials = netrc.netrc(rc_path.name)
netrc_credentials.hosts[url] = (uid, None, key)
rc_path.write_text(str(netrc_credentials))
rc_path.chmod(0o000600)
Expand Down

0 comments on commit 0a7438e

Please sign in to comment.