Skip to content

Commit 7295cef

Browse files
author
beta
committed
adding more types
1 parent 66ebb2a commit 7295cef

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

.vscode/tasks.json

+30-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"127.0.0.1",
3939
"--directory",
4040
"${workspaceFolder}/docs/build/html"
41-
]
41+
],
42+
"problemMatcher": []
4243
},
4344
{
4445
"label": "Lint ALL",
@@ -63,6 +64,34 @@
6364
"flask_restplus_sqlalchemy"
6465
],
6566
"problemMatcher": []
67+
},
68+
{
69+
"label": "Coverage html",
70+
"type": "shell",
71+
"command": "python3",
72+
"args": [
73+
"-m",
74+
"pytest",
75+
"--cov-report",
76+
"html",
77+
"--cov=flask_restplus_sqlalchemy/"
78+
],
79+
"problemMatcher": []
80+
},
81+
{
82+
"label": "Coverage Service",
83+
"type": "shell",
84+
"command": "python3",
85+
"args": [
86+
"-m",
87+
"http.server",
88+
"8001",
89+
"--bind",
90+
"127.0.0.1",
91+
"--directory",
92+
"${workspaceFolder}/htmlcov"
93+
],
94+
"problemMatcher": []
6695
}
6796
]
6897
}

test/test_factory.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"""
33
import unittest
44

5-
from sqlalchemy import BigInteger, Column, Integer, String, DateTime, Date
5+
from sqlalchemy import (BigInteger, Column, Integer, String, DateTime, Date,
6+
Numeric, Boolean, Float)
67
from flask_sqlalchemy import SQLAlchemy
78
from flask import Flask
89
from flask_restplus import Api
910
from flask_restplus_sqlalchemy import ApiModelFactory
1011

12+
1113
class TestFactory(unittest.TestCase):
1214
"""Test Factory Logic
1315
"""
@@ -28,8 +30,7 @@ def setUpClass(cls):
2830
description='Test')
2931
db: SQLAlchemy = SQLAlchemy()
3032

31-
32-
class Person(db.Model): # pylint: disable=unused-variable
33+
class Person(db.Model): # pylint: disable=unused-variable
3334
""" Person Entity
3435
"""
3536
__tablename__ = "person"
@@ -40,20 +41,19 @@ class Person(db.Model): # pylint: disable=unused-variable
4041
nullable=False
4142
)
4243
created_on: Column = Column(DateTime, nullable=False)
44+
active: Column = Column(Boolean, nullable=False)
4345
birth: Column = Column(Date, nullable=False)
4446
first_name: Column = Column(String(100), nullable=False)
4547
middle_name: Column = Column(String(100), nullable=True)
4648
last_name: Column = Column(String(100), nullable=False)
4749

48-
4950
class Fake(db.Model):
5051
""" Abstract entity that should not be placed into API Model factory
5152
"""
5253
__tablename__ = "fake"
5354
__abstract__ = True
5455

55-
56-
class NotFake(Fake): # pylint: disable=unused-variable
56+
class NotFake(Fake): # pylint: disable=unused-variable
5757
""" Inherits abstract class so should appear
5858
"""
5959
__tablename__ = "not_fake"
@@ -62,8 +62,8 @@ class NotFake(Fake): # pylint: disable=unused-variable
6262
primary_key=True,
6363
nullable=False
6464
)
65-
do_care: Column = Column(String(100), nullable=False)
66-
65+
do_care: Column = Column(Numeric, nullable=False)
66+
do_alt: Column = Column(Float, nullable=False)
6767

6868
cls.db = db
6969
# Note: How init must be called before the factory in called
@@ -83,7 +83,8 @@ def test_not_fake(self):
8383
def test_missing(self):
8484
""" Verify object throws expection as it is not database class
8585
"""
86-
self.assertRaises(Exception, self.api_model_factory.get_entity, 'object')
86+
self.assertRaises(
87+
Exception, self.api_model_factory.get_entity, 'object')
8788

8889
def test_person(self):
8990
""" Check if person is in the Factory model

0 commit comments

Comments
 (0)