From 46671d09fbd480bd0439d6cb3710f9a1e08769d4 Mon Sep 17 00:00:00 2001 From: androiddrew Date: Tue, 15 Jan 2019 15:12:19 -0500 Subject: [PATCH] Added TOML settings file and .coveragerc file. --- README.md | 5 +++- {{cookiecutter.project_slug}}/.coveragerc | 6 +++++ .../api/todo/view.py | 2 +- .../{{cookiecutter.project_slug}}/index.py | 26 +++++-------------- .../{{cookiecutter.project_slug}}/settings.py | 12 +++++++++ .../settings.toml | 10 +++++++ 6 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 {{cookiecutter.project_slug}}/.coveragerc create mode 100644 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py create mode 100644 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.toml diff --git a/README.md b/README.md index 5a8b2ed..74ba3fc 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ pip-sync dev_requirements.txt requirements.txt ``` #### Run tests ``` -$ pytest -v +$ export ENVIRONMENT=test && pytest -v ``` #### Using the management script @@ -44,5 +44,8 @@ MIT Licensed. ## Changelog +### 0.2.0 (01/15/2019) +- Added TOML settings file and .coveragerc file + ### 0.1.0 (12/09/2018) - Initial release \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/.coveragerc b/{{cookiecutter.project_slug}}/.coveragerc new file mode 100644 index 0000000..326ce2b --- /dev/null +++ b/{{cookiecutter.project_slug}}/.coveragerc @@ -0,0 +1,6 @@ +[run] +source = {{cookiecutter.project_slug}} +omit = test* + +[report] +show_missing = True \ No newline at end of file diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/api/todo/view.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/api/todo/view.py index 04b5166..949a7b3 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/api/todo/view.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/api/todo/view.py @@ -21,7 +21,7 @@ def delete_todo(todo_id: int, todo_manager: TodoManager): todo_manager.delete_todo(todo_id) return ( HTTP_202, - APIResponse(status=202, message=f"Delete request for store: {todo_id} accepted"), + APIResponse(status=202, message=f"Delete request for todo: {todo_id} accepted"), ) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/index.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/index.py index 24d018a..34df416 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/index.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/index.py @@ -3,14 +3,14 @@ from typing import Tuple from molten import App, Route, ResponseRendererMiddleware from molten.http import HTTP_404, Request from molten.openapi import Metadata, OpenAPIHandler, OpenAPIUIHandler -from molten.settings import Settings, SettingsComponent +from molten.settings import SettingsComponent from molten.contrib.sqlalchemy import SQLAlchemyMiddleware, SQLAlchemyEngineComponent, SQLAlchemySessionComponent from .api.welcome import welcome from .api.todo import TodoManagerComponent, todo_routes from .common import ExtJSONRenderer from .schema import APIResponse - +from .settings import SETTINGS get_schema = OpenAPIHandler( metadata=Metadata( @@ -22,20 +22,8 @@ get_schema = OpenAPIHandler( get_docs = OpenAPIUIHandler() -settings = Settings( - { - "database_engine_dsn": os.getenv( - "DATABASE_DSN", "postgresql://molten:local@localhost/cookiecutter" - ), - "database_engine_params": { - "echo": True, - "connect_args": {"options": "-c timezone=utc"}, - }, - } -) - components = [ - SettingsComponent(settings), + SettingsComponent(SETTINGS), SQLAlchemyEngineComponent(), SQLAlchemySessionComponent(), TodoManagerComponent(), @@ -46,10 +34,10 @@ middleware = [ResponseRendererMiddleware(), SQLAlchemyMiddleware()] renderers = [ExtJSONRenderer()] routes = [ - Route("/", welcome, "GET"), - Route("/_schema", get_schema, "GET"), - Route("/_docs", get_docs, "GET"), -] + [todo_routes] + Route("/", welcome, "GET"), + Route("/_schema", get_schema, "GET"), + Route("/_docs", get_docs, "GET"), + ] + [todo_routes] class ExtApp(App): diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py new file mode 100644 index 0000000..aa0e356 --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.py @@ -0,0 +1,12 @@ +import os + +from molten.contrib.toml_settings import TOMLSettings + +from .common import path_to + +ENVIRONMENT = os.getenv("ENVIRONMENT", "dev") +SETTINGS = TOMLSettings.from_path(path_to("settings.toml"), ENVIRONMENT) + + +def __getattr__(name): + return getattr(SETTINGS, name) diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.toml b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.toml new file mode 100644 index 0000000..e42cc8e --- /dev/null +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/settings.toml @@ -0,0 +1,10 @@ +[common] +database_engine_dsn = "postgresql://molten:local@localhost/cookiecutter" + +[dev] +database_engine_params.echo = true +database_engine_params.connect_args.options = "-c timezone=utc" + +[test] +database_engine_dsn = "postgresql://molten:local@localhost/test_cookiecutter" +database_engine_params.echo = true \ No newline at end of file