client = <FlaskClient <Flask 'swh.graphql.tests.conftest'>>
def test_query_cost_snapshots(client):
query_str = """
{
snapshot(swhid: "%s") {
branches(first: 50) {
nodes {
target {
...on Revision {
swhid
}
...on Directory {
swhid
entries(first: 3) {
nodes {
targetType
}
}
}
}
}
}
}
}
"""
# Total cost here is 157
# 1 (snapshot) + 2 *50 (branches) + 50 * 1 (revision or Directory) + 3 * 2 = 157
# parent multiplier is not applied when schema introspection is used
# ie: directory entry connection cost is 3 * 2 and not 50 * 3 * 2
> errors = utils.get_error_response(client, query_str % get_snapshots()[0].swhid())
.tox/py3/lib/python3.7/site-packages/swh/graphql/tests/functional/test_query_cost.py:107:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/graphql/tests/functional/utils.py:29: in get_error_response
data, errors = get_query_response(client, query_str, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
client = <FlaskClient <Flask 'swh.graphql.tests.conftest'>>
query_str = '\n {\n snapshot(swhid: "swh:1:snp:9e78d7105c5e0f886487511e2a92377b4ee4c32a") {\n branches(first: 50) {...\n }\n }\n }\n }\n }\n }\n }\n }\n '
kwargs = {}
query = '\n {\n snapshot(swhid: "swh:1:snp:9e78d7105c5e0f886487511e2a92377b4ee4c32a") {\n branches(first: 50) {...\n }\n }\n }\n }\n }\n }\n }\n }\n '
response = <WrapperTestResponse 161 bytes [400 BAD REQUEST]>, @py_assert1 = 400
@py_assert4 = 200, @py_assert3 = False
@py_format6 = '400\n{400 = <WrapperTestResponse streamed [400 BAD REQUEST]>.status_code\n} == 200'
@py_format8 = 'b\'{"errors":[{"extensions":{"cost":{"maximumAvailable":100,"requestedQueryCost":157}},"message":"The query exceeds t...ctual cost is 157"}]}\n~\'\n>assert 400\n{400 = <WrapperTestResponse streamed [400 BAD REQUEST]>.status_code\n} == 200'
def get_query_response(client, query_str: str, **kwargs) -> Tuple[Dict, Dict]:
query = gql(query_str)
response = client.post("/", json={"query": query, "variables": kwargs})
> assert response.status_code == 200, response.data
E AssertionError: b'{"errors":[{"extensions":{"cost":{"maximumAvailable":100,"requestedQueryCost":157}},"message":"The query exceeds the maximum cost of 100. Actual cost is 157"}]}
E '
E assert 400 == 200
E + where 400 = <WrapperTestResponse streamed [400 BAD REQUEST]>.status_code
.tox/py3/lib/python3.7/site-packages/swh/graphql/tests/functional/utils.py:15: AssertionError
TEST RESULT
TEST RESULT
- Run At
- Oct 25 2022, 11:49 AM