Ejemplo n.º 1
0
    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'])
Ejemplo n.º 2
0
 def test_init_reader_with_reader_value(self):
     reader = JsonReader()
     config = FileConfig('config.json', reader=reader)
     self.assertEqual(reader, config.reader)
Ejemplo n.º 3
0
 def test_load_with_file_not_found(self):
     config = FileConfig('not_found')
     with self.assertRaises(FileNotFoundError):
         config.load()
Ejemplo n.º 4
0
 def test_get_reader_with_default_value(self):
     config = FileConfig('config.json')
     self.assertIsNone(config.reader)
Ejemplo n.º 5
0
 def test_init_reader_with_str_value(self):
     with self.assertRaises(TypeError):
         FileConfig('config.json', reader='non reader')
Ejemplo n.º 6
0
 def test_init_filename_with_str_value(self):
     config = FileConfig('config.json')
     self.assertEqual('config.json', config.filename)
Ejemplo n.º 7
0
 def test_init_filename_with_int_value(self):
     with self.assertRaises(TypeError):
         FileConfig(filename=123)
Ejemplo n.º 8
0
import requests

from central.config.file import FileConfig
from central.property import PropertyManager
from flask import Flask

config = FileConfig('config.json').reload_every(1000)
config.load()

properties = PropertyManager(config)
timeout = properties.get_property('timeout').as_int(10)

app = Flask(__name__)
app.config.from_mapping(config)


@app.route('/time')
def get_current_time():
    response = requests.get('http://date.jsontest.com', timeout=timeout.get())
    data = response.json()
    return data.get('time')


if __name__ == '__main__':
    app.run()
Ejemplo n.º 9
0
from central.config.file import FileConfig

config = FileConfig('config.json')
config.load()

print(config.get('timeout'))
print(config.get('database'))

# you can set APP_ENV by using environment variables
# export APP_ENV=prod
# python main.py
Ejemplo n.º 10
0
from central.config import MergeConfig
from central.config.file import FileConfig


config = MergeConfig(
    FileConfig('config.json'),
    FileConfig('config.local.json')
)

config.load()

print(config.get('timeout'))
print(config.get('database'))

# you can set APP_ENV by using environment variables

# export APP_ENV=prod
# python main.py