From 745e75d10a5147793a95e6696d3a9ac9b9b64bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Thu, 1 Mar 2018 01:02:30 +0100 Subject: [PATCH] Refactoring of create report tests. --- openlobby/core/api/mutations.py | 3 + .../snapshots/snap_test_create_report.py | 2 +- tests/mutations/test_create_report.py | 101 +++++------------- 3 files changed, 31 insertions(+), 75 deletions(-) diff --git a/openlobby/core/api/mutations.py b/openlobby/core/api/mutations.py index e0e1c2b..a0e1012 100644 --- a/openlobby/core/api/mutations.py +++ b/openlobby/core/api/mutations.py @@ -168,6 +168,9 @@ class UpdateReport(relay.ClientIDMutation): if is_draft and not report.is_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.date = input.get('date') report.title = strip_all_tags(input.get('title', '')) diff --git a/tests/mutations/snapshots/snap_test_create_report.py b/tests/mutations/snapshots/snap_test_create_report.py index 3b98ccd..b7abf9d 100644 --- a/tests/mutations/snapshots/snap_test_create_report.py +++ b/tests/mutations/snapshots/snap_test_create_report.py @@ -15,7 +15,7 @@ snapshots['test_unauthorized 1'] = { { 'locations': [ { - 'column': 9, + 'column': 5, 'line': 3 } ], diff --git a/tests/mutations/test_create_report.py b/tests/mutations/test_create_report.py index d09fc27..63086b7 100644 --- a/tests/mutations/test_create_report.py +++ b/tests/mutations/test_create_report.py @@ -11,21 +11,39 @@ from ..utils import call_api, strip_value 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) def setup(): prepare_author() def test_unauthorized(client, snapshot): - query = """ - mutation createReport ($input: CreateReportInput!) { - createReport (input: $input) { - report { - id - } - } - } - """ input = { 'title': 'Short Story', 'body': 'I told you!', @@ -36,31 +54,6 @@ def test_unauthorized(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) title = 'Free Tesla' body = 'I visited Tesla factory and talked with Elon Musk.' @@ -80,11 +73,8 @@ def test_full_report(client, snapshot): 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') - # strip random ID from snapshot and check it id = strip_value(response, 'data', 'createReport', 'report', 'id') assert re.match(r'\w+', id) @@ -105,15 +95,6 @@ def test_full_report(client, snapshot): def test_input_sanitization(client): - query = """ - mutation createReport ($input: CreateReportInput!) { - createReport (input: $input) { - report { - id - } - } - } - """ input = { 'title': '<s>No</s> tags', 'body': 'some <a href="http://foo">link</a> <br>in body', @@ -136,31 +117,6 @@ def test_input_sanitization(client): 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) title = 'Visited by old friend' body = 'Niel deGrasse Tyson just visited me...' @@ -181,11 +137,8 @@ def test_is_draft(client, snapshot): 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') - # strip random ID from snapshot and check it id = strip_value(response, 'data', 'createReport', 'report', 'id') assert re.match(r'\w+', id) -- GitLab