11import unittest
22
33from sqlalchemyseed import errors
4- from sqlalchemyseed .validator import SchemaValidator
4+ from sqlalchemyseed .validator import SchemaValidator , Key
55from tests import instances as ins
66
77
@@ -10,6 +10,25 @@ class TestSchemaValidator(unittest.TestCase):
1010 def test_parent (self ):
1111 self .assertIsNone (SchemaValidator .validate (ins .PARENT ))
1212
13+ def test_parent_invalid (self ):
14+ self .assertRaises (errors .InvalidDataTypeError ,
15+ lambda : SchemaValidator .validate (ins .PARENT_INVALID ))
16+
17+ def test_parent_empty (self ):
18+ self .assertIsNone (SchemaValidator .validate (ins .PARENT_EMPTY ))
19+
20+ def test_parent_empty_data_list_invalid (self ):
21+ self .assertRaises (errors .EmptyDataError ,
22+ lambda : SchemaValidator .validate (ins .PARENT_EMPTY_DATA_LIST_INVALID ))
23+
24+ def test_parent_missing_model_invalid (self ):
25+ self .assertRaises (errors .MissingRequiredKeyError ,
26+ lambda : SchemaValidator .validate (ins .PARENT_MISSING_MODEL_INVALID ))
27+
28+ def test_parent_invalid_model_invalid (self ):
29+ self .assertRaises (errors .InvalidDataTypeError ,
30+ lambda : SchemaValidator .validate (ins .PARENT_INVALID_MODEL_INVALID ))
31+
1332 def test_parent_with_extra_length_invalid (self ):
1433 self .assertRaises (errors .MaxLengthExceededError ,
1534 lambda : SchemaValidator .validate (ins .PARENT_WITH_EXTRA_LENGTH_INVALID ))
@@ -24,6 +43,14 @@ def test_parent_without_data_invalid(self):
2443 self .assertRaises (errors .MissingRequiredKeyError ,
2544 lambda : SchemaValidator .validate (ins .PARENT_WITHOUT_DATA_INVALID ))
2645
46+ def test_parent_with_data_and_invalid_data_invalid (self ):
47+ self .assertRaises (errors .InvalidDataTypeError ,
48+ lambda : SchemaValidator .validate (ins .PARENT_WITH_DATA_AND_INVALID_DATA_INVALID ))
49+
50+ def test_parent_with_invalid_data_invalid (self ):
51+ self .assertRaises (errors .InvalidDataTypeError ,
52+ lambda : SchemaValidator .validate (ins .PARENT_WITH_INVALID_DATA_INVALID ))
53+
2754 def test_parent_to_child (self ):
2855 self .assertIsNone (SchemaValidator .validate (ins .PARENT_TO_CHILD ))
2956
@@ -38,3 +65,17 @@ def test_parent_to_children_with_multi_data(self):
3865
3966 def test_parent_to_children_with_multi_data_without_model (self ):
4067 self .assertIsNone (SchemaValidator .validate (ins .PARENT_TO_CHILDREN_WITH_MULTI_DATA_WITHOUT_MODEL ))
68+
69+
70+ class TestKey (unittest .TestCase ):
71+ def test_key_equal_key (self ):
72+ self .assertEqual (Key .model (), Key (label = 'model' , type_ = str ))
73+
74+ def test_key_not_equal (self ):
75+ self .assertNotEqual (Key .model (), Key .data ())
76+
77+ def test_key_equal_string (self ):
78+ self .assertEqual (Key .model (), 'model' )
79+
80+ def test_key_not_equal_other_instance (self ):
81+ self .assertNotEqual (Key .model (), object ())
0 commit comments