Browse Source

Adding documentation and cleanup of tests

code_cleanup
Drew Short 5 years ago
parent
commit
6aac72bae6
  1. 22
      server/README.md
  2. 14
      server/server/__init__.py
  3. 3
      server/tests/conftest.py
  4. 0
      server/tests/test_settings.py

22
server/README.md

@ -18,6 +18,12 @@ pipenv shell
## Configuration
Specify a settings file
```bash
export SERVER_SETTINGS='<path to settings python file>'
```
## Running
### Docker
@ -29,12 +35,20 @@ docker run -d corvus:local-test
### Local Development Version
Run a local version
```bash
FLASK_APP=corvus:corvus flask db upgrade
python manage.py user register-admin
FLASK_APP=corvus:corvus flask run
```
Set log level
```bash
export SERVER_LOGLEVEL=DEBUG
```
## FAQ
## Development
@ -52,6 +66,14 @@ pipenv install --dev
* If everything passes follow contributing guide.
## Testing
To run the pytests directly, use the following command
```bash
PYTHONPATH=$(pwd) pipenv run py.test
```
## Contributing
See ../CONTRIBUTING.md

14
server/server/__init__.py

@ -10,6 +10,7 @@ from server.errors import BaseError, handle_base_error, \
handle_404_error
from server.utility import json_utility, session_utility
LOGLEVEL = os.environ.get('SERVER_LOGLEVEL', 'INFO').upper()
dictConfig({
'version': 1,
'formatters': {'default': {
@ -21,7 +22,7 @@ dictConfig({
'formatter': 'default'
}},
'root': {
'level': 'INFO',
'level': LOGLEVEL,
'handlers': ['wsgi']
}
})
@ -48,11 +49,18 @@ def create_app(test_config: dict = None) -> Flask:
TRAP_HTTP_EXCEPTIONS=True,
)
config_directory = os.getenv('SERVER_CONFIG_DIRECTORY', 'config')
if test_config is None:
app.logger.debug('Loading configurations')
app.config.from_object('server.default_settings')
app.config.from_pyfile('config.py', silent=True)
default_settings = 'server.default_settings'
app.logger.debug('Loading configuration from ' + default_settings)
app.config.from_object(default_settings)
config_file = config_directory + '/config.py'
if os.path.exists(config_file):
app.logger.debug('Loading config from ' + config_file)
app.config.from_pyfile(config_file, silent=True)
if os.getenv('SERVER_SETTINGS', None):
app.logger.debug('Loading config from SERVER_SETTINGS=' + os.getenv('SERVER_SETTINGS', ''))
app.config.from_envvar('SERVER_SETTINGS')
else:
app.logger.debug('Loading test configuration')

3
server/tests/conftest.py

@ -36,6 +36,9 @@ def app() -> Generator[Flask, Any, Any]:
'TESTING': True,
'SQLALCHEMY_DATABASE_URI': test_database_uri,
})
test_settings = 'tests.test_settings'
server_app.logger.debug('Loading configuration from ' + test_settings)
server_app.config.from_object(test_settings)
register_blueprints(server_app)
register_error_handlers(server_app)

0
server/test_settings.py → server/tests/test_settings.py

Loading…
Cancel
Save