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

CreateReport mutation can create draft.

parent 2212aed1
No related branches found
No related tags found
No related merge requests found
...@@ -108,6 +108,7 @@ class CreateReport(relay.ClientIDMutation): ...@@ -108,6 +108,7 @@ class CreateReport(relay.ClientIDMutation):
our_participants = graphene.String() our_participants = graphene.String()
other_participants = graphene.String() other_participants = graphene.String()
date = DateTime(required=True) date = DateTime(required=True)
is_draft = graphene.Boolean(default_value=False)
report = graphene.Field(types.Report) report = graphene.Field(types.Report)
...@@ -127,6 +128,7 @@ class CreateReport(relay.ClientIDMutation): ...@@ -127,6 +128,7 @@ class CreateReport(relay.ClientIDMutation):
provided_benefit=strip_all_tags(input.get('provided_benefit', '')), provided_benefit=strip_all_tags(input.get('provided_benefit', '')),
our_participants=strip_all_tags(input.get('our_participants', '')), our_participants=strip_all_tags(input.get('our_participants', '')),
other_participants=strip_all_tags(input.get('other_participants', '')), other_participants=strip_all_tags(input.get('other_participants', '')),
is_draft=input.get('is_draft'),
) )
return CreateReport(report=types.Report.from_db(report)) return CreateReport(report=types.Report.from_db(report))
......
...@@ -48,3 +48,28 @@ snapshots['test_full_report 1'] = { ...@@ -48,3 +48,28 @@ snapshots['test_full_report 1'] = {
} }
} }
} }
snapshots['test_is_draft 1'] = {
'data': {
'createReport': {
'report': {
'author': {
'extra': None,
'firstName': 'Winston',
'id': 'QXV0aG9yOjE=',
'lastName': 'Wolfe'
},
'body': 'Niel deGrasse Tyson just visited me...',
'date': '2018-01-03 00:00:00+00:00',
'extra': None,
'id': '__STRIPPED__',
'otherParticipants': 'Neil deGrasse Tyson',
'ourParticipants': 'myself',
'providedBenefit': 'coffee',
'published': '__STRIPPED__',
'receivedBenefit': 'touch of the God',
'title': 'Visited by old friend'
}
}
}
}
...@@ -148,3 +148,74 @@ def test_input_sanitization(client): ...@@ -148,3 +148,74 @@ def test_input_sanitization(client):
assert report.provided_benefit == 'tea' assert report.provided_benefit == 'tea'
assert report.our_participants == 'me, myself' assert report.our_participants == 'me, myself'
assert report.other_participants == 'you!' assert report.other_participants == 'you!'
def test_is_draft(client, snapshot):
query = """
mutation createReport ($input: CreateReportInput!) {
createReport (input: $input) {
report {
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
extra
author {
id
firstName
lastName
extra
}
}
}
}
"""
date = arrow.get(2018, 1, 3)
title = 'Visited by old friend'
body = 'Niel deGrasse Tyson just visited me...'
received_benefit = 'touch of the God'
provided_benefit = 'coffee'
our_participants = 'myself'
other_participants = 'Neil deGrasse Tyson'
input = {
'title': title,
'body': body,
'receivedBenefit': received_benefit,
'providedBenefit': provided_benefit,
'ourParticipants': our_participants,
'otherParticipants': other_participants,
'date': date.isoformat(),
'isDraft': True,
}
response = call_api(client, query, input, 'wolfe')
# published date is set on save, changing between test runs, so we strip it
# from snapshot
published = response['data']['createReport']['report']['published']
response['data']['createReport']['report']['published'] = '__STRIPPED__'
# strip random ID from snapshot and check it
id = response['data']['createReport']['report']['id']
response['data']['createReport']['report']['id'] = '__STRIPPED__'
assert re.match(r'\w+', id)
snapshot.assert_match(response)
report = Report.objects.get()
assert report.author_id == 1
assert report.date == date.datetime
assert report.published == arrow.get(published).datetime
assert report.title == title
assert report.body == body
assert report.received_benefit == received_benefit
assert report.provided_benefit == provided_benefit
assert report.our_participants == our_participants
assert report.other_participants == other_participants
assert report.extra is None
assert report.is_draft is True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment