Skip to content

Commit

Permalink
Update tests for pytest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwkimball committed Feb 11, 2024
1 parent 4eda023 commit 7a046e0
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 422 deletions.
5 changes: 4 additions & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ rm -rf /tmp/yamlpath-python-coverage-data
rm -f .coverage

for pythonVersion in "${@}"; do
which deactivate &>/dev/null && deactivate &>/dev/null
if which deactivate &>/dev/null; then
echo "Deactivating Python $(python --version). If this dumps you right back to the shell prompt, you were running Microsoft's VSCode-embedded Python and were just put into a sub-shell; just exit to resume tests."
deactivate
fi

pyCommand=python${pythonVersion}
if ! which "$pyCommand" &>/dev/null; then
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def old_eyaml_keys(tmp_path_factory):

return (old_private_key_file, old_public_key_file)

@requireseyaml
@pytest.fixture(scope="session")
def new_eyaml_keys(tmp_path_factory):
"""Creates temporary keys for encryption/decryption tests."""
Expand Down
46 changes: 23 additions & 23 deletions tests/test_commands_eyaml_rotate_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ class Test_eyaml_rotate_keys():
command = "eyaml-rotate-keys"

def test_no_options(self, script_runner):
result = script_runner.run(self.command)
result = script_runner.run([self.command])
assert not result.success, result.stderr
assert "usage: {}".format(self.command) in result.stderr

def test_duplicate_keys(self, script_runner):
bunk_key = "/does/not/exist/on-most/systems"
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(bunk_key),
"--newpublickey={}".format(bunk_key),
"--oldprivatekey={}".format(bunk_key),
"--oldpublickey={}".format(bunk_key),
bunk_key
)
])
assert not result.success, result.stderr
assert "The new and old EYAML keys must be different." in result.stderr

def test_bad_keys(self, script_runner):
bunk_file = "/does/not/exist/on-most/systems"
bunk_old_key = "/does/not/exist/on-most/systems/old"
bunk_new_key = "/does/not/exist/on-most/systems/new"
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(bunk_new_key),
"--newpublickey={}".format(bunk_new_key),
"--oldprivatekey={}".format(bunk_old_key),
"--oldpublickey={}".format(bunk_old_key),
bunk_file
)
])
assert not result.success, result.stderr
assert "EYAML key is not a readable file:" in result.stderr

@requireseyaml
def test_no_yaml_files(self, script_runner, old_eyaml_keys, new_eyaml_keys):
bunk_file = "/does/not/exist/on-most/systems"
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
bunk_file
)
])
assert not result.success, result.stderr
assert "Not a file:" in result.stderr

Expand Down Expand Up @@ -99,15 +99,15 @@ def test_good_multi_replacements(self, script_runner, tmp_path_factory, old_eyam
simple_file = create_temp_yaml_file(tmp_path_factory, simple_content)
anchored_file = create_temp_yaml_file(tmp_path_factory, anchored_content)

result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
simple_file,
anchored_file
)
])
assert result.success, result.stderr

with open(simple_file, 'r') as fhnd:
Expand Down Expand Up @@ -171,38 +171,38 @@ def test_good_multi_replacements(self, script_runner, tmp_path_factory, old_eyam
assert unwrap_node_coords(node) == 'This is a test value.'

def test_yaml_parsing_error(self, script_runner, imparsible_yaml_file, old_eyaml_keys, new_eyaml_keys):
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
imparsible_yaml_file
)
])
assert not result.success, result.stderr
assert "YAML parsing error" in result.stderr

def test_yaml_syntax_error(self, script_runner, badsyntax_yaml_file, old_eyaml_keys, new_eyaml_keys):
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
badsyntax_yaml_file
)
])
assert not result.success, result.stderr
assert "YAML syntax error" in result.stderr

def test_yaml_composition_error(self, script_runner, badcmp_yaml_file, old_eyaml_keys, new_eyaml_keys):
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
badcmp_yaml_file
)
])
assert not result.success, result.stderr
assert "YAML composition error" in result.stderr

Expand All @@ -213,14 +213,14 @@ def test_corrupted_eyaml_value(self, script_runner, tmp_path_factory, old_eyaml_
DBAEqBBAwcy7jvcOGcMfLEtugGVWWUnWq1DJ4Q==]
"""
yaml_file = create_temp_yaml_file(tmp_path_factory, content)
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
yaml_file
)
])
assert not result.success, result.stderr
assert "Unable to decrypt value!" in result.stderr

Expand All @@ -239,14 +239,14 @@ def test_bad_recryption_key(self, script_runner, tmp_path_factory, old_eyaml_key
NI/TSIF7M9U=]
"""
yaml_file = create_temp_yaml_file(tmp_path_factory, content)
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[1]),
"--newpublickey={}".format(new_eyaml_keys[0]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
yaml_file
)
])
assert not result.success, result.stderr
assert "unable to encrypt" in result.stderr or "cannot be run due to exit code: 1" in result.stderr

Expand All @@ -267,15 +267,15 @@ def test_backup_file(self, script_runner, tmp_path_factory, old_eyaml_keys, new_
"""
yaml_file = create_temp_yaml_file(tmp_path_factory, content)
backup_file = yaml_file + ".bak"
result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
"--backup",
yaml_file
)
])
assert result.success, result.stderr
assert os.path.isfile(backup_file)

Expand Down Expand Up @@ -303,15 +303,15 @@ def test_replace_backup_file(self, script_runner, tmp_path_factory, old_eyaml_ke
with open(backup_file, 'w') as fhnd:
fhnd.write(content + "\nkey2: plain scalar string value")

result = script_runner.run(
result = script_runner.run([
self.command,
"--newprivatekey={}".format(new_eyaml_keys[0]),
"--newpublickey={}".format(new_eyaml_keys[1]),
"--oldprivatekey={}".format(old_eyaml_keys[0]),
"--oldpublickey={}".format(old_eyaml_keys[1]),
"--backup",
yaml_file
)
])
assert result.success, result.stderr
assert os.path.isfile(backup_file)

Expand Down
Loading

0 comments on commit 7a046e0

Please sign in to comment.