Example #1
0
    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"))
Example #2
0
    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"))
Example #3
0
    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))
Example #4
0
    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=()))
Example #5
0
    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")
Example #6
0
    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()))
Example #7
0
    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)
Example #8
0
    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"))
Example #9
0
    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()))
Example #10
0
    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)
        """)))