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 55from ..utils import (
66 get_model_fields , is_valid_mongoengine_model
77)
8- from .models import Reporter
8+ from .models import Reporter , Child
99
1010def test_get_model_fields_no_duplication ():
1111 reporter_fields = get_model_fields (Reporter )
1212 reporter_name_set = set (reporter_fields )
1313 assert len (reporter_fields ) == len (reporter_name_set )
1414
1515
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+
1620def test_is_valid_mongoengine_mode ():
1721 assert is_valid_mongoengine_model (Reporter )
1822
Original file line number Diff line number Diff line change 22import mongoengine
33
44from collections import OrderedDict
5- from mongoengine .base .fields import BaseField
65
76
87def get_model_fields (model , excluding = None ):
98 if excluding is None :
109 excluding = []
1110 attributes = dict ()
12- for attr_name in vars ( model ):
11+ for attr_name , attr in model . _fields . items ( ):
1312 if attr_name in excluding :
1413 continue
15- attr = getattr (model , attr_name )
16- if isinstance (attr , BaseField ):
17- attributes [attr_name ] = attr
18-
14+ attributes [attr_name ] = attr
1915 return OrderedDict (sorted (attributes .items ()))
2016
2117
You can’t perform that action at this time.
0 commit comments