File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 5
5
from ..utils import (
6
6
get_model_fields , is_valid_mongoengine_model
7
7
)
8
- from .models import Reporter
8
+ from .models import Reporter , Child
9
9
10
10
def test_get_model_fields_no_duplication ():
11
11
reporter_fields = get_model_fields (Reporter )
12
12
reporter_name_set = set (reporter_fields )
13
13
assert len (reporter_fields ) == len (reporter_name_set )
14
14
15
15
16
+ def test_get_base_model_fields ():
17
+ child_fields = get_model_fields (Child )
18
+ assert all (field in set (child_fields ) for field in ['bar' , 'baz' ])
19
+
16
20
def test_is_valid_mongoengine_mode ():
17
21
assert is_valid_mongoengine_model (Reporter )
18
22
Original file line number Diff line number Diff line change 2
2
import mongoengine
3
3
4
4
from collections import OrderedDict
5
- from mongoengine .base .fields import BaseField
6
5
7
6
8
7
def get_model_fields (model , excluding = None ):
9
8
if excluding is None :
10
9
excluding = []
11
10
attributes = dict ()
12
- for attr_name in vars ( model ):
11
+ for attr_name , attr in model . _fields . items ( ):
13
12
if attr_name in excluding :
14
13
continue
15
- attr = getattr (model , attr_name )
16
- if isinstance (attr , BaseField ):
17
- attributes [attr_name ] = attr
18
-
14
+ attributes [attr_name ] = attr
19
15
return OrderedDict (sorted (attributes .items ()))
20
16
21
17
You can’t perform that action at this time.
0 commit comments