added application factory and render tests

email
androiddrew 7 years ago
parent 3a6ae5df43
commit 83d560685a

@ -0,0 +1,3 @@
from cookie_api.renders import JSONRenderer
from cookie_api.models.schema import Base
from cookie_api.app import application_factory

@ -6,11 +6,9 @@ from apistar.handlers import docs_urls, static_urls
from apistar.interfaces import Router, Injector, Auth
from apistar_jwt.authentication import JWTAuthentication
from apistar_jwt.exceptions import AuthenticationFailed
from cookie_api.renders import JSONRenderer
from cookie_api.commands import commands
from cookie_api.models.schema import Base, Cookie
from cookie_api.models.schema import Cookie
from cookie_api.auth import auth_routes, auth_components
@ -69,24 +67,16 @@ routes = [
Include('/static', static_urls)
]
settings = {
'DATABASE': {
'URL': 'postgresql://apistar:local@localhost/apistar',
'METADATA': Base.metadata
},
'RENDERERS': [JSONRenderer()],
'JWT': {
'SECRET': 'thisisasecret'
}
}
routes = routes + auth_routes
commands = sqlalchemy_backend.commands + commands
app = App(routes=routes + auth_routes,
settings=settings,
commands=commands,
components=sqlalchemy_backend.components + auth_components
)
components = sqlalchemy_backend.components + auth_components
if __name__ == "__main__":
app.main()
def application_factory(**settings):
"""Returns an instance of Cookie API"""
return App(settings=settings,
commands=commands,
components=components,
routes=routes)

@ -7,15 +7,16 @@ from apistar_jwt.token import JWT
from .models.schema import User
# /auth/register
# /auth/login
# /auth/logout
# /auth/user
# /auth/logout
auth_components = [
Component(JWT, init=get_jwt)
]
# /auth/login
def login(settings: Settings, json_data: http.RequestData, session: Session):
user_id = json_data.get('email')
password = json_data.get('password')

@ -33,7 +33,7 @@ def test_non_registered_user_login():
# Test Login
def test_registered_user_login(self):
def test_registered_user_login():
""" Test for login of registered-user login """
pass

@ -0,0 +1,23 @@
import datetime as dt
from decimal import Decimal
import json
from cookie_api.renders import extended_encoder, JSONRenderer
def test_extended_encoder_date_parsing():
test_date = dt.datetime(2017, 5, 10)
assert test_date.isoformat() == extended_encoder(test_date)
def test_extended_encoder_decimal_casting():
test_decimal = Decimal('1.0')
assert 1.0 == extended_encoder(test_decimal)
def test_render_with_extended_encoder():
test_date = dt.datetime(2017, 5, 10)
test_decimal = Decimal('0.1')
expected = dict(my_date="2017-05-10T00:00:00", my_float=0.1)
test_response = dict(my_date=test_date, my_float=test_decimal)
assert json.dumps(expected).encode('utf-8') == JSONRenderer().render(test_response)

@ -1,3 +1,17 @@
from cookie_api import JSONRenderer, Base, application_factory
settings = {
'DATABASE': {
'URL': 'postgresql://apistar:local@localhost/apistar',
'METADATA': Base.metadata
},
'RENDERERS': [JSONRenderer()],
'JWT': {
'SECRET': 'thisisasecret'
}
}
if __name__ == "__main__":
from cookie_api.app import app
app = application_factory(**settings)
app.main()

Loading…
Cancel
Save