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

Split schema tests into multiple files.

parent 41c7aafa
No related branches found
No related tags found
No related merge requests found
...@@ -7,52 +7,7 @@ from snapshottest import Snapshot ...@@ -7,52 +7,7 @@ from snapshottest import Snapshot
snapshots = Snapshot() snapshots = Snapshot()
snapshots['test_login_shortcuts__none 1'] = { snapshots['test_all 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'] = {
'data': { 'data': {
'authors': { 'authors': {
'edges': [ 'edges': [
...@@ -98,7 +53,7 @@ snapshots['TestAuthors.test_all 1'] = { ...@@ -98,7 +53,7 @@ snapshots['TestAuthors.test_all 1'] = {
} }
} }
snapshots['TestAuthors.test_first 1'] = { snapshots['test_first 1'] = {
'data': { 'data': {
'authors': { 'authors': {
'edges': [ 'edges': [
...@@ -126,7 +81,7 @@ snapshots['TestAuthors.test_first 1'] = { ...@@ -126,7 +81,7 @@ snapshots['TestAuthors.test_first 1'] = {
} }
} }
snapshots['TestAuthors.test_first_after 1'] = { snapshots['test_first_after 1'] = {
'data': { 'data': {
'authors': { 'authors': {
'edges': [ 'edges': [
...@@ -148,7 +103,24 @@ snapshots['TestAuthors.test_first_after 1'] = { ...@@ -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': { 'data': {
'authors': { 'authors': {
'edges': [ 'edges': [
...@@ -169,20 +141,3 @@ snapshots['TestAuthors.test_last_before 1'] = { ...@@ -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.'
}
]
}
# -*- 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': [
]
}
}
# -*- 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
}
}
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())
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())
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())
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())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment