From f083a0f4e7d069b444c94790b6cfd68ca65a7c7e Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 28 Jul 2022 21:14:50 +0200 Subject: [PATCH] xfconf: add unit test for bool value (#5014) (#5018) (cherry picked from commit 1c167ab8948afe429fd4591ea4434f14ab40a862) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- .../plugins/modules/system/test_xfconf.py | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/tests/unit/plugins/modules/system/test_xfconf.py b/tests/unit/plugins/modules/system/test_xfconf.py index 5744100c5e..7743d07cd4 100644 --- a/tests/unit/plugins/modules/system/test_xfconf.py +++ b/tests/unit/plugins/modules/system/test_xfconf.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Author: Alexei Znamensky (russoz@gmail.com) # Largely adapted from test_redhat_subscription by # Jiri Hnidek (jhnidek@redhat.com) @@ -110,6 +111,41 @@ TEST_CASES = [ 'value': '90', }, ], + [ + { + 'channel': 'xfce4-session', + 'property': '/general/SaveOnExit', + 'state': 'present', + 'value_type': 'bool', + 'value': False, + }, + { + 'id': 'test_property_set_property_bool_false', + 'run_command.calls': [ + ( + # Calling of following command will be asserted + ['/testbin/xfconf-query', '--channel', 'xfce4-session', '--property', '/general/SaveOnExit'], + # Was return code checked? + {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False}, + # Mock of returned code, stdout and stderr + (0, 'true\n', '',), + ), + ( + # Calling of following command will be asserted + ['/testbin/xfconf-query', '--channel', 'xfce4-session', '--property', '/general/SaveOnExit', + '--create', '--type', 'bool', '--set', 'false'], + # Was return code checked? + {'environ_update': {'LANGUAGE': 'C', 'LC_ALL': 'C'}, 'check_rc': False}, + # Mock of returned code, stdout and stderr + (0, 'false\n', '',), + ), + ], + 'changed': True, + 'previous_value': 'true', + 'value_type': 'bool', + 'value': 'False', + }, + ], [ { 'channel': 'xfwm4', @@ -252,12 +288,6 @@ def test_xfconf(mocker, capfd, patch_xfconf, testcase): assert results[test_result] == results['invocation']['module_args'][test_result], \ "'{0}': '{1}' != '{2}'".format(test_result, results[test_result], results['invocation']['module_args'][test_result]) - for conditional_test_result in ('msg', 'value', 'previous_value'): - if conditional_test_result in testcase: - assert conditional_test_result in results, "'{0}' not found in {1}".format(conditional_test_result, results) - assert results[conditional_test_result] == testcase[conditional_test_result], \ - "'{0}': '{1}' != '{2}'".format(conditional_test_result, results[conditional_test_result], testcase[conditional_test_result]) - assert mock_run_command.call_count == len(testcase['run_command.calls']) if mock_run_command.call_count: call_args_list = [(item[0][0], item[1]) for item in mock_run_command.call_args_list] @@ -265,3 +295,9 @@ def test_xfconf(mocker, capfd, patch_xfconf, testcase): print("call args list =\n%s" % call_args_list) print("expected args list =\n%s" % expected_call_args_list) assert call_args_list == expected_call_args_list + + for conditional_test_result in ('msg', 'value', 'previous_value'): + if conditional_test_result in testcase: + assert conditional_test_result in results, "'{0}' not found in {1}".format(conditional_test_result, results) + assert results[conditional_test_result] == testcase[conditional_test_result], \ + "'{0}': '{1}' != '{2}'".format(conditional_test_result, results[conditional_test_result], testcase[conditional_test_result])