1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
from pytest import raises
from ..field import Field
from ..objecttype import ObjectType
from ..union import Union
from ..unmountedtype import UnmountedType
class MyObjectType1(ObjectType):
pass
class MyObjectType2(ObjectType):
pass
def test_generate_union():
class MyUnion(Union):
"""Documentation"""
class Meta:
types = (MyObjectType1, MyObjectType2)
assert MyUnion._meta.name == "MyUnion"
assert MyUnion._meta.description == "Documentation"
assert MyUnion._meta.types == (MyObjectType1, MyObjectType2)
def test_generate_union_with_meta():
class MyUnion(Union):
class Meta:
name = "MyOtherUnion"
description = "Documentation"
types = (MyObjectType1, MyObjectType2)
assert MyUnion._meta.name == "MyOtherUnion"
assert MyUnion._meta.description == "Documentation"
def test_generate_union_with_no_types():
with raises(Exception) as exc_info:
class MyUnion(Union):
pass
assert str(exc_info.value) == "Must provide types for Union MyUnion."
def test_union_can_be_mounted():
class MyUnion(Union):
class Meta:
types = (MyObjectType1, MyObjectType2)
my_union_instance = MyUnion()
assert isinstance(my_union_instance, UnmountedType)
my_union_field = my_union_instance.mount_as(Field)
assert isinstance(my_union_field, Field)
assert my_union_field.type == MyUnion
|