コード例 #1
0
ファイル: test_ini_manage.py プロジェクト: mcalmer/salt
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
コード例 #2
0
 def test_get_ini(self):
     '''
     Test get_ini method.
     '''
     self.assertEqual(
         dict(ini.get_ini(self.tfile.name)), {
             'SectionC': {'empty_option': ''},
             'SectionB': {'test1': 'value 1B', 'test3': 'value 3B'},
             'main': {'test1': 'value 1', 'test2': 'value 2'},
             'option2': 'main2', 'option1': 'main1'})
コード例 #3
0
 def test_get_ini(self):
     """
     Test get_ini method.
     """
     self.assertEqual(
         dict(ini.get_ini(self.tfile.name)),
         {
             "SectionC": {"empty_option": ""},
             "SectionB": {"test1": "value 1B", "test3": "value 3B"},
             "main": {"test1": "value 1", "test2": "value 2"},
             "option2": "main2",
             "option1": "main1",
         },
     )
コード例 #4
0
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