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

Test get Report from Node interface.

parent 22617169
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ class SearchReportsConnection(relay.Connection): ...@@ -23,7 +23,7 @@ class SearchReportsConnection(relay.Connection):
node = types.Report node = types.Report
def get_authors(ids): def _get_authors_cache(ids):
users = User.objects.filter(id__in=ids) users = User.objects.filter(id__in=ids)
return {u.id: types.User.from_db(u) for u in users} return {u.id: types.User.from_db(u) for u in users}
...@@ -78,7 +78,7 @@ class Query: ...@@ -78,7 +78,7 @@ class Query:
edges = [] edges = []
if len(response) > 0: if len(response) > 0:
authors = get_authors(ids=[r.author_id for r in response]) authors = _get_authors_cache(ids=[r.author_id for r in response])
for i, report in enumerate(response): for i, report in enumerate(response):
cursor = paginator.get_edge_cursor(i + 1) cursor = paginator.get_edge_cursor(i + 1)
node = types.Report.from_es(report, author=authors[report.author_id]) node = types.Report.from_es(report, author=authors[report.author_id])
......
...@@ -50,7 +50,7 @@ class Report(graphene.ObjectType): ...@@ -50,7 +50,7 @@ class Report(graphene.ObjectType):
@classmethod @classmethod
def get_node(cls, info, id): def get_node(cls, info, id):
try: try:
report = ReportDoc.get(id, using=info.context['es'], index=info.context['index']) report = ReportDoc.get(id)
except NotFoundError: except NotFoundError:
return None return None
......
...@@ -3,6 +3,16 @@ import arrow ...@@ -3,6 +3,16 @@ import arrow
from openlobby.core.models import Report, User from openlobby.core.models import Report, User
authors = [
{
'id': 1,
'username': 'Wolf',
'openid_uid': 'Wolf',
'first_name': 'Winston',
'last_name': 'Wolfe',
},
]
reports = [ reports = [
{ {
'id': 1, 'id': 1,
...@@ -42,7 +52,11 @@ reports = [ ...@@ -42,7 +52,11 @@ reports = [
def prepare_reports(): def prepare_reports():
author = User.objects.create(id=1, username='Wolf', openid_uid='Wolf', author = User.objects.create(**authors[0])
first_name='Winston', last_name='Wolfe')
for report in reports: for report in reports:
Report.objects.create(author=author, **report) Report.objects.create(author=author, **report)
def prepare_report():
author = User.objects.create(**authors[0])
Report.objects.create(author=author, **reports[0])
...@@ -33,3 +33,26 @@ snapshots['test_author__returns_only_if_is_author 1'] = { ...@@ -33,3 +33,26 @@ snapshots['test_author__returns_only_if_is_author 1'] = {
'node': None 'node': None
} }
} }
snapshots['test_report 1'] = {
'data': {
'node': {
'author': {
'extra': None,
'firstName': 'Winston',
'id': 'QXV0aG9yOjE=',
'lastName': 'Wolfe'
},
'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'
}
}
}
...@@ -3,8 +3,10 @@ from graphql_relay import to_global_id ...@@ -3,8 +3,10 @@ from graphql_relay import to_global_id
from openlobby.core.models import OpenIdClient, User from openlobby.core.models import OpenIdClient, User
from ..dummy import prepare_report
pytestmark = pytest.mark.django_db
pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')]
def test_login_shortcut(client, snapshot): def test_login_shortcut(client, snapshot):
...@@ -59,3 +61,32 @@ def test_author__returns_only_if_is_author(client, snapshot): ...@@ -59,3 +61,32 @@ def test_author__returns_only_if_is_author(client, snapshot):
}} }}
""".format(id=to_global_id('Author', 7))}) """.format(id=to_global_id('Author', 7))})
snapshot.assert_match(res.json()) snapshot.assert_match(res.json())
def test_report(client, snapshot):
prepare_report()
res = client.post('/graphql', {'query': """
query {{
node (id:"{id}") {{
... on Report {{
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
extra
author {{
id
firstName
lastName
extra
}}
}}
}}
}}
""".format(id=to_global_id('Report', 1))})
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