Пример #1
0
    def test_file_contents(self):
        test_path = '/path/to/some/foo.bar.json'
        test_value = 'foooooooo'
        conf = Configuration()

        self.assertEqual(conf._get_file_contents(None), None)
        self.assertEqual(conf._get_file_contents(''), None)
Пример #2
0
    def test_load_source(self):
        conf = Configuration()

        test_file_type = 'json'
        test_contents = 'test contents'
        test_parsed = {'foo': 'bar'}

        conf._get_file_type = mock.Mock(return_value=test_file_type)
        conf._get_file_contents = mock.Mock(return_value=test_contents)
        conf._parse_contents = mock.Mock(return_value=(test_parsed, None))

        conf.load_source(self.test_origin)

        self.assertEqual(len(conf.sources), 1)
        built_source = conf.sources[0]
        self.assertEqual(built_source['origin'], self.test_origin)
        self.assertEqual(built_source['location'], self.test_origin)
        self.assertEqual(built_source['type'], test_file_type)
        self.assertEqual(built_source['contents'], test_contents)
        self.assertEqual(built_source['data'], test_parsed)
Пример #3
0
 def test_invalid_config_file(self):
     conf = Configuration(silent_on_missing=False, silent_on_invalid=False)
     conf._get_file_contents = mock.Mock(return_value='{invalid,,,:json')
     with self.assertRaises(InvalidConfigError):
         conf.load_source(self.test_origin)
Пример #4
0
 def test_config_file_exists(self):
     conf = Configuration(silent_on_missing=True, silent_on_invalid=True)
     conf._get_file_contents = mock.Mock(return_value=None)
     conf.load_source(self.test_origin)
     self.assertEqual(len(conf.sources), 1)
Пример #5
0
 def test_missing_config_file(self):
     conf = Configuration(silent_on_missing=False, silent_on_invalid=False)
     conf._get_file_contents = mock.Mock(return_value=None)
     with self.assertRaises(MissingConfigFileError):
         conf.load_source(self.test_origin)