def test_options_present_true_file(tmp_path, sections): """ Test to verify options present when file does exist and test=True """ name = str(tmp_path / "test_true_file.ini") exp_ret = { "name": name, "changes": {}, "result": None, "comment": ("Unchanged key hostname in section general.\n" "Unchanged key port in section general.\n" "Changed key user in section general.\n"), } ini_manage.options_present(name, sections) new_section = copy.deepcopy(sections) new_section["general"]["user"] = "******" with patch.dict(ini_manage.__opts__, {"test": True}), patch.dict(mod_ini_manage.__opts__, {"test": True}): assert ini_manage.options_present(name, new_section) == exp_ret assert os.path.exists(name) assert mod_ini_manage.get_ini(name) == sections
def test_options_present(self): ''' Test to verify options present in file. ''' name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(ini_manage.__opts__, {'test': True}): comt = 'No changes detected.' ret.update({'comment': comt, 'result': True}) self.assertDictEqual(ini_manage.options_present(name), ret) changes = { 'first': 'who is on', 'second': 'what is on', 'third': "I don't know" } with patch.dict(ini_manage.__salt__, {'ini.set_option': MagicMock(return_value=changes)}): with patch.dict(ini_manage.__opts__, {'test': False}): comt = ('Changes take effect') ret.update({ 'comment': comt, 'result': True, 'changes': changes }) self.assertDictEqual(ini_manage.options_present(name), ret)
def test_options_present(self): ''' Test to verify options present in file. ''' name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(ini_manage.__opts__, {'test': True}): comt = (('ini file {0} shall be validated for presence of ' 'given options under their respective ' 'sections').format(name)) ret.update({'comment': comt}) self.assertDictEqual(ini_manage.options_present(name), ret) changes = { 'first': 'who is on', 'second': 'what is on', 'third': "I don't know" } with patch.dict(ini_manage.__salt__, {'ini.set_option': MagicMock(return_value=changes)}): with patch.dict(ini_manage.__opts__, {'test': False}): comt = ('Changes take effect') ret.update({ 'comment': comt, 'result': True, 'changes': changes }) self.assertDictEqual(ini_manage.options_present(name), ret)
def test_options_present(self): ''' Test to verify options present in file. ''' name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(ini_manage.__opts__, {'test': True}): comt = (('ini file {0} shall be validated for presence of ' 'given options under their respective ' 'sections').format(name)) ret.update({'comment': comt}) self.assertDictEqual(ini_manage.options_present(name), ret) with patch.dict(ini_manage.__opts__, {'test': False}): comt = ('No anomaly detected') ret.update({'comment': comt, 'result': True}) self.assertDictEqual(ini_manage.options_present(name), ret)
def test_options_present(tmpdir, sections): """ Test to verify options present when file does not initially exist """ name = tmpdir.join("test.ini").strpath exp_ret = { "name": name, "changes": {"general": {"before": None, "after": sections["general"]}}, "result": True, "comment": "Changes take effect", } assert ini_manage.options_present(name, sections) == exp_ret assert os.path.exists(name) assert mod_ini_manage.get_ini(name) == sections
def test_options_present_true_no_file(tmpdir, sections): """ Test to verify options present when file does not initially exist and test=True """ name = tmpdir.join("test_true_no_file.ini").strpath exp_ret = { "name": name, "changes": {}, "result": None, "comment": "Changed key hostname in section general.\n" "Changed key port in section general.\n", } with patch.dict(ini_manage.__opts__, {"test": True}), patch.dict( mod_ini_manage.__opts__, {"test": True} ): assert ini_manage.options_present(name, sections) == exp_ret assert not os.path.exists(name)
def test_options_present(self): """ Test to verify options present in file. """ name = "salt" ret = {"name": name, "result": None, "comment": "", "changes": {}} with patch.dict(ini_manage.__opts__, {"test": True}): comt = "" ret.update({"comment": comt, "result": True}) self.assertDictEqual(ini_manage.options_present(name), ret) changes = { "first": "who is on", "second": "what is on", "third": "I don't know", } with patch.dict(ini_manage.__salt__, {"ini.set_option": MagicMock(return_value=changes)}): with patch.dict(ini_manage.__opts__, {"test": False}): comt = "Changes take effect" ret.update({ "comment": comt, "result": True, "changes": changes }) self.assertDictEqual(ini_manage.options_present(name), ret) original = { "mysection": { "first": "who is on", "second": "what is on", "third": "I don't know", } } desired = {"mysection": {"first": "who is on", "second": "what is on"}} changes = { "mysection": { "first": "who is on", "second": "what is on", "third": { "after": None, "before": "I don't know" }, } } with patch.dict(ini_manage.__salt__, {"ini.get_ini": MagicMock(return_value=original)}): with patch.dict( ini_manage.__salt__, {"ini.remove_option": MagicMock(return_value="third")}, ): with patch.dict( ini_manage.__salt__, {"ini.get_option": MagicMock(return_value="I don't know")}, ): with patch.dict( ini_manage.__salt__, {"ini.set_option": MagicMock(return_value=desired)}, ): with patch.dict(ini_manage.__opts__, {"test": False}): comt = "Changes take effect" ret.update({ "comment": comt, "result": True, "changes": changes }) self.assertDictEqual( ini_manage.options_present(name, desired, strict=True), ret, )
def test_options_present(self): ''' Test to verify options present in file. ''' name = 'salt' ret = {'name': name, 'result': None, 'comment': '', 'changes': {}} with patch.dict(ini_manage.__opts__, {'test': True}): comt = 'No changes detected.' ret.update({'comment': comt, 'result': True}) self.assertDictEqual(ini_manage.options_present(name), ret) changes = { 'first': 'who is on', 'second': 'what is on', 'third': "I don't know" } with patch.dict(ini_manage.__salt__, {'ini.set_option': MagicMock(return_value=changes)}): with patch.dict(ini_manage.__opts__, {'test': False}): comt = ('Changes take effect') ret.update({ 'comment': comt, 'result': True, 'changes': changes }) self.assertDictEqual(ini_manage.options_present(name), ret) original = { 'mysection': { 'first': 'who is on', 'second': 'what is on', 'third': "I don't know" } } desired = {'mysection': {'first': 'who is on', 'second': 'what is on'}} changes = { 'mysection': { 'first': 'who is on', 'second': 'what is on', 'third': { 'after': None, 'before': "I don't know" } } } with patch.dict( ini_manage.__salt__, {'ini.get_section': MagicMock(return_value=original['mysection']) }): with patch.dict( ini_manage.__salt__, {'ini.remove_option': MagicMock(return_value='third')}): with patch.dict( ini_manage.__salt__, {'ini.get_option': MagicMock(return_value="I don't know") }): with patch.dict( ini_manage.__salt__, {'ini.set_option': MagicMock(return_value=desired)}): with patch.dict(ini_manage.__opts__, {'test': False}): comt = ('Changes take effect') ret.update({ 'comment': comt, 'result': True, 'changes': changes }) self.assertDictEqual( ini_manage.options_present(name, desired, strict=True), ret)