|
4 | 4 | from graphene.relay import Node, is_node
|
5 | 5 |
|
6 | 6 | from .. import registry
|
7 |
| -from ..types import MongoengineObjectType |
| 7 | +from ..types import MongoengineObjectType, MongoengineObjectTypeOptions |
8 | 8 | from .models import Article, EmbeddedArticle, Reporter
|
9 | 9 | from .models import Parent, Child
|
10 | 10 | from .utils import with_local_registry
|
@@ -127,3 +127,41 @@ class Meta:
|
127 | 127 | exclude_fields = ('headline')
|
128 | 128 |
|
129 | 129 | assert 'headline' not in list(A._meta.fields.keys())
|
| 130 | + |
| 131 | + |
| 132 | +@with_local_registry |
| 133 | +def test_passing_meta_when_subclassing_mongoengine_objecttype(): |
| 134 | + class TypeSubclassWithBadOptions(MongoengineObjectType): |
| 135 | + class Meta: |
| 136 | + abstract = True |
| 137 | + |
| 138 | + @classmethod |
| 139 | + def __init_subclass_with_meta__(cls, **kwargs): |
| 140 | + _meta = ['hi'] |
| 141 | + super(TypeSubclassWithBadOptions, cls). \ |
| 142 | + __init_subclass_with_meta__(_meta=_meta, **kwargs) |
| 143 | + |
| 144 | + with raises(Exception) as einfo: |
| 145 | + class A(TypeSubclassWithBadOptions): |
| 146 | + class Meta: |
| 147 | + model = Article |
| 148 | + assert 'instance of MongoengineObjectTypeOptions' in str(einfo.value) |
| 149 | + |
| 150 | + class TypeSubclass(MongoengineObjectType): |
| 151 | + class Meta: |
| 152 | + abstract = True |
| 153 | + |
| 154 | + @classmethod |
| 155 | + def __init_subclass_with_meta__(cls, some_subclass_attr=None, |
| 156 | + **kwargs): |
| 157 | + _meta = MongoengineObjectTypeOptions(cls) |
| 158 | + _meta.some_subclass_attr = some_subclass_attr |
| 159 | + super(TypeSubclass, cls). \ |
| 160 | + __init_subclass_with_meta__(_meta=_meta, **kwargs) |
| 161 | + |
| 162 | + class B(TypeSubclass): |
| 163 | + class Meta: |
| 164 | + model = Article |
| 165 | + some_subclass_attr = 'someval' |
| 166 | + assert hasattr(B._meta, 'some_subclass_attr') |
| 167 | + assert B._meta.some_subclass_attr == 'someval' |
0 commit comments