def test_write_extra(self):
     """Writing the throttling back to the file, with extra sections."""
     conf_file = os.path.join(
         self.test_root, 'test_write_extra_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[__main__]\n')
         fp.write('log_level = INFO\n')
         fp.write('disable_ssl_verify = True\n')
         fp.write('\n')
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = False\n')
         fp.write('read_limit = 2000\n')
         fp.write('write_limit = 200\n')
     self.assertTrue(path_exists(conf_file))
     conf = config._Config(conf_file)
     conf.set_throttling(True)
     conf.set_throttling_read_limit(3000)
     conf.set_throttling_write_limit(300)
     conf.save()
     # load the config in a barebone ConfigParser and check
     conf_1 = ConfigParser()
     conf_1.read(conf_file)
     self.assertThrottlingSection(conf_1, conf, True, 3000, 300)
     self.assertEqual(conf_1.get('__main__', 'log_level'),
                      conf.get('__main__', 'log_level'))
     self.assertEqual(conf_1.getboolean('__main__', 'disable_ssl_verify'),
                      conf.getboolean('__main__', 'disable_ssl_verify'))
 def test_load_empty(self):
     """Test loading the a non-existent config file."""
     conf_file = os.path.join(self.test_root, 'test_missing_config.conf')
     # create the config object with an empty config file
     conf = config._Config(conf_file)
     self.assertEqual(False, conf.get_throttling())
     self.assertEqual(2097152, conf.get_throttling_read_limit())
     self.assertEqual(2097152, conf.get_throttling_write_limit())
 def test_get_memory_pool_limit(self):
     """Get the memory pool limit."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     with open_file(conf_file, 'w') as fh:
         fh.write('[__main__]\n')
         fh.write('memory_pool_limit = 12345\n')
     conf = config._Config(conf_file)
     self.assertEqual(conf.get_memory_pool_limit(), 12345)
 def test_get_max_payload_size(self):
     """Get the maximum payload size."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     with open_file(conf_file, 'w') as fh:
         fh.write('[__main__]\n')
         fh.write('max_payload_size = 12345\n')
     conf = config._Config(conf_file)
     self.assertEqual(conf.get_max_payload_size(), 12345)
 def test_get_simult_transfers(self):
     """Get simult transfers."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     with open_file(conf_file, 'w') as fh:
         fh.write('[__main__]\n')
         fh.write('simult_transfers = 12345\n')
     conf = config._Config(conf_file)
     self.assertEqual(conf.get_simult_transfers(), 12345)
 def test_load_partial_config(self):
     """Test loading a partial config file and fallback to defaults."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = True\n')
         fp.write('read_limit = 1\n')
     conf = config._Config(conf_file)
     self.assertEqual(True, conf.get_throttling())
     self.assertEqual(1, conf.get_throttling_read_limit())
     self.assertEqual(2097152, conf.get_throttling_write_limit())
 def test_load_basic(self):
     """Test loading the config file with only the throttling values."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = True\n')
         fp.write('read_limit = 1000\n')
         fp.write('write_limit = 200\n')
     conf = config._Config(conf_file)
     self.assertEqual(True, conf.get_throttling())
     self.assertEqual(1000, conf.get_throttling_read_limit())
     self.assertEqual(200, conf.get_throttling_write_limit())
 def test_override(self):
     """Test loading the config file with only the throttling values."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = True\n')
         fp.write('read_limit = 1000\n')
         fp.write('write_limit = 200\n')
     conf = config._Config(conf_file)
     conf_orig = config._Config(conf_file)
     overridden_opts = [('bandwidth_throttling', 'on', False)]
     conf.override_options(overridden_opts)
     self.assertEqual(False, conf.get_throttling())
     self.assertFalse(conf.get_throttling() == conf_orig.get_throttling())
     self.assertEqual(1000, conf.get_throttling_read_limit())
     self.assertEqual(200, conf.get_throttling_write_limit())
     conf.save()
     # load the config in a barebone ConfigParser and check
     conf_1 = ConfigParser()
     conf_1.read(conf_file)
     self.assertThrottlingSection(conf_1, conf_orig, True, 1000, 200)
 def test_load_negative_limits(self):
     """Test loading the config file with negative read/write limits."""
     conf_file = os.path.join(self.test_root, 'test_load_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = True\n')
         fp.write('read_limit = -1\n')
         fp.write('write_limit = -1\n')
     conf = config._Config(conf_file)
     self.assertEqual(True, conf.get_throttling())
     self.assertEqual(None, conf.get_throttling_read_limit())
     self.assertEqual(None, conf.get_throttling_write_limit())
 def test_write_new(self):
     """Test writing the throttling section to a new config file."""
     conf_file = os.path.join(self.test_root, 'test_write_new_config.conf')
     self.assertFalse(path_exists(conf_file))
     conf = config._Config(conf_file)
     conf.set_throttling(True)
     conf.set_throttling_read_limit(1000)
     conf.set_throttling_write_limit(100)
     conf.save()
     # load the config in a barebone ConfigParser and check
     conf_1 = ConfigParser()
     conf_1.read(conf_file)
     self.assertThrottlingSection(conf_1, conf, True, 1000, 100)
 def test_load_extra_data(self):
     """Test loading the a config file with other sections too."""
     conf_file = os.path.join(self.test_root, 'test_load_extra_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[__main__]\n')
         fp.write('log_level = INFO\n')
         fp.write('disable_ssl_verify = True\n')
         fp.write('\n')
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = True\n')
         fp.write('read_limit = 1000\n')
         fp.write('write_limit = 200\n')
     conf = config._Config(conf_file)
     self.assertEqual(True, conf.get_throttling())
     self.assertEqual(1000, conf.get_throttling_read_limit())
     self.assertEqual(200, conf.get_throttling_write_limit())
 def test_write_existing_partial(self):
     """Writing a partially updated throttling section to existing file."""
     conf_file = os.path.join(self.test_root,
                              'test_write_existing_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = True\n')
         fp.write('read_limit = 1000\n')
         fp.write('write_limit = 100\n')
     self.assertTrue(path_exists(conf_file))
     conf = config._Config(conf_file)
     conf.set_throttling(False)
     conf.save()
     # load the config in a barebone ConfigParser and check
     conf_1 = ConfigParser()
     conf_1.read(conf_file)
     self.assertThrottlingSection(conf_1, conf, False, 1000, 100)
 def test_write_existing(self):
     """Test writing the throttling section to a existing config file."""
     conf_file = os.path.join(self.test_root,
                              'test_write_existing_config.conf')
     # write some throttling values to the config file
     with open_file(conf_file, 'w') as fp:
         fp.write('[bandwidth_throttling]\n')
         fp.write('on = False\n')
         fp.write('read_limit = 1000\n')
         fp.write('write_limit = 100\n')
     self.assertTrue(path_exists(conf_file))
     conf = config._Config(conf_file)
     conf.set_throttling(True)
     conf.set_throttling_read_limit(2000)
     conf.set_throttling_write_limit(200)
     conf.save()
     # load the config in a barebone ConfigParser and check
     conf_1 = ConfigParser()
     conf_1.read(conf_file)
     self.assertThrottlingSection(conf_1, conf, True, 2000, 200)
    def test_load_udf_autosubscribe(self):
        """Test load/set/override of udf_autosubscribe config value."""
        conf_file = os.path.join(self.test_root,
                                 'test_udf_autosubscribe_config.conf')
        # write some throttling values to the config file
        with open_file(conf_file, 'w') as fp:
            fp.write('[__main__]\n')
            fp.write('log_level = INFO\n')
            fp.write('disable_ssl_verify = True\n')
            fp.write('udf_autosubscribe = True\n')
            fp.write('\n')
            fp.write('[bandwidth_throttling]\n')
            fp.write('on = True\n')
            fp.write('read_limit = 1000\n')
            fp.write('write_limit = 200\n')

        # keep a original around
        conf_orig = config._Config(conf_file)

        # load the config
        conf = config._Config(conf_file)
        self.assertTrue(conf.get_udf_autosubscribe())
        # change it to False
        conf.set_udf_autosubscribe(False)
        self.assertFalse(conf.get_udf_autosubscribe())
        # save, load and check
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertFalse(conf_1.get_udf_autosubscribe())
        # change it to True
        conf.set_udf_autosubscribe(True)
        self.assertTrue(conf.get_udf_autosubscribe())
        # save, load and check
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertTrue(conf_1.get_udf_autosubscribe())

        # load the config, check the override of the value
        conf = config._Config(conf_file)
        self.assertTrue(conf.get_udf_autosubscribe())
        overridden_opts = [('__main__', 'udf_autosubscribe', False)]
        conf.override_options(overridden_opts)
        self.assertFalse(conf.get_udf_autosubscribe())
        self.assertNotEqual(conf.get_udf_autosubscribe(),
                            conf_orig.get_udf_autosubscribe())
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertEqual(True, conf_1.get_udf_autosubscribe())
    def test_load_autoconnect(self):
        """Test load/set/override of autoconnect config value."""
        conf_file = os.path.join(self.test_root,
                                 'test_autoconnect_config.conf')
        # ensure that autoconnect is True
        with open_file(conf_file, 'w') as fp:
            fp.write('[__main__]\n')
            fp.write('autoconnect = True\n')

        # keep a original around
        conf_orig = config._Config(conf_file)

        # assert default is correct
        self.assertTrue(conf_orig.get_autoconnect(),
                        'autoconnect is True by default.')

        # load the config
        conf = config._Config(conf_file)
        self.assertTrue(conf.get_autoconnect())

        # change it to False
        conf.set_autoconnect(False)
        self.assertFalse(conf.get_autoconnect())

        # save, load and check
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertFalse(conf_1.get_autoconnect())
        # change it to True
        conf.set_autoconnect(True)
        self.assertTrue(conf.get_autoconnect())
        # save, load and check
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertTrue(conf_1.get_autoconnect())

        # load the config, check the override of the value
        conf = config._Config(conf_file)
        self.assertTrue(conf.get_autoconnect())
        overridden_opts = [('__main__', 'autoconnect', False)]
        conf.override_options(overridden_opts)
        self.assertFalse(conf.get_autoconnect())
        self.assertNotEqual(conf.get_autoconnect(),
                            conf_orig.get_autoconnect())
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertEqual(True, conf_1.get_autoconnect())
    def test_load_share_autosubscribe(self):
        """Test load/set/override of share_autosubscribe config value."""
        conf_file = os.path.join(self.test_root,
                                 'test_share_autosubscribe_config.conf')
        # write some throttling values to the config file
        with open_file(conf_file, 'w') as fp:
            fp.write('[__main__]\n')
            fp.write('share_autosubscribe = True\n')

        # keep a original around
        conf_orig = config._Config(conf_file)

        # load the config
        conf = config._Config(conf_file)
        self.assertTrue(conf.get_share_autosubscribe())
        # change it to False
        conf.set_share_autosubscribe(False)
        self.assertFalse(conf.get_share_autosubscribe())
        # save, load and check
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertFalse(conf_1.get_share_autosubscribe())
        # change it to True
        conf.set_share_autosubscribe(True)
        self.assertTrue(conf.get_share_autosubscribe())
        # save, load and check
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertTrue(conf_1.get_share_autosubscribe())

        # load the config, check the override of the value
        conf = config._Config(conf_file)
        self.assertTrue(conf.get_share_autosubscribe())
        overridden_opts = [('__main__', 'share_autosubscribe', False)]
        conf.override_options(overridden_opts)
        self.assertFalse(conf.get_share_autosubscribe())
        self.assertNotEqual(conf.get_share_autosubscribe(),
                            conf_orig.get_share_autosubscribe())
        conf.save()
        conf_1 = config._Config(conf_file)
        self.assertEqual(True, conf_1.get_share_autosubscribe())