def test_load_with_real_file(self): import tempfile with tempfile.NamedTemporaryFile() as f: f.write(b'{"key": "value"}') f.flush() config = FileConfig(f.name, reader=JsonReader()) config.load() self.assertEqual('value', config['key'])
def test_load_without_url_extension_and_custom_reader(self): class Config(UrlConfig): def _open_url(self, url): content_type = None stream = BytesIO() stream.write(b'''{ "key_str": "value" }''') stream.seek(0, 0) return content_type, stream config = Config('http://example.com/config', reader=JsonReader()) config.load()
def test_load_without_file_extension_and_custom_reader(self): class Config(FileConfig): def _find_file(self, filename): return filename def _open_file(self, filename): stream = BytesIO() stream.write(b'{"key": "value"}') stream.seek(0, 0) return stream config = Config('./config', reader=JsonReader()) config.load() self.assertEqual('value', config['key'])
def test_init_reader_with_reader_value(self): reader = JsonReader() config = UrlConfig('http://config.json', reader=reader) self.assertEqual(reader, config.reader)
def setUp(self): self.reader = JsonReader() self.data = u'{"database": {"host": "localhost", "port": "1234"}}'
def test_init_reader_with_reader_value(self): reader = JsonReader() config = S3Config(client=self.s3, bucket_name='bucket name', filename='config.json', reader=reader) self.assertEqual(reader, config.reader)
def test_load_without_file_extension_and_custom_reader(self): class Config(S3Config): def _open_file(self, filename): stream = BytesIO() stream.write(b'{"key": "value"}') stream.seek(0, 0) return stream config = Config(client=self.s3, bucket_name='bucket name', filename='./config', reader=JsonReader()) config.load() self.assertEqual('value', config.get('key'))