Esempio n. 1
0
    def test_005_config_manager(self):
        """ Test adding to the config context, adding single values that do not
        overwrite existing.
        """
        cfg = ConfigManager(self.default_file)

        self.assertNotIn('value10', cfg.__dict__)
        cfg.value10 = 5000
        self.assertIn('value10', cfg.__dict__)
Esempio n. 2
0
    def test_010_config_manager(self):
        """ Test writing config out, using the internally-specified config file.
        """
        with open(self.valid_file, 'r') as f:
            old_json = json.load(f)

        cfg = ConfigManager(self.valid_file)
        cfg.write()

        with open(self.valid_file, 'r') as f:
            new_json = json.load(f)

        self.assertEqual(old_json, new_json)
Esempio n. 3
0
    def test_009_config_manager(self):
        """ Test writing config to a specified output file.
        """
        with open(self.valid_file, 'r') as f:
            old_json = json.load(f)

        cfg = ConfigManager(self.valid_file)
        cfg.write(self.valid_file)

        with open(self.valid_file, 'r') as f:
            new_json = json.load(f)

        self.assertEqual(old_json, new_json)
Esempio n. 4
0
    def test_006_config_manager(self):
        """ Test adding to the config context, adding single values that do
        overwrite existing.
        """
        cfg = ConfigManager(self.default_file)

        self.assertNotIn('value10', cfg.__dict__)
        cfg.value10 = 5000
        self.assertIn('value10', cfg.__dict__)
        self.assertEqual(cfg.value10, 5000)
        cfg.value10 = 'new-value'
        self.assertIn('value10', cfg.__dict__)
        self.assertEqual(cfg.value10, 'new-value')
Esempio n. 5
0
    def test_017_config_manager(self):
        """ Test regex filename matching. In this case, none of the supplied names should match.
        """
        cfg = ConfigManager(self.default_file)

        filenames = [
            'config', 'configuration', 'CONFIG', 'CONFIGURATION', 'CoNfIg',
            'config.yml', 'config.jsn', 'cfg.json', 'test_confg.json',
            'cfg_test.json'
        ]

        results = cfg._find_config_matches(filenames)

        self.assertEqual(len(results), 0)
Esempio n. 6
0
    def test_016_config_manager(self):
        """ Test regex filename matching. In this case, all supplied names should match.
        """
        cfg = ConfigManager(self.default_file)

        filenames = [
            'config.json', 'CONFIG.json', 'config.JSON', 'CONFIG.JSON',
            'CoNfIg.JsOn', 'test_config.json', 'config_test.json',
            'configuration.json', 'service-config.json', 'service.config.json'
        ]

        results = cfg._find_config_matches(filenames)

        self.assertEqual(len(results), len(filenames))
        self.assertEqual(results, filenames)
Esempio n. 7
0
    def test_002_config_manager(self):
        """ Test initializing the config manager with a valid file.
        """
        cfg = ConfigManager(self.valid_file)

        self.assertEqual(cfg.none_value, None)
        self.assertEqual(cfg.bool_value, True)
        self.assertEqual(cfg.string_value, 'value1')
        self.assertEqual(cfg.int_value, 5000)
        self.assertEqual(cfg.float_value, 1.234)
        self.assertEqual(cfg.list_value, [1, 2, 3, 4])
        self.assertEqual(cfg.dict_value, {'val1': 1, 'val2': 2})

        self.assertEqual(cfg['none_value'], None)
        self.assertEqual(cfg['bool_value'], True)
        self.assertEqual(cfg['string_value'], 'value1')
        self.assertEqual(cfg['int_value'], 5000)
        self.assertEqual(cfg['float_value'], 1.234)
        self.assertEqual(cfg['list_value'], [1, 2, 3, 4])
        self.assertEqual(cfg['dict_value'], {'val1': 1, 'val2': 2})

        with self.assertRaises(AttributeError):
            cfg['not_a_key']

        with self.assertRaises(AttributeError):
            cfg.not_a_key

        # should be of len 8 -> 7 for the number of values in the config file,
        # plus 2 for internally tracked state.
        self.assertEqual(len(cfg.__dict__), 9)
Esempio n. 8
0
    def test_007_config_manager(self):
        """ Test adding to the config context, adding multiple values that do not
        overwrite existing.
        """
        cfg = ConfigManager(self.default_file)

        to_add = {'value10': 5000, 'value20': 'test', 'value30': False}

        for k, v in to_add.iteritems():
            self.assertNotIn(k, cfg.__dict__)

        cfg.add_config(to_add)

        for k, v in to_add.iteritems():
            self.assertIn(k, cfg.__dict__)
            self.assertEqual(cfg.__dict__[k], v)
Esempio n. 9
0
    def test_015_config_manager(self):
        """ Test initializing with a default file and override which does not exist.
        """
        with open(self.default_file, 'r') as f:
            default = json.load(f)

        cfg = ConfigManager(self.default_file, './not/a/path')

        for k, v in default.iteritems():
            self.assertIn(k, cfg.__dict__)
            self.assertEqual(v, cfg.__dict__[k])
Esempio n. 10
0
    def test_013_config_manager(self):
        """ Test initializing with a default file and invalid override.
        """
        with open(self.default_file, 'r') as f:
            default = json.load(f)

        cfg = ConfigManager(self.default_file, self.invalid_override)

        for k, v in default.iteritems():
            self.assertIn(k, cfg.__dict__)
            self.assertEqual(v, cfg.__dict__[k])
Esempio n. 11
0
    def test_014_config_manager(self):
        """ Test initializing with a default file and valid override.
        """
        with open(self.default_file, 'r') as f:
            default = json.load(f)

        with open(os.path.join(self.valid_override, 'test_config.json'),
                  'r') as f:
            override = json.load(f)

        cfg = ConfigManager(self.default_file, self.valid_override)

        default.update(override)
        for k, v in default.iteritems():
            self.assertIn(k, cfg.__dict__)
            self.assertEqual(v, cfg.__dict__[k])
Esempio n. 12
0
 def test_001_config_manager(self):
     """ Test initializing the config manager with an invalid json file.
     """
     with self.assertRaises(ValueError):
         ConfigManager(self.invalid_file)
Esempio n. 13
0
 def test_000_config_manager(self):
     """ Test initializing the config manager with a nonexistent file.
     """
     with self.assertRaises(IOError):
         ConfigManager(self.nonexistent_file)
Esempio n. 14
0
 def test_004_config_manager(self):
     """ Test initializing the config manager with invalid arguments.
     """
     with self.assertRaises(ValueError):
         ConfigManager(None)
Esempio n. 15
0
 def test_003_config_manager(self):
     """ Test initializing the config manager with no file.
     """
     with self.assertRaises(ValueError):
         ConfigManager('')
Esempio n. 16
0
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

OpenDCRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenDCRE.  If not, see <http://www.gnu.org/licenses/>.
"""
from version import __api_version__
from vapor_common.vapor_config import ConfigManager

# get pertinent config data from the opendcre config file. assumes root at /opendcre
cfg = ConfigManager('/opendcre/opendcre_config.json')
_PORT = cfg.port
_ENDPOINTPREFIX = cfg.endpoint_prefix
_SSL_ENABLE = cfg.ssl_enable

# determine the protocol to use based on config
PROTOCOL = 'https://' if _SSL_ENABLE else 'http://'

# southbound endpoint prefix for test containers
PREFIX = PROTOCOL + 'opendcre-southbound-test-container:' + str(
    _PORT) + _ENDPOINTPREFIX + __api_version__

# test user/pass for http basic auth via requests lib
TEST_USERNAME = "******"
TEST_PASSWORD = "******"