From bfcdcf2fa2bb2eabfaff7cf0b540853ff79d3eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Thu, 1 Feb 2018 01:14:29 +0100 Subject: [PATCH] Get authors with reports. --- openlobby/core/api/types.py | 8 ++--- tests/schema/snapshots/snap_test_authors.py | 36 +++++++++++++++++++ tests/schema/test_authors.py | 38 ++++++++++++++++++++- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/openlobby/core/api/types.py b/openlobby/core/api/types.py index a077f03..217902d 100644 --- a/openlobby/core/api/types.py +++ b/openlobby/core/api/types.py @@ -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): diff --git a/tests/schema/snapshots/snap_test_authors.py b/tests/schema/snapshots/snap_test_authors.py index 897784a..6a8de11 100644 --- a/tests/schema/snapshots/snap_test_authors.py +++ b/tests/schema/snapshots/snap_test_authors.py @@ -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 + } + } + } + ] + } + } +} diff --git a/tests/schema/test_authors.py b/tests/schema/test_authors.py index f8c03f9..614f82d 100644 --- a/tests/schema/test_authors.py +++ b/tests/schema/test_authors.py @@ -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()) -- GitLab