Added OpenAPI schema endpoint, swagger docs endpoint, and additional todo testing

master
androiddrew 6 years ago
parent 4a505318d5
commit 85237a5ccc

@ -10,7 +10,7 @@ $ cookiecutter https://github.com/androiddrew/cookiecutter-molten
```
You will be asked for some basic information regarding your project (name, project name, etc.). This info will be used in your new project
#### Create virtual env
#### Create a virtual environment
```
$ cd <app_dir>
$ python -m venv env
@ -23,7 +23,17 @@ $ pip-sync dev_requirements.txt requirements.txt
$ pytest -v
```
#### Run dev server
#### Using the management script
In a similar style to Django this cookiecutter provides a `manage.py` module to assist you in your development. This script is simply assembled using the [click](https://github.com/pallets/click) library.
Excuting the script with no parameters will print a list of available operations.
```
$ python manage.py
```
If you have installed the dev dependencies you will have access to the werkzueg dev server. Do not use this server in production.
```
$ python manage.py runserver
```

@ -20,14 +20,22 @@ def test_insert_todo(client):
assert content['todo'] == payload['todo']
def test_get_individual_todo_by_href(client):
payload = {"todo": "my individual todo"}
response = client.post("/todos", data=payload)
content = response.json()
get_response = client.get(f"{content.get('href')}")
get_content = get_response.json()
assert get_response.status_code == 200
assert content == get_content
def test_update_todo(client):
payload = {"todo": "sample app"}
response = client.post("/todos", json=payload)
todo = response.json()
print(todo)
update_response = client.patch("{}".format(todo.get("href")), json={"complete": True, "todo": "sample app"})
updated_todo = update_response.json()
print(updated_todo)
assert updated_todo["complete"] == True
@ -37,3 +45,11 @@ def test_todo_not_found(client):
assert response.status_code == 404
assert content["status"] == 404
assert content["message"]
def test_delete_todo(client):
payload = {"todo": "sample app"}
response = client.post("/todos", json=payload)
todo = response.json()
delete_response = client.delete(f"/todos/{todo.get('id')}")
assert delete_response.status_code == 202

@ -2,6 +2,7 @@ import os
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.contrib.sqlalchemy import SQLAlchemyMiddleware, SQLAlchemyEngineComponent, SQLAlchemySessionComponent
@ -10,6 +11,17 @@ from .api.todo import TodoManagerComponent, todo_routes
from .common import ExtJSONRenderer
from .schema import APIResponse
get_schema = OpenAPIHandler(
metadata=Metadata(
title="{{cookiecutter.project_slug}}",
description="{{cookiecutter.description}}",
version="0.0.0"
)
)
get_docs = OpenAPIUIHandler()
settings = Settings(
{
"database_engine_dsn": os.getenv(
@ -33,7 +45,11 @@ middleware = [ResponseRendererMiddleware(), SQLAlchemyMiddleware()]
renderers = [ExtJSONRenderer()]
routes = [Route("/", welcome, "GET")] + [todo_routes]
routes = [
Route("/", welcome, "GET"),
Route("/_schema", get_schema, "GET"),
Route("/_docs", get_docs, "GET"),
] + [todo_routes]
class ExtApp(App):

Loading…
Cancel
Save