Пример #1
0
 def testIsConfigEquals(self):
     ""
     self.assertFalse(
         self.config.isConfigEquals(
             ConfigManager("test-datas/sbackup.conf.good")))
     self.config = ConfigManager("test-datas/sbackup.conf.good")
     self.assertTrue(
         self.config.isConfigEquals(
             ConfigManager("test-datas/sbackup.conf.good")))
Пример #2
0
 def __get_configuration(self):
     _configfile_hdl = ConfigurationFileHandler()
     _config = None
     _configfile = _configfile_hdl.get_conffile()
     if local_file_utils.path_exists(_configfile):
         _config = ConfigManager(_configfile)
     else:
         _config = ConfigManager()
     return _config
Пример #3
0
 def testread(self):
     "Testing the config file read function "
     self.assertRaises(SBException, ConfigManager, "sbackup.conf.fake")
     self.config = ConfigManager("test-datas/sbackup.conf.good")
     self.assertEqual(self.config.conffile, "test-datas/sbackup.conf.good")
     #        for s in self.config.sections():
     #            print(str(s))
     #        self.assertEqual(len(self.config.sections()),3)
     self.assertEqual(len(self.config.options("dirconfig")), 10)
     self.assertEqual(len(self.config.options("general")), 4)
     self.assertEqual(len(self.config.options("exclude")), 2)
Пример #4
0
    def __retrieve_confm(self, force_conffile):
        """Factory method that retrieves the appropriate configuration managers
        for the existing profiles. Super-user rights are taken into account.
        The created configuration managers are stored in member variable
        'self.__confm'.

        :todo: Place the path names in class `ConfigStaticData`.

        """
        self.__confm = []

        # default profile config file and the config directory is determined
        conffile_hdl = ConfigurationFileHandler()
        if force_conffile is None:
            conffile = conffile_hdl.get_conffile()
        else:
            # conffile given on commandline is treated as default profile's config
            conffile = force_conffile
        confdir = conffile_hdl.get_profilesdir(conffile)

        # create config manager for the default profile and set as current
        if local_file_utils.path_exists(conffile):
            confm = ConfigManager(conffile)
            self.__profilename = confm.getProfileName()
            self.__confm.append(
                confm)  # store the created ConfigManager in a collection
        else:
            errmsg = _(
                "Critical Error: No configuration file for the default profile was found!\n\nNow continue processing remaining profiles."
            )
            self.__errors.append(errmsg)

        if force_conffile is None:
            # search for alternate configuration files only if no config file was given
            for _prof in get_profiles(confdir).values():
                _prof_path = _prof[0]
                _prof_enable = _prof[1]

                if _prof_enable:
                    confm = ConfigManager(_prof_path)
                    self.__confm.append(confm)
Пример #5
0
 def testvalidate_config_file_options(self):
     "Validate config file"
     self.assertRaises(NonValidOptionException, ConfigManager,
                       "test-datas/sbackup.conf.bad")
     self.config = ConfigManager("test-datas/sbackup.conf.good")
     self.assertTrue(self.config.validateConfigFileOpts)
Пример #6
0
 def setUp(self):
     self.config = ConfigManager()
Пример #7
0
class TestConfigManager(unittest.TestCase):
    def setUp(self):
        self.config = ConfigManager()

    def testinitSection(self):
        " Init the config sections "
        self.config.initSection()
        self.assertTrue(self.config.has_section("general"))
        self.assertTrue(self.config.has_section("dirconfig"))
        self.assertTrue(self.config.has_section("places"))
        self.assertTrue(self.config.has_section("exclude"))
        self.assertEqual(len(self.config.sections()), 7)

    #===========================================================================
    # def testsetDefaultForRoot(self):
    #    "Set the default config for root user"
    #    if os.geteuid() != 0:
    #        self.assertRaises(IOError, self.config.setDefaultForRoot )
    #    else:
    #        self.config.setDefaultForRoot()
    #        self.assertTrue(os.path.exists("/var/log/sbackup.log"))
    #
    # def testsetDefaultForUsers(self):
    #    "Set the default config for normal users"
    #    self.config.setDefaultForUsers()
    #===========================================================================

    def test_set_defaults(self):
        """Testing of default settings.
        """
        self.config._set_defaults()
        if os.geteuid() == 0:
            self.assertTrue(os.path.exists("/var/log/sbackup.log"))

    def testread(self):
        "Testing the config file read function "
        self.assertRaises(SBException, ConfigManager, "sbackup.conf.fake")
        self.config = ConfigManager("test-datas/sbackup.conf.good")
        self.assertEqual(self.config.conffile, "test-datas/sbackup.conf.good")
        #        for s in self.config.sections():
        #            print(str(s))
        #        self.assertEqual(len(self.config.sections()),3)
        self.assertEqual(len(self.config.options("dirconfig")), 10)
        self.assertEqual(len(self.config.options("general")), 4)
        self.assertEqual(len(self.config.options("exclude")), 2)

    def testparse_commandline(self):
        ""
        self.config.parseCmdLine()

    def testIsConfigEquals(self):
        ""
        self.assertFalse(
            self.config.isConfigEquals(
                ConfigManager("test-datas/sbackup.conf.good")))
        self.config = ConfigManager("test-datas/sbackup.conf.good")
        self.assertTrue(
            self.config.isConfigEquals(
                ConfigManager("test-datas/sbackup.conf.good")))

    def testvalidate_config_file_options(self):
        "Validate config file"
        self.assertRaises(NonValidOptionException, ConfigManager,
                          "test-datas/sbackup.conf.bad")
        self.config = ConfigManager("test-datas/sbackup.conf.good")
        self.assertTrue(self.config.validateConfigFileOpts)