2
2
"""
3
3
import unittest
4
4
5
- from sqlalchemy import BigInteger , Column , Integer , String , DateTime , Date
5
+ from sqlalchemy import (BigInteger , Column , Integer , String , DateTime , Date ,
6
+ Numeric , Boolean , Float )
6
7
from flask_sqlalchemy import SQLAlchemy
7
8
from flask import Flask
8
9
from flask_restplus import Api
9
10
from flask_restplus_sqlalchemy import ApiModelFactory
10
11
12
+
11
13
class TestFactory (unittest .TestCase ):
12
14
"""Test Factory Logic
13
15
"""
@@ -28,8 +30,7 @@ def setUpClass(cls):
28
30
description = 'Test' )
29
31
db : SQLAlchemy = SQLAlchemy ()
30
32
31
-
32
- class Person (db .Model ): # pylint: disable=unused-variable
33
+ class Person (db .Model ): # pylint: disable=unused-variable
33
34
""" Person Entity
34
35
"""
35
36
__tablename__ = "person"
@@ -40,20 +41,19 @@ class Person(db.Model): # pylint: disable=unused-variable
40
41
nullable = False
41
42
)
42
43
created_on : Column = Column (DateTime , nullable = False )
44
+ active : Column = Column (Boolean , nullable = False )
43
45
birth : Column = Column (Date , nullable = False )
44
46
first_name : Column = Column (String (100 ), nullable = False )
45
47
middle_name : Column = Column (String (100 ), nullable = True )
46
48
last_name : Column = Column (String (100 ), nullable = False )
47
49
48
-
49
50
class Fake (db .Model ):
50
51
""" Abstract entity that should not be placed into API Model factory
51
52
"""
52
53
__tablename__ = "fake"
53
54
__abstract__ = True
54
55
55
-
56
- class NotFake (Fake ): # pylint: disable=unused-variable
56
+ class NotFake (Fake ): # pylint: disable=unused-variable
57
57
""" Inherits abstract class so should appear
58
58
"""
59
59
__tablename__ = "not_fake"
@@ -62,8 +62,8 @@ class NotFake(Fake): # pylint: disable=unused-variable
62
62
primary_key = True ,
63
63
nullable = False
64
64
)
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 )
67
67
68
68
cls .db = db
69
69
# Note: How init must be called before the factory in called
@@ -83,7 +83,8 @@ def test_not_fake(self):
83
83
def test_missing (self ):
84
84
""" Verify object throws expection as it is not database class
85
85
"""
86
- self .assertRaises (Exception , self .api_model_factory .get_entity , 'object' )
86
+ self .assertRaises (
87
+ Exception , self .api_model_factory .get_entity , 'object' )
87
88
88
89
def test_person (self ):
89
90
""" Check if person is in the Factory model
0 commit comments