From 98e270402cca1335289288473873fdd5239ff767 Mon Sep 17 00:00:00 2001 From: Alan Pryor Date: Sun, 19 May 2019 08:22:53 -0400 Subject: [PATCH] Add schema and interface tests --- app/fizz/fizzbar/interface_test.py | 0 app/widget/interface_test.py | 19 +++++++++++++++++++ app/widget/model.py | 1 - app/widget/schema_test.py | 27 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 app/fizz/fizzbar/interface_test.py create mode 100644 app/widget/interface_test.py diff --git a/app/fizz/fizzbar/interface_test.py b/app/fizz/fizzbar/interface_test.py new file mode 100644 index 0000000..e69de29 diff --git a/app/widget/interface_test.py b/app/widget/interface_test.py new file mode 100644 index 0000000..da75bc8 --- /dev/null +++ b/app/widget/interface_test.py @@ -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 diff --git a/app/widget/model.py b/app/widget/model.py index fbcd9a9..5707376 100644 --- a/app/widget/model.py +++ b/app/widget/model.py @@ -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 diff --git a/app/widget/schema_test.py b/app/widget/schema_test.py index e69de29..9f4f702 100644 --- a/app/widget/schema_test.py +++ b/app/widget/schema_test.py @@ -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'