From 12d7d81def335dc76ef9896b998f3d7fc9e56556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Sun, 28 Jan 2018 14:04:48 +0100 Subject: [PATCH] Authors schema tests. --- openlobby/core/api/schema.py | 7 +- .../core/tests/snapshots/snap_test_schema.py | 101 +++++++++++++++++- openlobby/core/tests/test_schema.py | 100 ++++++++++++++++- 3 files changed, 200 insertions(+), 8 deletions(-) diff --git a/openlobby/core/api/schema.py b/openlobby/core/api/schema.py index 035594f..eb66ac6 100644 --- a/openlobby/core/api/schema.py +++ b/openlobby/core/api/schema.py @@ -33,10 +33,13 @@ class Query: ' Default: false') node = relay.Node.Field() - authors = relay.ConnectionField(AuthorsConnection) + authors = relay.ConnectionField( + AuthorsConnection, + description='List of Authors. Returns first 10 nodes if pagination is not specified.', + ) search_reports = relay.ConnectionField( SearchReportsConnection, - description='Fulltext search in Reports.', + description='Fulltext search in Reports. Returns first 10 nodes if pagination is not specified.', query=graphene.String(description='Text to search for.'), highlight=graphene.Boolean(default_value=False, description=highlight_help), ) diff --git a/openlobby/core/tests/snapshots/snap_test_schema.py b/openlobby/core/tests/snapshots/snap_test_schema.py index 81dfb09..151ec07 100644 --- a/openlobby/core/tests/snapshots/snap_test_schema.py +++ b/openlobby/core/tests/snapshots/snap_test_schema.py @@ -63,7 +63,7 @@ snapshots['TestAuthors.test_all 1'] = { 'firstName': 'Winston', 'id': 'QXV0aG9yOjE=', 'lastName': 'Wolfe', - 'openidUid': 'TheWolf' + 'openidUid': 'first' } }, { @@ -73,7 +73,7 @@ snapshots['TestAuthors.test_all 1'] = { 'firstName': 'Captain', 'id': 'QXV0aG9yOjM=', 'lastName': 'Obvious', - 'openidUid': 'ccc' + 'openidUid': 'second' } }, { @@ -83,11 +83,106 @@ snapshots['TestAuthors.test_all 1'] = { 'firstName': 'Shaun', 'id': 'QXV0aG9yOjQ=', 'lastName': 'Sheep', - 'openidUid': 'ddd' + 'openidUid': 'third' } } ], + 'pageInfo': { + 'endCursor': 'Mw==', + 'hasNextPage': False, + 'hasPreviousPage': False, + 'startCursor': 'MQ==' + }, 'totalCount': 3 } } } + +snapshots['TestAuthors.test_first 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'MQ==', + 'node': { + 'openidUid': 'first' + } + }, + { + 'cursor': 'Mg==', + 'node': { + 'openidUid': 'second' + } + } + ], + 'pageInfo': { + 'endCursor': 'Mg==', + 'hasNextPage': True, + 'hasPreviousPage': False, + 'startCursor': 'MQ==' + }, + 'totalCount': 3 + } + } +} + +snapshots['TestAuthors.test_first_after 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'Mg==', + 'node': { + 'openidUid': 'second' + } + } + ], + 'pageInfo': { + 'endCursor': 'Mg==', + 'hasNextPage': True, + 'hasPreviousPage': True, + 'startCursor': 'Mg==' + }, + 'totalCount': 3 + } + } +} + +snapshots['TestAuthors.test_last_before 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'Mg==', + 'node': { + 'openidUid': 'second' + } + } + ], + 'pageInfo': { + 'endCursor': 'Mg==', + 'hasNextPage': True, + 'hasPreviousPage': True, + 'startCursor': 'Mg==' + }, + 'totalCount': 3 + } + } +} + +snapshots['TestAuthors.test_last 1'] = { + 'data': { + 'authors': None + }, + 'errors': [ + { + 'locations': [ + { + 'column': 13, + 'line': 3 + } + ], + 'message': 'Pagination "last" works only in combination with "before" argument.' + } + ] +} diff --git a/openlobby/core/tests/test_schema.py b/openlobby/core/tests/test_schema.py index a3060b7..8b0be3e 100644 --- a/openlobby/core/tests/test_schema.py +++ b/openlobby/core/tests/test_schema.py @@ -95,12 +95,12 @@ class TestAuthors: @pytest.fixture(autouse=True) def setup(self): - User.objects.create(id=1, is_author=True, username='a', openid_uid='TheWolf', + User.objects.create(id=1, is_author=True, username='a', openid_uid='first', first_name='Winston', last_name='Wolfe', extra={'x': 1}) User.objects.create(id=2, is_author=False, username='b') - User.objects.create(id=3, is_author=True, username='c', openid_uid='ccc', + User.objects.create(id=3, is_author=True, username='c', openid_uid='second', first_name='Captain', last_name='Obvious') - User.objects.create(id=4, is_author=True, username='d', openid_uid='ddd', + User.objects.create(id=4, is_author=True, username='d', openid_uid='third', first_name='Shaun', last_name='Sheep') yield @@ -119,6 +119,100 @@ class TestAuthors: extra } } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_first(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (first: 2) { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_first_after(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (first: 1, after: "MQ==") { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_last(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (last: 2) { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + def test_last_before(self, client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (last: 1, before: "Mw==") { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } } } """}) -- GitLab