def test_boolean(self): """ Test to set up an SELinux boolean. """ name = "samba_create_home_dirs" value = True ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_en = MagicMock(return_value=[]) with patch.dict(selinux.__salt__, {"selinux.list_sebool": mock_en}): comt = "Boolean {0} is not available".format(name) ret.update({"comment": comt}) self.assertDictEqual(selinux.boolean(name, value), ret) mock_bools = MagicMock( return_value={name: { "State": "on", "Default": "on" }}) with patch.dict(selinux.__salt__, {"selinux.list_sebool": mock_bools}): comt = "None is not a valid value for the boolean" ret.update({"comment": comt}) self.assertDictEqual(selinux.boolean(name, None), ret) comt = "Boolean is in the correct state" ret.update({"comment": comt, "result": True}) self.assertDictEqual(selinux.boolean(name, value, True), ret) comt = "Boolean is in the correct state" ret.update({"comment": comt, "result": True}) self.assertDictEqual(selinux.boolean(name, value), ret) mock_bools = MagicMock( return_value={name: { "State": "off", "Default": "on" }}) mock = MagicMock(side_effect=[True, False]) with patch.dict( selinux.__salt__, { "selinux.list_sebool": mock_bools, "selinux.setsebool": mock }, ): with patch.dict(selinux.__opts__, {"test": True}): comt = "Boolean samba_create_home_dirs" " is set to be changed to on" ret.update({"comment": comt, "result": None}) self.assertDictEqual(selinux.boolean(name, value), ret) with patch.dict(selinux.__opts__, {"test": False}): comt = "Boolean samba_create_home_dirs has been set to on" ret.update({"comment": comt, "result": True}) ret.update({"changes": {"State": {"old": "off", "new": "on"}}}) self.assertDictEqual(selinux.boolean(name, value), ret) comt = "Failed to set the boolean " "samba_create_home_dirs to on" ret.update({"comment": comt, "result": False}) ret.update({"changes": {}}) self.assertDictEqual(selinux.boolean(name, value), ret)
def test_boolean(self): ''' Test to set up an SELinux boolean. ''' name = 'samba_create_home_dirs' value = True ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} mock_en = MagicMock(return_value=[]) with patch.dict(selinux.__salt__, {'selinux.list_sebool': mock_en}): comt = ('Boolean {0} is not available'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(selinux.boolean(name, value), ret) mock_bools = MagicMock( return_value={name: { 'State': 'on', 'Default': 'on' }}) with patch.dict(selinux.__salt__, {'selinux.list_sebool': mock_bools}): comt = ('None is not a valid value for the boolean') ret.update({'comment': comt}) self.assertDictEqual(selinux.boolean(name, None), ret) comt = ('Boolean is in the correct state') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(selinux.boolean(name, value, True), ret) comt = ('Boolean is in the correct state') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(selinux.boolean(name, value), ret) mock_bools = MagicMock( return_value={name: { 'State': 'off', 'Default': 'on' }}) mock = MagicMock(side_effect=[True, False]) with patch.dict(selinux.__salt__, { 'selinux.list_sebool': mock_bools, 'selinux.setsebool': mock }): with patch.dict(selinux.__opts__, {'test': True}): comt = ('Boolean samba_create_home_dirs' ' is set to be changed to on') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(selinux.boolean(name, value), ret) with patch.dict(selinux.__opts__, {'test': False}): comt = ('Boolean samba_create_home_dirs has been set to on') ret.update({'comment': comt, 'result': True}) ret.update({'changes': {'State': {'old': 'off', 'new': 'on'}}}) self.assertDictEqual(selinux.boolean(name, value), ret) comt = ('Failed to set the boolean ' 'samba_create_home_dirs to on') ret.update({'comment': comt, 'result': False}) ret.update({'changes': {}}) self.assertDictEqual(selinux.boolean(name, value), ret)
def test_boolean(self): ''' Test to set up an SELinux boolean. ''' name = 'samba_create_home_dirs' value = True ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''} mock_en = MagicMock(return_value=[]) with patch.dict(selinux.__salt__, {'selinux.list_sebool': mock_en}): comt = ('Boolean {0} is not available'.format(name)) ret.update({'comment': comt}) self.assertDictEqual(selinux.boolean(name, value), ret) mock_bools = MagicMock(return_value={name: {'State': 'on', 'Default': 'on'}}) with patch.dict(selinux.__salt__, {'selinux.list_sebool': mock_bools}): comt = ('None is not a valid value for the boolean') ret.update({'comment': comt}) self.assertDictEqual(selinux.boolean(name, None), ret) comt = ('Boolean is in the correct state') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(selinux.boolean(name, value, True), ret) comt = ('Boolean is in the correct state') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(selinux.boolean(name, value), ret) mock_bools = MagicMock(return_value={name: {'State': 'off', 'Default': 'on'}}) mock = MagicMock(side_effect=[True, False]) with patch.dict(selinux.__salt__, {'selinux.list_sebool': mock_bools, 'selinux.setsebool': mock}): with patch.dict(selinux.__opts__, {'test': True}): comt = ('Boolean samba_create_home_dirs' ' is set to be changed to on') ret.update({'comment': comt, 'result': None}) self.assertDictEqual(selinux.boolean(name, value), ret) with patch.dict(selinux.__opts__, {'test': False}): comt = ('Boolean samba_create_home_dirs has been set to on') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(selinux.boolean(name, value), ret) comt = ('Failed to set the boolean ' 'samba_create_home_dirs to on') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(selinux.boolean(name, value), ret)