From df2a497fc16c2268fec95315d304fda1872b040f 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:56:04 +0100 Subject: [PATCH] Split schema tests into multiple files. --- tests/schema/__init__.py | 0 tests/schema/snapshots/__init__.py | 0 .../snapshots/snap_test_authors.py} | 87 ++----- .../snapshots/snap_test_login_shortcuts.py | 26 +++ tests/schema/snapshots/snap_test_node.py | 35 +++ tests/schema/test_authors.py | 137 +++++++++++ tests/schema/test_login_shortcuts.py | 33 +++ tests/schema/test_node.py | 61 +++++ tests/test_schema.py | 219 ------------------ 9 files changed, 313 insertions(+), 285 deletions(-) create mode 100644 tests/schema/__init__.py create mode 100644 tests/schema/snapshots/__init__.py rename tests/{snapshots/snap_test_schema.py => schema/snapshots/snap_test_authors.py} (75%) create mode 100644 tests/schema/snapshots/snap_test_login_shortcuts.py create mode 100644 tests/schema/snapshots/snap_test_node.py create mode 100644 tests/schema/test_authors.py create mode 100644 tests/schema/test_login_shortcuts.py create mode 100644 tests/schema/test_node.py delete mode 100644 tests/test_schema.py diff --git a/tests/schema/__init__.py b/tests/schema/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/schema/snapshots/__init__.py b/tests/schema/snapshots/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/snapshots/snap_test_schema.py b/tests/schema/snapshots/snap_test_authors.py similarity index 75% rename from tests/snapshots/snap_test_schema.py rename to tests/schema/snapshots/snap_test_authors.py index 151ec07..eda1a3a 100644 --- a/tests/snapshots/snap_test_schema.py +++ b/tests/schema/snapshots/snap_test_authors.py @@ -7,52 +7,7 @@ from snapshottest import Snapshot snapshots = Snapshot() -snapshots['test_login_shortcuts__none 1'] = { - 'data': { - 'loginShortcuts': [ - ] - } -} - -snapshots['test_login_shortcuts 1'] = { - 'data': { - 'loginShortcuts': [ - { - 'id': 'TG9naW5TaG9ydGN1dDoyMA==', - 'name': 'bar' - } - ] - } -} - -snapshots['test_node__login_shortcut 1'] = { - 'data': { - 'node': { - 'id': 'TG9naW5TaG9ydGN1dDoxMA==', - 'name': 'foo' - } - } -} - -snapshots['test_node__author 1'] = { - 'data': { - 'node': { - 'extra': '{"x": 1}', - 'firstName': 'Winston', - 'id': 'QXV0aG9yOjU=', - 'lastName': 'Wolfe', - 'openidUid': 'TheWolf' - } - } -} - -snapshots['test_node__author__only_if_is_author 1'] = { - 'data': { - 'node': None - } -} - -snapshots['TestAuthors.test_all 1'] = { +snapshots['test_all 1'] = { 'data': { 'authors': { 'edges': [ @@ -98,7 +53,7 @@ snapshots['TestAuthors.test_all 1'] = { } } -snapshots['TestAuthors.test_first 1'] = { +snapshots['test_first 1'] = { 'data': { 'authors': { 'edges': [ @@ -126,7 +81,7 @@ snapshots['TestAuthors.test_first 1'] = { } } -snapshots['TestAuthors.test_first_after 1'] = { +snapshots['test_first_after 1'] = { 'data': { 'authors': { 'edges': [ @@ -148,7 +103,24 @@ snapshots['TestAuthors.test_first_after 1'] = { } } -snapshots['TestAuthors.test_last_before 1'] = { +snapshots['test_last 1'] = { + 'data': { + 'authors': None + }, + 'errors': [ + { + 'locations': [ + { + 'column': 9, + 'line': 3 + } + ], + 'message': 'Pagination "last" works only in combination with "before" argument.' + } + ] +} + +snapshots['test_last_before 1'] = { 'data': { 'authors': { 'edges': [ @@ -169,20 +141,3 @@ snapshots['TestAuthors.test_last_before 1'] = { } } } - -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/tests/schema/snapshots/snap_test_login_shortcuts.py b/tests/schema/snapshots/snap_test_login_shortcuts.py new file mode 100644 index 0000000..45cc81f --- /dev/null +++ b/tests/schema/snapshots/snap_test_login_shortcuts.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# snapshottest: v1 - https://goo.gl/zC4yUc +from __future__ import unicode_literals + +from snapshottest import Snapshot + + +snapshots = Snapshot() + +snapshots['test_returns_only_shortcuts 1'] = { + 'data': { + 'loginShortcuts': [ + { + 'id': 'TG9naW5TaG9ydGN1dDoyMA==', + 'name': 'bar' + } + ] + } +} + +snapshots['test_none 1'] = { + 'data': { + 'loginShortcuts': [ + ] + } +} diff --git a/tests/schema/snapshots/snap_test_node.py b/tests/schema/snapshots/snap_test_node.py new file mode 100644 index 0000000..65af548 --- /dev/null +++ b/tests/schema/snapshots/snap_test_node.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# snapshottest: v1 - https://goo.gl/zC4yUc +from __future__ import unicode_literals + +from snapshottest import Snapshot + + +snapshots = Snapshot() + +snapshots['test_login_shortcut 1'] = { + 'data': { + 'node': { + 'id': 'TG9naW5TaG9ydGN1dDoxMA==', + 'name': 'foo' + } + } +} + +snapshots['test_author 1'] = { + 'data': { + 'node': { + 'extra': '{"x": 1}', + 'firstName': 'Winston', + 'id': 'QXV0aG9yOjU=', + 'lastName': 'Wolfe', + 'openidUid': 'TheWolf' + } + } +} + +snapshots['test_author__returns_only_if_is_author 1'] = { + 'data': { + 'node': None + } +} diff --git a/tests/schema/test_authors.py b/tests/schema/test_authors.py new file mode 100644 index 0000000..88bc1a0 --- /dev/null +++ b/tests/schema/test_authors.py @@ -0,0 +1,137 @@ +import pytest + +from openlobby.core.models import User + + +pytestmark = pytest.mark.django_db + + +@pytest.fixture(autouse=True) +def setup(): + 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='second', + first_name='Captain', last_name='Obvious') + User.objects.create(id=4, is_author=True, username='d', openid_uid='third', + first_name='Shaun', last_name='Sheep') + yield + + +def test_all(client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors { + totalCount + edges { + cursor + node { + id + firstName + lastName + openidUid + extra + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) + + +def test_first(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(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(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(client, snapshot): + res = client.post('/graphql', {'query': """ + query { + authors (last: 1, before: "Mw==") { + totalCount + edges { + cursor + node { + openidUid + } + } + pageInfo { + hasPreviousPage + hasNextPage + startCursor + endCursor + } + } + } + """}) + snapshot.assert_match(res.json()) diff --git a/tests/schema/test_login_shortcuts.py b/tests/schema/test_login_shortcuts.py new file mode 100644 index 0000000..92f44fc --- /dev/null +++ b/tests/schema/test_login_shortcuts.py @@ -0,0 +1,33 @@ +import pytest + +from openlobby.core.models import OpenIdClient + + +pytestmark = pytest.mark.django_db + + +def test_returns_only_shortcuts(client, snapshot): + OpenIdClient.objects.create(id=10, name='foo', issuer='foo') + OpenIdClient.objects.create(id=20, name='bar', issuer='bar', is_shortcut=True) + res = client.post('/graphql', {'query': """ + query { + loginShortcuts { + id + name + } + } + """}) + snapshot.assert_match(res.json()) + + +def test_none(client, snapshot): + OpenIdClient.objects.create(id=10, name='foo') + res = client.post('/graphql', {'query': """ + query { + loginShortcuts { + id + name + } + } + """}) + snapshot.assert_match(res.json()) diff --git a/tests/schema/test_node.py b/tests/schema/test_node.py new file mode 100644 index 0000000..eeaa5e2 --- /dev/null +++ b/tests/schema/test_node.py @@ -0,0 +1,61 @@ +import pytest +from graphql_relay import to_global_id + +from openlobby.core.models import OpenIdClient, User + + +pytestmark = pytest.mark.django_db + + +def test_login_shortcut(client, snapshot): + OpenIdClient.objects.create(id=10, name='foo', issuer='foo', is_shortcut=True) + res = client.post('/graphql', {'query': """ + query {{ + node (id:"{id}") {{ + ... on LoginShortcut {{ + id + name + }} + }} + }} + """.format(id=to_global_id('LoginShortcut', 10))}) + snapshot.assert_match(res.json()) + + +def test_author(client, snapshot): + User.objects.create( + id=5, + is_author=True, + openid_uid='TheWolf', + first_name='Winston', + last_name='Wolfe', + extra={'x': 1}, + ) + res = client.post('/graphql', {'query': """ + query {{ + node (id:"{id}") {{ + ... on Author {{ + id + firstName + lastName + openidUid + extra + }} + }} + }} + """.format(id=to_global_id('Author', 5))}) + snapshot.assert_match(res.json()) + + +def test_author__returns_only_if_is_author(client, snapshot): + User.objects.create(id=7, is_author=False) + res = client.post('/graphql', {'query': """ + query {{ + node (id:"{id}") {{ + ... on Author {{ + id + }} + }} + }} + """.format(id=to_global_id('Author', 7))}) + snapshot.assert_match(res.json()) diff --git a/tests/test_schema.py b/tests/test_schema.py deleted file mode 100644 index 4bf9e08..0000000 --- a/tests/test_schema.py +++ /dev/null @@ -1,219 +0,0 @@ -import pytest -from graphql_relay import to_global_id - -from openlobby.core.models import OpenIdClient, User - - -@pytest.mark.django_db -def test_login_shortcuts(client, snapshot): - OpenIdClient.objects.create(id=10, name='foo', issuer='foo') - OpenIdClient.objects.create(id=20, name='bar', issuer='bar', is_shortcut=True) - res = client.post('/graphql', {'query': """ - query { - loginShortcuts { - id - name - } - } - """}) - snapshot.assert_match(res.json()) - - -@pytest.mark.django_db -def test_login_shortcuts__none(client, snapshot): - OpenIdClient.objects.create(id=10, name='foo') - res = client.post('/graphql', {'query': """ - query { - loginShortcuts { - id - name - } - } - """}) - snapshot.assert_match(res.json()) - - -@pytest.mark.django_db -def test_node__login_shortcut(client, snapshot): - OpenIdClient.objects.create(id=10, name='foo', issuer='foo', is_shortcut=True) - res = client.post('/graphql', {'query': """ - query {{ - node (id:"{id}") {{ - ... on LoginShortcut {{ - id - name - }} - }} - }} - """.format(id=to_global_id('LoginShortcut', 10))}) - snapshot.assert_match(res.json()) - - -@pytest.mark.django_db -def test_node__author(client, snapshot): - User.objects.create( - id=5, - is_author=True, - openid_uid='TheWolf', - first_name='Winston', - last_name='Wolfe', - extra={'x': 1}, - ) - res = client.post('/graphql', {'query': """ - query {{ - node (id:"{id}") {{ - ... on Author {{ - id - firstName - lastName - openidUid - extra - }} - }} - }} - """.format(id=to_global_id('Author', 5))}) - snapshot.assert_match(res.json()) - - -@pytest.mark.django_db -def test_node__author__only_if_is_author(client, snapshot): - User.objects.create(id=7, is_author=False) - res = client.post('/graphql', {'query': """ - query {{ - node (id:"{id}") {{ - ... on Author {{ - id - }} - }} - }} - """.format(id=to_global_id('Author', 7))}) - snapshot.assert_match(res.json()) - - -@pytest.mark.django_db -class TestAuthors: - - @pytest.fixture(autouse=True) - def setup(self): - 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='second', - first_name='Captain', last_name='Obvious') - User.objects.create(id=4, is_author=True, username='d', openid_uid='third', - first_name='Shaun', last_name='Sheep') - yield - - def test_all(self, client, snapshot): - res = client.post('/graphql', {'query': """ - query { - authors { - totalCount - edges { - cursor - node { - id - firstName - lastName - openidUid - 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 - } - } - } - """}) - snapshot.assert_match(res.json()) -- GitLab