Skip to content
Snippets Groups Projects
Commit 50471b43 authored by jan.bednarik's avatar jan.bednarik
Browse files

Schema tests refactoring.

parent 5dc9dfeb
Branches
Tags
No related merge requests found
......@@ -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
}
}
}
......@@ -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,26 +87,30 @@ 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')
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
......@@ -118,4 +122,4 @@ def test_authors(client, snapshot):
}
}
"""})
snapshot.assert_match(res.content)
snapshot.assert_match(res.json())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment