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

List of Report drafts in schema.

parent b80f9a71
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ from ..models import OpenIdClient ...@@ -7,7 +7,7 @@ from ..models import OpenIdClient
from .paginator import Paginator from .paginator import Paginator
from .sanitizers import extract_text from .sanitizers import extract_text
from .. import search from .. import search
from ..models import User from ..models import User, Report
class AuthorsConnection(relay.Connection): class AuthorsConnection(relay.Connection):
...@@ -50,6 +50,10 @@ class Query: ...@@ -50,6 +50,10 @@ class Query:
types.LoginShortcut, types.LoginShortcut,
description='Shortcuts for login. Use with LoginByShortcut mutation.', description='Shortcuts for login. Use with LoginByShortcut mutation.',
) )
report_drafts = graphene.List(
types.Report,
description='Saved drafts of reports for Viewer.',
)
def resolve_authors(self, info, **kwargs): def resolve_authors(self, info, **kwargs):
paginator = Paginator(**kwargs) paginator = Paginator(**kwargs)
...@@ -100,3 +104,10 @@ class Query: ...@@ -100,3 +104,10 @@ class Query:
def resolve_login_shortcuts(self, info, **kwargs): def resolve_login_shortcuts(self, info, **kwargs):
clients = OpenIdClient.objects.filter(is_shortcut=True).order_by('name') clients = OpenIdClient.objects.filter(is_shortcut=True).order_by('name')
return [types.LoginShortcut.from_db(c) for c in clients] return [types.LoginShortcut.from_db(c) for c in clients]
def resolve_report_drafts(self, info, **kwargs):
if info.context.user.is_authenticated:
drafts = Report.objects.filter(author=info.context.user, is_draft=True)
return [types.Report.from_db(d) for d in drafts]
else:
return []
...@@ -75,14 +75,27 @@ reports = [ ...@@ -75,14 +75,27 @@ reports = [
'other_participants': '', 'other_participants': '',
'is_draft': True, 'is_draft': True,
}, },
{
'id': 5,
'date': arrow.get(2018, 1, 12).datetime,
'published': arrow.get(2018, 1, 13).datetime,
'title': 'The Hobbit',
'body': 'Work in progress...',
'received_benefit': '',
'provided_benefit': '',
'our_participants': '',
'other_participants': '',
'is_draft': True,
},
] ]
def prepare_reports(): def prepare_reports():
author1 = User.objects.create(**authors[0]) author1 = User.objects.create(**authors[0])
author2 = User.objects.create(**authors[1]) author2 = User.objects.create(**authors[1])
author3 = User.objects.create(**authors[2])
Report.objects.create(author=author1, **reports[0]) Report.objects.create(author=author1, **reports[0])
Report.objects.create(author=author2, **reports[1]) Report.objects.create(author=author2, **reports[1])
Report.objects.create(author=author1, **reports[2]) Report.objects.create(author=author1, **reports[2])
Report.objects.create(author=author1, **reports[3]) Report.objects.create(author=author1, **reports[3])
User.objects.create(**authors[2]) Report.objects.create(author=author3, **reports[4])
# -*- coding: utf-8 -*-
# snapshottest: v1 - https://goo.gl/zC4yUc
from __future__ import unicode_literals
from snapshottest import Snapshot
snapshots = Snapshot()
snapshots['test_unauthenticated 1'] = {
'data': {
'reportDrafts': [
]
}
}
snapshots['test_authenticated 1'] = {
'data': {
'reportDrafts': [
{
'body': 'Not finished yet.',
'date': '2018-01-09 00:00:00+00:00',
'id': 'UmVwb3J0OjQ=',
'otherParticipants': '',
'ourParticipants': '',
'providedBenefit': '',
'published': '2018-01-11 00:00:00+00:00',
'receivedBenefit': '',
'title': 'The Silmarillion'
}
]
}
}
import pytest
from openlobby.core.auth import create_access_token
from ..dummy import prepare_reports
pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')]
def test_unauthenticated(client, snapshot):
prepare_reports()
res = client.post('/graphql', {'query': """
query {
reportDrafts {
id
}
}
"""})
snapshot.assert_match(res.json())
def test_authenticated(client, snapshot):
prepare_reports()
token = create_access_token('Wolf')
auth_header = 'Bearer {}'.format(token)
res = client.post('/graphql', {'query': """
query {
reportDrafts {
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
}
}
"""}, HTTP_AUTHORIZATION=auth_header)
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