simonw / datasette-graphql

Datasette plugin providing an automatic GraphQL API for your SQLite databases
https://datasette-graphql-demo.datasette.io/
Apache License 2.0
100 stars 6 forks source link

test_num_queries_limit fail on Python 3.6 #83

Closed simonw closed 2 years ago

simonw commented 2 years ago

Tests pass on other Pythons, fail on 3.6 here: https://github.com/simonw/datasette-graphql/runs/4241305026?check_suite_focus=true

=================================== FAILURES ===================================
____________________________ test_num_queries_limit ____________________________

db_path = PosixPath('/tmp/pytest-of-runner/pytest-0/dbs0/test.db')

    @pytest.mark.asyncio
    async def test_num_queries_limit(db_path):
        ds = Datasette(
            [str(db_path)],
            metadata={"plugins": {"datasette-graphql": {"num_queries_limit": 2}}},
        )
        query = """
        {
            users {
                nodes {
                    id
                    name
                    repos_list {
                        nodes {
                            full_name
                        }
                    }
                }
            }
        }
        """
        response = await ds.client.post("/graphql", json={"query": query})
        assert response.status_code == 500
>       assert response.json() == {
            "data": {
                "users": {
                    "nodes": [
                        {
                            "id": 1,
                            "name": "cleopaws",
                            "repos_list": {"nodes": [{"full_name": "cleopaws/dogspotter"}]},
                        },
                        {"id": 2, "name": "simonw", "repos_list": None},
                    ]
                }
            },
            "errors": [
                {
                    "message": "Query limit exceeded: 3 > 2 - /test/repos.json?_nofacet=1&_size=10&owner=2",
                    "locations": [{"line": 7, "column": 17}],
                    "path": ["users", "nodes", 1, "repos_list"],
                }
            ],
        }
E       AssertionError: assert {'data': {'us...epos_list']}]} == {'data': {'us...epos_list']}]}
E         Differing items:
E         {'errors': [{'locations': [{'column': 17, 'line': 7}], 'message': 'Query limit exceeded: 3 > 2 - /test/repos.json?_nofacet=1&_size=10&owner=1', 'path': ['users', 'nodes', 0, 'repos_list']}]} != {'errors': [{'locations': [{'column': 17, 'line': 7}], 'message': 'Query limit exceeded: 3 > 2 - /test/repos.json?_nofacet=1&_size=10&owner=2', 'path': ['users', 'nodes', 1, 'repos_list']}]}
E         {'data': {'users': {'nodes': [{'id': 1, 'name': 'cleopaws', 'repos_list': None}, {'id': 2, 'name': 'simonw', 'repos_list': {'nodes': [...]}}]}}} != {'data': {'users': {'nodes': [{'id': 1, 'name': 'cleopaws', 'repos_list': {'nodes': [...]}}, {'id': 2, 'name': 'simonw', 'repos_list': None}]}}}
E         Use -v to get the full diff
simonw commented 2 years ago

Here's a diff that fixes the tests in 3.6 (and breaks them elsewhere):

diff --git a/tests/test_graphql.py b/tests/test_graphql.py
index dcbe8bd..77e70cb 100644
--- a/tests/test_graphql.py
+++ b/tests/test_graphql.py
@@ -557,20 +557,25 @@ async def test_num_queries_limit(db_path):
         "data": {
             "users": {
                 "nodes": [
+                    {"id": 1, "name": "cleopaws", "repos_list": None},
                     {
-                        "id": 1,
-                        "name": "cleopaws",
-                        "repos_list": {"nodes": [{"full_name": "cleopaws/dogspotter"}]},
+                        "id": 2,
+                        "name": "simonw",
+                        "repos_list": {
+                            "nodes": [
+                                {"full_name": "simonw/datasette"},
+                                {"full_name": "simonw/private"},
+                            ]
+                        },
                     },
-                    {"id": 2, "name": "simonw", "repos_list": None},
                 ]
             }
         },
         "errors": [
             {
-                "message": "Query limit exceeded: 3 > 2 - /test/repos.json?_nofacet=1&_size=10&owner=2",
+                "message": "Query limit exceeded: 3 > 2 - /test/repos.json?_nofacet=1&_size=10&owner=1",
                 "locations": [{"line": 7, "column": 17}],
-                "path": ["users", "nodes", 1, "repos_list"],
+                "path": ["users", "nodes", 0, "repos_list"],
             }
         ],
     }
simonw commented 2 years ago

The difference is that repos_list now comes back empty for Cleo and populated for Simon, whereas in other versions it comes back empty for Simon and populated for Cleo.

simonw commented 2 years ago

I'm updating the test so it passes provided at least one user has an empty repos_list and the error message starts with the correct text.