added application factory and render tests
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
|
@ -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…
Reference in New Issue