From b77f03c603c743944e795a6d754eeec5789cf1b9 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Tue, 29 Nov 2022 14:51:50 -0500 Subject: [PATCH] Fix tests --- .../plugins/action/network/test_network.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/unit/plugins/action/network/test_network.py b/tests/unit/plugins/action/network/test_network.py index d076c1fab..a24b6ca6c 100644 --- a/tests/unit/plugins/action/network/test_network.py +++ b/tests/unit/plugins/action/network/test_network.py @@ -63,8 +63,9 @@ def test_backup_options(plugin, backup_dir, backup_file, role_path): # This doesn't need to be conditional, but doing so tests the equivalent # `if backup_options:` in the action plugin itself. + backup_options = None if backup_dir or backup_file: - plugin._task.args["backup_options"] = { + backup_options = { "dir_path": backup_dir, "filename": backup_file, } @@ -79,7 +80,7 @@ def test_backup_options(plugin, backup_dir, backup_file, role_path): try: # result is updated in place, nothing is returned - plugin._handle_backup_option(result, task_vars) + plugin._handle_backup_option(result, task_vars, backup_options) assert not result.get("failed") with open(result["backup_path"]) as backup_file_obj: @@ -108,7 +109,7 @@ def test_backup_options(plugin, backup_dir, backup_file, role_path): if backup_file: # check for idempotency result = {"__backup__": content} - plugin._handle_backup_option(result, task_vars) + plugin._handle_backup_option(result, task_vars, backup_options) assert not result.get("failed") assert result["changed"] is False @@ -123,7 +124,7 @@ def test_backup_no_content(plugin): with pytest.raises( AnsibleError, match="Failed while reading configuration backup" ): - plugin._handle_backup_option(result, task_vars) + plugin._handle_backup_option(result, task_vars, backup_options=None) def test_backup_options_error(plugin): @@ -131,13 +132,11 @@ def test_backup_options_error(plugin): task_vars = {} with tempfile.NamedTemporaryFile() as existing_file: - plugin._task.args = { - "backup_options": { - "dir_path": existing_file.name, - "filename": "backup_file", - } + backup_options = { + "dir_path": existing_file.name, + "filename": "backup_file", } - plugin._handle_backup_option(result, task_vars) + plugin._handle_backup_option(result, task_vars, backup_options) assert result["failed"] is True assert result["msg"] == (