1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

xfconf: add unit test for bool value (#5014)

This commit is contained in:
Alexei Znamensky 2022-07-28 19:21:23 +12:00 committed by GitHub
parent 9290381bea
commit 1c167ab894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Author: Alexei Znamensky (russoz@gmail.com) # Author: Alexei Znamensky (russoz@gmail.com)
# Largely adapted from test_redhat_subscription by # Largely adapted from test_redhat_subscription by
# Jiri Hnidek (jhnidek@redhat.com) # Jiri Hnidek (jhnidek@redhat.com)
@ -110,6 +111,41 @@ TEST_CASES = [
'value': '90', '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', 'channel': 'xfwm4',
@ -252,12 +288,6 @@ def test_xfconf(mocker, capfd, patch_xfconf, testcase):
assert results[test_result] == results['invocation']['module_args'][test_result], \ 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]) "'{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']) assert mock_run_command.call_count == len(testcase['run_command.calls'])
if mock_run_command.call_count: if mock_run_command.call_count:
call_args_list = [(item[0][0], item[1]) for item in mock_run_command.call_args_list] 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("call args list =\n%s" % call_args_list)
print("expected args list =\n%s" % expected_call_args_list) print("expected args list =\n%s" % expected_call_args_list)
assert call_args_list == 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])