def test_cannot_change_type_of_enum_query(self): class Season(enum.Enum): winter = "WINTER" class Quarter(enum.Enum): q1 = "Q1" SeasonGraphType = schema.EnumType(Season) QuarterGraphType = schema.EnumType(Quarter) error = pytest.raises(TypeError, lambda: SeasonGraphType().for_type(QuarterGraphType)) assert_that(str(error.value), equal_to("cannot coerce query for Season to query for Quarter"))
def test_adding_enum_queries_of_different_type_raises_type_error(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) class Size(enum.Enum): big = "big" small = "small" SizeGraphType = schema.EnumType(Size) error = pytest.raises(TypeError, lambda: DirectionGraphType() + SizeGraphType()) assert_that(str(error.value), equal_to("cannot add queries for different enum types: Direction and Size"))
def test_enum_has_no_child_types(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) assert_that(schema.collect_types((DirectionGraphType, )), contains_exactly(DirectionGraphType))
def test_adding_enum_query_to_other_query_raises_type_error(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) pytest.raises(TypeError, lambda: DirectionGraphType() + schema.ObjectType("Obj", fields=()))
def test_cannot_coerce_string_to_enum(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) self._assert_coercion_failure(DirectionGraphType, "up", "cannot coerce 'up' to Direction")
def test_enum_queries_merge_into_enum_query(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) query = DirectionGraphType() + DirectionGraphType() assert_that(query, is_query(DirectionGraphType()))
def test_enum_type_coerces_enum_values_to_enum_values(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) self._assert_coercion(DirectionGraphType, Direction.up, Direction.up) self._assert_coercion(DirectionGraphType, Direction.down, Direction.down)
def test_enums_are_converted_to_strings(self): class Season(enum.Enum): winter = "WINTER" spring = "SPRING" summer = "SUMMER" autumn = "AUTUMN" SeasonGraphType = schema.EnumType(Season) query = SeasonGraphType() assert_that(query.to_json_value(Season.winter), equal_to("WINTER"))
def test_enum_query_for_type_is_enum_query(self): class Season(enum.Enum): winter = "WINTER" spring = "SPRING" summer = "SUMMER" autumn = "AUTUMN" SeasonGraphType = schema.EnumType(Season) query = SeasonGraphType().for_type(SeasonGraphType) assert_that(query, is_query(SeasonGraphType()))
def test_enum_query_string_includes_type(self): class Direction(enum.Enum): up = "up" down = "down" DirectionGraphType = schema.EnumType(Direction) query = DirectionGraphType() assert_that(str(query), equal_to(dedent(""" EnumQuery(type=Direction) """)))