Add schema and interface tests

This commit is contained in:
Alan Pryor 2019-05-19 08:22:53 -04:00
parent 1ef26d3b60
commit 98e270402c
4 changed files with 46 additions and 1 deletions

View File

View File

@ -0,0 +1,19 @@
from pytest import fixture
from .model import Widget
from .interface import WidgetInterface
@fixture
def interface() -> WidgetInterface:
return WidgetInterface(
widget_id=1, name='Test widget', purpose='Test purpose'
)
def test_WidgetInterface_create(interface: WidgetInterface):
assert interface
def test_WidgetInterface_works(interface: WidgetInterface):
widget = Widget(**interface)
assert widget

View File

@ -1,7 +1,6 @@
from sqlalchemy import Integer, Column, String
from app import db # noqa
from .interface import WidgetInterface
from typing import Any
class Widget(db.Model): # type: ignore

View File

@ -0,0 +1,27 @@
from pytest import fixture
from .model import Widget
from .schema import WidgetSchema
from .interface import WidgetInterface
@fixture
def schema() -> WidgetSchema:
return WidgetSchema()
def test_WidgetSchema_create(schema: WidgetSchema):
assert schema
def test_WidgetSchema_works(schema: WidgetSchema):
params: WidgetInterface = schema.load({
'widgetId': '123',
'name': 'Test widget',
'purpose': 'Test purpose'
}).data
widget = Widget(**params)
assert widget.widget_id == 123
assert widget.name == 'Test widget'
assert widget.purpose == 'Test purpose'