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

Get authors with reports.

parent ab603468
No related branches found
No related tags found
No related merge requests found
......@@ -99,8 +99,7 @@ class Author(graphene.ObjectType):
last_name = graphene.String()
openid_uid = graphene.String()
extra = JSONString()
# TODO
# reports = relay.ConnectionField(ReportConnection)
reports = relay.ConnectionField(ReportConnection)
class Meta:
interfaces = (relay.Node, )
......@@ -122,11 +121,9 @@ class Author(graphene.ObjectType):
except models.User.DoesNotExist:
return None
# TODO
"""
def resolve_reports(self, info, **kwargs):
paginator = Paginator(**kwargs)
response = search.reports_by_author(self.id, paginator, **info.context)
response = search.reports_by_author(self.id, paginator)
total = response.hits.total
page_info = paginator.get_page_info(total)
......@@ -137,7 +134,6 @@ class Author(graphene.ObjectType):
edges.append(ReportConnection.Edge(node=node, cursor=cursor))
return ReportConnection(page_info=page_info, edges=edges, total_count=total)
"""
class LoginShortcut(graphene.ObjectType):
......
......@@ -141,3 +141,39 @@ snapshots['test_last_before 1'] = {
}
}
}
snapshots['test_with_reports 1'] = {
'data': {
'authors': {
'edges': [
{
'node': {
'firstName': 'Winston',
'id': 'QXV0aG9yOjE=',
'lastName': 'Wolfe',
'reports': {
'edges': [
{
'cursor': 'MQ==',
'node': {
'body': 'Long story short: we got the Ring!',
'date': '2018-01-01 00:00:00+00:00',
'extra': None,
'id': 'UmVwb3J0OjE=',
'otherParticipants': 'Saruman',
'ourParticipants': 'Frodo, Gandalf',
'providedBenefit': '',
'published': '2018-01-02 00:00:00+00:00',
'receivedBenefit': 'The Ring',
'title': 'The Fellowship of the Ring'
}
}
],
'totalCount': 1
}
}
}
]
}
}
}
......@@ -2,7 +2,7 @@ import pytest
from openlobby.core.models import User
from ..dummy import prepare_authors
from ..dummy import prepare_authors, prepare_report
pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')]
......@@ -131,3 +131,39 @@ def test_last_before(client, snapshot):
}
"""})
snapshot.assert_match(res.json())
def test_with_reports(client, snapshot):
prepare_report()
res = client.post('/graphql', {'query': """
query {
authors {
edges {
node {
id
firstName
lastName
reports {
totalCount
edges {
cursor
node {
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
extra
}
}
}
}
}
}
}
"""})
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