diff --git a/openlobby/core/tests/snapshots/snap_test_schema.py b/openlobby/core/tests/snapshots/snap_test_schema.py index 50b4228282f4443073b66b1a83b37208c3573b3c..81dfb093baf81cb553170feb3f6237291509ea16 100644 --- a/openlobby/core/tests/snapshots/snap_test_schema.py +++ b/openlobby/core/tests/snapshots/snap_test_schema.py @@ -7,14 +7,87 @@ from snapshottest import Snapshot snapshots = Snapshot() -snapshots['test_login_shortcuts__none 1'] = b'{"data":{"loginShortcuts":[]}}' +snapshots['test_login_shortcuts__none 1'] = { + 'data': { + 'loginShortcuts': [ + ] + } +} -snapshots['test_login_shortcuts 1'] = b'{"data":{"loginShortcuts":[{"id":"TG9naW5TaG9ydGN1dDoyMA==","name":"bar"}]}}' +snapshots['test_login_shortcuts 1'] = { + 'data': { + 'loginShortcuts': [ + { + 'id': 'TG9naW5TaG9ydGN1dDoyMA==', + 'name': 'bar' + } + ] + } +} -snapshots['test_node__login_shortcut 1'] = b'{"data":{"node":{"id":"TG9naW5TaG9ydGN1dDoxMA==","name":"foo"}}}' +snapshots['test_node__login_shortcut 1'] = { + 'data': { + 'node': { + 'id': 'TG9naW5TaG9ydGN1dDoxMA==', + 'name': 'foo' + } + } +} -snapshots['test_node__author 1'] = b'{"data":{"node":{"id":"QXV0aG9yOjU=","firstName":"Winston","lastName":"Wolfe","openidUid":"TheWolf","extra":"{\\"x\\": 1}"}}}' +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'] = b'{"data":{"node":null}}' +snapshots['test_node__author__only_if_is_author 1'] = { + 'data': { + 'node': None + } +} -snapshots['test_authors 1'] = b'{"data":{"authors":{"totalCount":1,"edges":[{"node":{"id":"QXV0aG9yOjU=","firstName":"Winston","lastName":"Wolfe","openidUid":"TheWolf","extra":"{\\"x\\": 1}"}}]}}}' +snapshots['TestAuthors.test_all 1'] = { + 'data': { + 'authors': { + 'edges': [ + { + 'cursor': 'MQ==', + 'node': { + 'extra': '{"x": 1}', + 'firstName': 'Winston', + 'id': 'QXV0aG9yOjE=', + 'lastName': 'Wolfe', + 'openidUid': 'TheWolf' + } + }, + { + 'cursor': 'Mg==', + 'node': { + 'extra': None, + 'firstName': 'Captain', + 'id': 'QXV0aG9yOjM=', + 'lastName': 'Obvious', + 'openidUid': 'ccc' + } + }, + { + 'cursor': 'Mw==', + 'node': { + 'extra': None, + 'firstName': 'Shaun', + 'id': 'QXV0aG9yOjQ=', + 'lastName': 'Sheep', + 'openidUid': 'ddd' + } + } + ], + 'totalCount': 3 + } + } +} diff --git a/openlobby/core/tests/test_schema.py b/openlobby/core/tests/test_schema.py index e79e87b009ee8ed93a61e4f8685a8ef1533a0153..a3060b7c0a47a1e0a8a7f1284b80abe5b7b3e8a4 100644 --- a/openlobby/core/tests/test_schema.py +++ b/openlobby/core/tests/test_schema.py @@ -16,7 +16,7 @@ def test_login_shortcuts(client, snapshot): } } """}) - snapshot.assert_match(res.content) + snapshot.assert_match(res.json()) @pytest.mark.django_db @@ -30,7 +30,7 @@ def test_login_shortcuts__none(client, snapshot): } } """}) - snapshot.assert_match(res.content) + snapshot.assert_match(res.json()) @pytest.mark.django_db @@ -46,7 +46,7 @@ def test_node__login_shortcut(client, snapshot): }} }} """.format(id=to_global_id('LoginShortcut', 10))}) - snapshot.assert_match(res.content) + snapshot.assert_match(res.json()) @pytest.mark.django_db @@ -72,7 +72,7 @@ def test_node__author(client, snapshot): }} }} """.format(id=to_global_id('Author', 5))}) - snapshot.assert_match(res.content) + snapshot.assert_match(res.json()) @pytest.mark.django_db @@ -87,35 +87,39 @@ def test_node__author__only_if_is_author(client, snapshot): }} }} """.format(id=to_global_id('Author', 7))}) - snapshot.assert_match(res.content) + snapshot.assert_match(res.json()) @pytest.mark.django_db -def test_authors(client, snapshot): - User.objects.create( - id=5, - username='a', - is_author=True, - openid_uid='TheWolf', - first_name='Winston', - last_name='Wolfe', - extra={'x': 1}, - ) - User.objects.create(id=7, is_author=False, username='b') - res = client.post('/graphql', {'query': """ - query { - authors { - totalCount - edges { - node { - id - firstName - lastName - openidUid - extra +class TestAuthors: + + @pytest.fixture(autouse=True) + def setup(self): + User.objects.create(id=1, is_author=True, username='a', openid_uid='TheWolf', + 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', + first_name='Captain', last_name='Obvious') + User.objects.create(id=4, is_author=True, username='d', openid_uid='ddd', + 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 + } } } } - } - """}) - snapshot.assert_match(res.content) + """}) + snapshot.assert_match(res.json())