Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dternyak committed Sep 30, 2018
1 parent 58b07b1 commit 83098f0
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 24 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Molten-Boilerplate

## What's included?
- SQLAlchemy
- alembic
- camelCase API
- py.test

## Usage
Install requirements

Expand Down
1 change: 0 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from api.user.models import User
2 changes: 1 addition & 1 deletion alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ script_location = migrations
# are written from script.py.mako
# output_encoding = utf-8

# OVERWRITTEN IN migrations/env.py
# !!! Overwritten in migrations/env.py !!!
sqlalchemy.url = sqlite:///db.sqlite3


Expand Down
2 changes: 2 additions & 0 deletions api/user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import views
from . import models
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion custom/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from molten import RequestBody
from molten.errors import ParseError

from animal_case.convert import parse_keys
from .animal_case.convert import parse_keys


class JSONParser:
Expand Down
2 changes: 1 addition & 1 deletion custom/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from molten import Response
from molten.validation import dump_schema, is_schema

from animal_case.convert import parse_keys
from .animal_case.convert import parse_keys


class JSONRenderer:
Expand Down
3 changes: 0 additions & 3 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

Base = declarative_base()

from api.comment.models import *
from api.user.models import *


def init_db(engine_data: EngineData):
Base.metadata.create_all(engine_data.engine)
Expand Down
18 changes: 2 additions & 16 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
from molten import URLEncodingParser, MultiPartParser
from molten.contrib.sqlalchemy import (
SQLAlchemyEngineComponent, SQLAlchemyMiddleware,
SQLAlchemySessionComponent,
EngineData)
SQLAlchemySessionComponent)
from molten.contrib.toml_settings import TOMLSettingsComponent
from molten.openapi import HTTPSecurityScheme, Metadata, OpenAPIHandler, OpenAPIUIHandler

from api.comment.views import list_comments, create_comment, get_comment, delete_comment
from api.user.views import list_users, create_user, get_user, delete_user
from custom import JSONParser, JSONRenderer
from db import Base

get_docs = OpenAPIUIHandler()

Expand Down Expand Up @@ -62,7 +60,7 @@
]


def create_app(_components=None, _middleware=None, _routes=None, _setup_db=False):
def create_app(_components=None, _middleware=None, _routes=None):
app = App(
components=_components or components,
middleware=_middleware or middleware,
Expand All @@ -74,16 +72,4 @@ def create_app(_components=None, _middleware=None, _routes=None, _setup_db=False
],
renderers=[JSONRenderer()]
)
if _setup_db:
setup_db(app)
return app


def init_db(engine_data: EngineData):
Base.metadata.create_all(engine_data.engine)


def setup_db(app):
# Initialize the DB by injecting EngineData into initdb and calling it.
resolver = app.injector.get_resolver()
resolver.resolve(init_db)()
16 changes: 15 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import pytest
from molten import testing
from molten.contrib.sqlalchemy import (
EngineData)

from db import Base
from index import create_app


def init_db(engine_data: EngineData):
Base.metadata.create_all(engine_data.engine)


def setup_db(app):
# Initialize the DB by injecting EngineData into init_db and calling it.
resolver = app.injector.get_resolver()
resolver.resolve(init_db)()


# requires function scope so that database is removed on every tests
# TODO - find a less hacky way to clear database after each test
@pytest.fixture(scope="function")
def app():
app = create_app(_setup_db=True)
app = create_app()
setup_db(app)
yield app
import os
test_db = "test.db.sqlite3"
Expand Down

0 comments on commit 83098f0

Please sign in to comment.