def test_handles_unsupported_http_methods():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, "put", None)

    assert exc_info.value == HttpQueryError(
        405,
        "GraphQL only supports GET and POST requests.",
        headers={"Allow": "GET, POST"},
    )
예제 #2
0
def test_handles_unsupported_http_methods():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, 'put', None)

    assert exc_info.value == HttpQueryError(
        405,
        'GraphQL only supports GET and POST requests.',
        headers={
            'Allow': 'GET, POST'
        }
    )
예제 #3
0
def test_hash_http_query_errors():
    errors = {
        HttpQueryError(400, "Bad error 1"),
        HttpQueryError(400, "Bad error 2"),
        HttpQueryError(403, "Bad error 1"),
    }
    assert HttpQueryError(400, "Bad error 1") in errors
    assert HttpQueryError(400, "Bad error 2") in errors
    assert HttpQueryError(403, "Bad error 1") in errors
    assert HttpQueryError(403, "Bad error 2") not in errors
예제 #4
0
def test_handles_poorly_formed_variables():
    with raises(HttpQueryError) as exc_info:
        run_http_query(
            schema,
            "get",
            {},
            dict(
                query="query helloWho($who: String){ test(who: $who) }",
                variables="who:You",
            ),
        )

    assert exc_info.value == HttpQueryError(400, "Variables are invalid JSON.")
예제 #5
0
def test_errors_when_sending_a_mutation_via_get():
    with raises(HttpQueryError) as exc_info:
        run_http_query(
            schema,
            "get",
            {},
            query_data=dict(query="""
                mutation TestMutation { writeTest { test } }
                """),
        )

    assert exc_info.value == HttpQueryError(
        405,
        "Can only perform a mutation operation from a POST request.",
        headers={"Allow": "POST"},
    )
예제 #6
0
def test_handles_plain_post_text():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, "post", {})

    assert exc_info.value == HttpQueryError(400, "Must provide query string.")
예제 #7
0
def test_handles_incomplete_json_bodies():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, "post", load_json_body('{"query":'))

    assert exc_info.value == HttpQueryError(400,
                                            "POST body sent invalid JSON.")
예제 #8
0
def test_handles_batch_correctly_if_is_disabled():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, "post", [])

    assert exc_info.value == HttpQueryError(
        400, "Batch GraphQL requests are not enabled.")
예제 #9
0
def test_handles_errors_caused_by_a_lack_of_query():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, "get", {})

    assert exc_info.value == HttpQueryError(400, "Must provide query string.")
예제 #10
0
def test_empty_batch_in_batch_query():
    with raises(HttpQueryError) as exc_info:
        run_http_query(schema, "get", [], batch_enabled=True)

    assert exc_info.value == HttpQueryError(
        400, "Received an empty list in the batch request.")
예제 #11
0
def test_load_invalid_json_body():
    with raises(HttpQueryError) as exc_info:
        load_json_body('{"query":')
    assert exc_info.value == HttpQueryError(400,
                                            "POST body sent invalid JSON.")
예제 #12
0
def test_handles_errors_caused_by_invalid_query_type():
    with raises(HttpQueryError) as exc_info:
        results, params = run_http_query(schema, "get", dict(query=42))

    assert exc_info.value == HttpQueryError(400, "Unexpected query type.")
예제 #13
0
def test_can_create_http_query_error():
    error = HttpQueryError(400, "Bad error")
    assert error.status_code == 400
    assert error.message == "Bad error"
    assert not error.is_graphql_error
    assert error.headers is None