diff --git a/tests/dummy.py b/tests/dummy.py index 98c6220d6a5c39525055a28000b64651d48ac087..f37ab08fe1017e7b8a9240f122d624c769c8e062 100644 --- a/tests/dummy.py +++ b/tests/dummy.py @@ -10,6 +10,8 @@ authors = [ 'openid_uid': 'Wolf', 'first_name': 'Winston', 'last_name': 'Wolfe', + 'is_author': True, + 'extra': {'movies': 1}, }, { 'id': 2, @@ -17,6 +19,15 @@ authors = [ 'openid_uid': 'sponge', 'first_name': 'Spongebob', 'last_name': 'Squarepants', + 'is_author': True, + }, + { + 'id': 3, + 'username': 'shaun', + 'openid_uid': 'shaun', + 'first_name': 'Shaun', + 'last_name': 'Sheep', + 'is_author': True, }, ] @@ -69,3 +80,8 @@ def prepare_reports(): def prepare_report(): author = User.objects.create(**authors[0]) Report.objects.create(author=author, **reports[0]) + + +def prepare_authors(): + for author in authors: + User.objects.create(**author) diff --git a/tests/schema/snapshots/snap_test_authors.py b/tests/schema/snapshots/snap_test_authors.py index eda1a3a143f2294a670cf845647870c4c5520044..897784abd0c78c13eebc875f770e95b5772df835 100644 --- a/tests/schema/snapshots/snap_test_authors.py +++ b/tests/schema/snapshots/snap_test_authors.py @@ -14,21 +14,21 @@ snapshots['test_all 1'] = { { 'cursor': 'MQ==', 'node': { - 'extra': '{"x": 1}', + 'extra': '{"movies": 1}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjE=', 'lastName': 'Wolfe', - 'openidUid': 'first' + 'openidUid': 'Wolf' } }, { 'cursor': 'Mg==', 'node': { 'extra': None, - 'firstName': 'Captain', - 'id': 'QXV0aG9yOjM=', - 'lastName': 'Obvious', - 'openidUid': 'second' + 'firstName': 'Spongebob', + 'id': 'QXV0aG9yOjI=', + 'lastName': 'Squarepants', + 'openidUid': 'sponge' } }, { @@ -36,9 +36,9 @@ snapshots['test_all 1'] = { 'node': { 'extra': None, 'firstName': 'Shaun', - 'id': 'QXV0aG9yOjQ=', + 'id': 'QXV0aG9yOjM=', 'lastName': 'Sheep', - 'openidUid': 'third' + 'openidUid': 'shaun' } } ], @@ -60,13 +60,13 @@ snapshots['test_first 1'] = { { 'cursor': 'MQ==', 'node': { - 'openidUid': 'first' + 'openidUid': 'Wolf' } }, { 'cursor': 'Mg==', 'node': { - 'openidUid': 'second' + 'openidUid': 'sponge' } } ], @@ -88,7 +88,7 @@ snapshots['test_first_after 1'] = { { 'cursor': 'Mg==', 'node': { - 'openidUid': 'second' + 'openidUid': 'sponge' } } ], @@ -127,7 +127,7 @@ snapshots['test_last_before 1'] = { { 'cursor': 'Mg==', 'node': { - 'openidUid': 'second' + 'openidUid': 'sponge' } } ], diff --git a/tests/schema/snapshots/snap_test_node.py b/tests/schema/snapshots/snap_test_node.py index f35ffd408336794448cfdf727912a9de58894b84..89676b8662f10df5cea49fe2974abb9e8a8a6235 100644 --- a/tests/schema/snapshots/snap_test_node.py +++ b/tests/schema/snapshots/snap_test_node.py @@ -38,7 +38,7 @@ snapshots['test_report 1'] = { 'data': { 'node': { 'author': { - 'extra': None, + 'extra': '{"movies": 1}', 'firstName': 'Winston', 'id': 'QXV0aG9yOjE=', 'lastName': 'Wolfe' diff --git a/tests/schema/test_authors.py b/tests/schema/test_authors.py index 88bc1a094debd0c7c7a576ee664d4e500e1f384a..f8c03f9a37875d5644da9f84aa66f8b09e094299 100644 --- a/tests/schema/test_authors.py +++ b/tests/schema/test_authors.py @@ -2,23 +2,15 @@ import pytest from openlobby.core.models import User +from ..dummy import prepare_authors -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 +pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')] def test_all(client, snapshot): + prepare_authors() + User.objects.create(id=4, is_author=False, username='x') res = client.post('/graphql', {'query': """ query { authors { @@ -46,6 +38,7 @@ def test_all(client, snapshot): def test_first(client, snapshot): + prepare_authors() res = client.post('/graphql', {'query': """ query { authors (first: 2) { @@ -69,6 +62,7 @@ def test_first(client, snapshot): def test_first_after(client, snapshot): + prepare_authors() res = client.post('/graphql', {'query': """ query { authors (first: 1, after: "MQ==") { @@ -92,6 +86,7 @@ def test_first_after(client, snapshot): def test_last(client, snapshot): + prepare_authors() res = client.post('/graphql', {'query': """ query { authors (last: 2) { @@ -115,6 +110,7 @@ def test_last(client, snapshot): def test_last_before(client, snapshot): + prepare_authors() res = client.post('/graphql', {'query': """ query { authors (last: 1, before: "Mw==") {