|
2 | 2 | # Adapted for Graphene 2.0
|
3 | 3 |
|
4 | 4 | from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
| 5 | +from graphene.types.inputobjecttype import InputObjectType, InputObjectTypeOptions |
| 6 | +from graphene.types.enum import Enum, EnumOptions |
5 | 7 |
|
6 | 8 |
|
| 9 | +# ObjectType |
7 | 10 | class SpecialOptions(ObjectTypeOptions):
|
8 | 11 | other_attr = None
|
9 | 12 |
|
@@ -40,3 +43,77 @@ class MyType(SpecialObjectType):
|
40 | 43 | assert MyType._meta.name == 'MyType'
|
41 | 44 | assert MyType._meta.default_resolver is None
|
42 | 45 | assert MyType._meta.interfaces == ()
|
| 46 | + |
| 47 | + |
| 48 | +# InputObjectType |
| 49 | +class SpecialInputObjectTypeOptions(ObjectTypeOptions): |
| 50 | + other_attr = None |
| 51 | + |
| 52 | + |
| 53 | +class SpecialInputObjectType(InputObjectType): |
| 54 | + |
| 55 | + @classmethod |
| 56 | + def __init_subclass_with_meta__(cls, other_attr='default', **options): |
| 57 | + _meta = SpecialInputObjectTypeOptions(cls) |
| 58 | + _meta.other_attr = other_attr |
| 59 | + super(SpecialInputObjectType, cls).__init_subclass_with_meta__(_meta=_meta, **options) |
| 60 | + |
| 61 | + |
| 62 | +def test_special_inputobjecttype_could_be_subclassed(): |
| 63 | + class MyInputObjectType(SpecialInputObjectType): |
| 64 | + |
| 65 | + class Meta: |
| 66 | + other_attr = 'yeah!' |
| 67 | + |
| 68 | + assert MyInputObjectType._meta.other_attr == 'yeah!' |
| 69 | + |
| 70 | + |
| 71 | +def test_special_inputobjecttype_could_be_subclassed_default(): |
| 72 | + class MyInputObjectType(SpecialInputObjectType): |
| 73 | + pass |
| 74 | + |
| 75 | + assert MyInputObjectType._meta.other_attr == 'default' |
| 76 | + |
| 77 | + |
| 78 | +def test_special_inputobjecttype_inherit_meta_options(): |
| 79 | + class MyInputObjectType(SpecialInputObjectType): |
| 80 | + pass |
| 81 | + |
| 82 | + assert MyInputObjectType._meta.name == 'MyInputObjectType' |
| 83 | + |
| 84 | + |
| 85 | +# Enum |
| 86 | +class SpecialEnumOptions(EnumOptions): |
| 87 | + other_attr = None |
| 88 | + |
| 89 | + |
| 90 | +class SpecialEnum(Enum): |
| 91 | + |
| 92 | + @classmethod |
| 93 | + def __init_subclass_with_meta__(cls, other_attr='default', **options): |
| 94 | + _meta = SpecialEnumOptions(cls) |
| 95 | + _meta.other_attr = other_attr |
| 96 | + super(SpecialEnum, cls).__init_subclass_with_meta__(_meta=_meta, **options) |
| 97 | + |
| 98 | + |
| 99 | +def test_special_enum_could_be_subclassed(): |
| 100 | + class MyEnum(SpecialEnum): |
| 101 | + |
| 102 | + class Meta: |
| 103 | + other_attr = 'yeah!' |
| 104 | + |
| 105 | + assert MyEnum._meta.other_attr == 'yeah!' |
| 106 | + |
| 107 | + |
| 108 | +def test_special_enum_could_be_subclassed_default(): |
| 109 | + class MyEnum(SpecialEnum): |
| 110 | + pass |
| 111 | + |
| 112 | + assert MyEnum._meta.other_attr == 'default' |
| 113 | + |
| 114 | + |
| 115 | +def test_special_enum_inherit_meta_options(): |
| 116 | + class MyEnum(SpecialEnum): |
| 117 | + pass |
| 118 | + |
| 119 | + assert MyEnum._meta.name == 'MyEnum' |
0 commit comments