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

Authors schema tests.

parent 18447ab4
No related branches found
No related tags found
No related merge requests found
...@@ -33,10 +33,13 @@ class Query: ...@@ -33,10 +33,13 @@ class Query:
' Default: false') ' Default: false')
node = relay.Node.Field() node = relay.Node.Field()
authors = relay.ConnectionField(AuthorsConnection) authors = relay.ConnectionField(
AuthorsConnection,
description='List of Authors. Returns first 10 nodes if pagination is not specified.',
)
search_reports = relay.ConnectionField( search_reports = relay.ConnectionField(
SearchReportsConnection, SearchReportsConnection,
description='Fulltext search in Reports.', description='Fulltext search in Reports. Returns first 10 nodes if pagination is not specified.',
query=graphene.String(description='Text to search for.'), query=graphene.String(description='Text to search for.'),
highlight=graphene.Boolean(default_value=False, description=highlight_help), highlight=graphene.Boolean(default_value=False, description=highlight_help),
) )
......
...@@ -63,7 +63,7 @@ snapshots['TestAuthors.test_all 1'] = { ...@@ -63,7 +63,7 @@ snapshots['TestAuthors.test_all 1'] = {
'firstName': 'Winston', 'firstName': 'Winston',
'id': 'QXV0aG9yOjE=', 'id': 'QXV0aG9yOjE=',
'lastName': 'Wolfe', 'lastName': 'Wolfe',
'openidUid': 'TheWolf' 'openidUid': 'first'
} }
}, },
{ {
...@@ -73,7 +73,7 @@ snapshots['TestAuthors.test_all 1'] = { ...@@ -73,7 +73,7 @@ snapshots['TestAuthors.test_all 1'] = {
'firstName': 'Captain', 'firstName': 'Captain',
'id': 'QXV0aG9yOjM=', 'id': 'QXV0aG9yOjM=',
'lastName': 'Obvious', 'lastName': 'Obvious',
'openidUid': 'ccc' 'openidUid': 'second'
} }
}, },
{ {
...@@ -83,11 +83,106 @@ snapshots['TestAuthors.test_all 1'] = { ...@@ -83,11 +83,106 @@ snapshots['TestAuthors.test_all 1'] = {
'firstName': 'Shaun', 'firstName': 'Shaun',
'id': 'QXV0aG9yOjQ=', 'id': 'QXV0aG9yOjQ=',
'lastName': 'Sheep', 'lastName': 'Sheep',
'openidUid': 'ddd' 'openidUid': 'third'
}
}
],
'pageInfo': {
'endCursor': 'Mw==',
'hasNextPage': False,
'hasPreviousPage': False,
'startCursor': 'MQ=='
},
'totalCount': 3
}
}
}
snapshots['TestAuthors.test_first 1'] = {
'data': {
'authors': {
'edges': [
{
'cursor': 'MQ==',
'node': {
'openidUid': 'first'
}
},
{
'cursor': 'Mg==',
'node': {
'openidUid': 'second'
}
}
],
'pageInfo': {
'endCursor': 'Mg==',
'hasNextPage': True,
'hasPreviousPage': False,
'startCursor': 'MQ=='
},
'totalCount': 3
}
}
}
snapshots['TestAuthors.test_first_after 1'] = {
'data': {
'authors': {
'edges': [
{
'cursor': 'Mg==',
'node': {
'openidUid': 'second'
} }
} }
], ],
'pageInfo': {
'endCursor': 'Mg==',
'hasNextPage': True,
'hasPreviousPage': True,
'startCursor': 'Mg=='
},
'totalCount': 3 'totalCount': 3
} }
} }
} }
snapshots['TestAuthors.test_last_before 1'] = {
'data': {
'authors': {
'edges': [
{
'cursor': 'Mg==',
'node': {
'openidUid': 'second'
}
}
],
'pageInfo': {
'endCursor': 'Mg==',
'hasNextPage': True,
'hasPreviousPage': True,
'startCursor': 'Mg=='
},
'totalCount': 3
}
}
}
snapshots['TestAuthors.test_last 1'] = {
'data': {
'authors': None
},
'errors': [
{
'locations': [
{
'column': 13,
'line': 3
}
],
'message': 'Pagination "last" works only in combination with "before" argument.'
}
]
}
...@@ -95,12 +95,12 @@ class TestAuthors: ...@@ -95,12 +95,12 @@ class TestAuthors:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup(self): def setup(self):
User.objects.create(id=1, is_author=True, username='a', openid_uid='TheWolf', User.objects.create(id=1, is_author=True, username='a', openid_uid='first',
first_name='Winston', last_name='Wolfe', extra={'x': 1}) first_name='Winston', last_name='Wolfe', extra={'x': 1})
User.objects.create(id=2, is_author=False, username='b') User.objects.create(id=2, is_author=False, username='b')
User.objects.create(id=3, is_author=True, username='c', openid_uid='ccc', User.objects.create(id=3, is_author=True, username='c', openid_uid='second',
first_name='Captain', last_name='Obvious') first_name='Captain', last_name='Obvious')
User.objects.create(id=4, is_author=True, username='d', openid_uid='ddd', User.objects.create(id=4, is_author=True, username='d', openid_uid='third',
first_name='Shaun', last_name='Sheep') first_name='Shaun', last_name='Sheep')
yield yield
...@@ -119,6 +119,100 @@ class TestAuthors: ...@@ -119,6 +119,100 @@ class TestAuthors:
extra 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
}
} }
} }
"""}) """})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment