create a documentation for config path
This commit is contained in:
parent
e978121d58
commit
0b64fe6746
|
@ -53,6 +53,15 @@ import myapp.default_settings
|
|||
app = Sanic('myapp')
|
||||
app.config.from_object(myapp.default_settings)
|
||||
```
|
||||
or also by path to config:
|
||||
|
||||
```
|
||||
import myapp.default_settings
|
||||
|
||||
app = Sanic('myapp')
|
||||
app.config.from_object('config.path.config.Class')
|
||||
```
|
||||
|
||||
|
||||
You could use a class or any other object as well.
|
||||
|
||||
|
|
|
@ -16,17 +16,25 @@ def temp_path():
|
|||
yield Path(td, 'file')
|
||||
|
||||
|
||||
def test_load_from_object(app):
|
||||
class Config:
|
||||
class Config:
|
||||
not_for_config = 'should not be used'
|
||||
CONFIG_VALUE = 'should be used'
|
||||
|
||||
|
||||
def test_load_from_object(app):
|
||||
app.config.from_object(Config)
|
||||
assert 'CONFIG_VALUE' in app.config
|
||||
assert app.config.CONFIG_VALUE == 'should be used'
|
||||
assert 'not_for_config' not in app.config
|
||||
|
||||
|
||||
def test_load_from_object_string(app):
|
||||
app.config.from_object('test_config.Config')
|
||||
assert 'CONFIG_VALUE' in app.config
|
||||
assert app.config.CONFIG_VALUE == 'should be used'
|
||||
assert 'not_for_config' not in app.config
|
||||
|
||||
|
||||
def test_auto_load_env():
|
||||
environ["SANIC_TEST_ANSWER"] = "42"
|
||||
app = Sanic()
|
||||
|
|
Loading…
Reference in New Issue
Block a user