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

Refactoring of create report tests.

parent 87e60ee0
No related branches found
No related tags found
No related merge requests found
...@@ -168,6 +168,9 @@ class UpdateReport(relay.ClientIDMutation): ...@@ -168,6 +168,9 @@ class UpdateReport(relay.ClientIDMutation):
if is_draft and not report.is_draft: if is_draft and not report.is_draft:
raise Exception('You cannot update published Report with draft.') raise Exception('You cannot update published Report with draft.')
# TODO updating published report older than like a hour should create
# new revision in history of report
report.published = arrow.utcnow().datetime report.published = arrow.utcnow().datetime
report.date = input.get('date') report.date = input.get('date')
report.title = strip_all_tags(input.get('title', '')) report.title = strip_all_tags(input.get('title', ''))
......
...@@ -15,7 +15,7 @@ snapshots['test_unauthorized 1'] = { ...@@ -15,7 +15,7 @@ snapshots['test_unauthorized 1'] = {
{ {
'locations': [ 'locations': [
{ {
'column': 9, 'column': 5,
'line': 3 'line': 3
} }
], ],
......
...@@ -11,21 +11,39 @@ from ..utils import call_api, strip_value ...@@ -11,21 +11,39 @@ from ..utils import call_api, strip_value
pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')] pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')]
query = """
mutation createReport ($input: CreateReportInput!) {
createReport (input: $input) {
report {
id
date
published
title
body
receivedBenefit
providedBenefit
ourParticipants
otherParticipants
extra
author {
id
firstName
lastName
totalReports
extra
}
}
}
}
"""
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def setup(): def setup():
prepare_author() prepare_author()
def test_unauthorized(client, snapshot): def test_unauthorized(client, snapshot):
query = """
mutation createReport ($input: CreateReportInput!) {
createReport (input: $input) {
report {
id
}
}
}
"""
input = { input = {
'title': 'Short Story', 'title': 'Short Story',
'body': 'I told you!', 'body': 'I told you!',
...@@ -36,31 +54,6 @@ def test_unauthorized(client, snapshot): ...@@ -36,31 +54,6 @@ def test_unauthorized(client, snapshot):
def test_full_report(client, snapshot): def test_full_report(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
totalReports
extra
}
}
}
}
"""
date = arrow.get(2018, 1, 1) date = arrow.get(2018, 1, 1)
title = 'Free Tesla' title = 'Free Tesla'
body = 'I visited Tesla factory and talked with Elon Musk.' body = 'I visited Tesla factory and talked with Elon Musk.'
...@@ -80,11 +73,8 @@ def test_full_report(client, snapshot): ...@@ -80,11 +73,8 @@ def test_full_report(client, snapshot):
response = call_api(client, query, input, 'wolf') response = call_api(client, query, input, 'wolf')
# published date is set on save, changing between test runs, so we strip it
# from snapshot
published = strip_value(response, 'data', 'createReport', 'report', 'published') published = strip_value(response, 'data', 'createReport', 'report', 'published')
# strip random ID from snapshot and check it
id = strip_value(response, 'data', 'createReport', 'report', 'id') id = strip_value(response, 'data', 'createReport', 'report', 'id')
assert re.match(r'\w+', id) assert re.match(r'\w+', id)
...@@ -105,15 +95,6 @@ def test_full_report(client, snapshot): ...@@ -105,15 +95,6 @@ def test_full_report(client, snapshot):
def test_input_sanitization(client): def test_input_sanitization(client):
query = """
mutation createReport ($input: CreateReportInput!) {
createReport (input: $input) {
report {
id
}
}
}
"""
input = { input = {
'title': '<s>No</s> tags', 'title': '<s>No</s> tags',
'body': 'some <a href="http://foo">link</a> <br>in body', 'body': 'some <a href="http://foo">link</a> <br>in body',
...@@ -136,31 +117,6 @@ def test_input_sanitization(client): ...@@ -136,31 +117,6 @@ def test_input_sanitization(client):
def test_is_draft(client, snapshot): 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
totalReports
extra
}
}
}
}
"""
date = arrow.get(2018, 1, 3) date = arrow.get(2018, 1, 3)
title = 'Visited by old friend' title = 'Visited by old friend'
body = 'Niel deGrasse Tyson just visited me...' body = 'Niel deGrasse Tyson just visited me...'
...@@ -181,11 +137,8 @@ def test_is_draft(client, snapshot): ...@@ -181,11 +137,8 @@ def test_is_draft(client, snapshot):
response = call_api(client, query, input, 'wolf') response = call_api(client, query, input, 'wolf')
# published date is set on save, changing between test runs, so we strip it
# from snapshot
published = strip_value(response, 'data', 'createReport', 'report', 'published') published = strip_value(response, 'data', 'createReport', 'report', 'published')
# strip random ID from snapshot and check it
id = strip_value(response, 'data', 'createReport', 'report', 'id') id = strip_value(response, 'data', 'createReport', 'report', 'id')
assert re.match(r'\w+', id) assert re.match(r'\w+', id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment