From 089a7693e47b7adc21676b34c417cbb7ef0c288d Mon Sep 17 00:00:00 2001 From: Nate Kean <14845347+garlic-os@users.noreply.github.com> Date: Thu, 18 Jul 2024 16:01:01 -0500 Subject: [PATCH 1/5] Fix tautology The parentheses in the asserts in test_envVars and test_updateTrue were being interpreted as a set(!), making them always evaluate to True. This was resulting in these tests passing when there was actually something wrong with them. - Asserts fixed to evaluate correctly - Tests fixed to pass fair and square even with the corrected assertions --- test/credentials/test_envVars.py | 10 +++++----- test/credentials/test_updateTrue.py | 11 ++++++----- tools/RAiDER/models/credentials.py | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/credentials/test_envVars.py b/test/credentials/test_envVars.py index 9c8bcd07..1ec3ec28 100644 --- a/test/credentials/test_envVars.py +++ b/test/credentials/test_envVars.py @@ -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' diff --git a/test/credentials/test_updateTrue.py b/test/credentials/test_updateTrue.py index 9ed65fbc..5b31dbfc 100644 --- a/test/credentials/test_updateTrue.py +++ b/test/credentials/test_updateTrue.py @@ -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' diff --git a/tools/RAiDER/models/credentials.py b/tools/RAiDER/models/credentials.py index 70900bca..aad3fc05 100644 --- a/tools/RAiDER/models/credentials.py +++ b/tools/RAiDER/models/credentials.py @@ -151,7 +151,7 @@ def check_api(model: str, # one that belongs to this URL. 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) From 39c47594a0534e1019035f8a38e0aa126b07faa6 Mon Sep 17 00:00:00 2001 From: Nate Kean <14845347+garlic-os@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:35:33 -0500 Subject: [PATCH 2/5] Update CHANGELOG.md for #672 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21a32654..34636514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 +* [672](https://github.com/dbekaert/RAiDER/pull/672) - Fixed a bug causing test_updateTrue to falsely pass. + ## [0.5.2] ### Changed * [627](https://github.com/dbekaert/RAiDER/pull/627) - Made Python datetimes timezone-aware and added unit tests and bug fixes. From 19a9d9067314d1a848ff44ebf6ab157f2e8b6d2d Mon Sep 17 00:00:00 2001 From: Nate Kean <14845347+garlic-os@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:33:41 -0500 Subject: [PATCH 3/5] Give netrc empty string instead of None --- tools/RAiDER/models/credentials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/RAiDER/models/credentials.py b/tools/RAiDER/models/credentials.py index aad3fc05..17c2c9e3 100644 --- a/tools/RAiDER/models/credentials.py +++ b/tools/RAiDER/models/credentials.py @@ -152,7 +152,7 @@ def check_api(model: str, import netrc rc_path.touch() netrc_credentials = netrc.netrc(rc_path.name) - netrc_credentials.hosts[url] = (uid, None, key) + netrc_credentials.hosts[url] = (uid, '', key) rc_path.write_text(str(netrc_credentials)) rc_path.chmod(0o000600) From 0bf14ab8887f0b91f278b48f8f8a4767b1d949db Mon Sep 17 00:00:00 2001 From: Nate Kean <14845347+garlic-os@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:34:06 -0500 Subject: [PATCH 4/5] Fix typo I meant to turn the path into a string --- tools/RAiDER/models/credentials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/RAiDER/models/credentials.py b/tools/RAiDER/models/credentials.py index 17c2c9e3..e6c238cc 100644 --- a/tools/RAiDER/models/credentials.py +++ b/tools/RAiDER/models/credentials.py @@ -151,7 +151,7 @@ def check_api(model: str, # one that belongs to this URL. import netrc rc_path.touch() - netrc_credentials = netrc.netrc(rc_path.name) + netrc_credentials = netrc.netrc(str(rc_path)) netrc_credentials.hosts[url] = (uid, '', key) rc_path.write_text(str(netrc_credentials)) rc_path.chmod(0o000600) From 62732f5565cd20788c2ea28da4beb6bf977ce8e3 Mon Sep 17 00:00:00 2001 From: Nate Kean <14845347+garlic-os@users.noreply.github.com> Date: Thu, 1 Aug 2024 16:38:17 -0500 Subject: [PATCH 5/5] Update CHANGELOG.md for #679 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5725b1bb..c7958bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ### Fixed -* [672](https://github.com/dbekaert/RAiDER/pull/672) - Fixed a bug causing test_updateTrue to falsely pass. +* [679](https://github.com/dbekaert/RAiDER/pull/679) - Fixed a bug causing test_updateTrue to falsely pass. ## [0.5.3] ### Fixed