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

Test util for stripping random values before snapshotting.

parent 932fa650
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,8 @@ snapshots['test_full_report 1'] = { ...@@ -32,7 +32,8 @@ snapshots['test_full_report 1'] = {
'extra': '{"movies": 1}', 'extra': '{"movies": 1}',
'firstName': 'Winston', 'firstName': 'Winston',
'id': 'QXV0aG9yOjE=', 'id': 'QXV0aG9yOjE=',
'lastName': 'Wolfe' 'lastName': 'Wolfe',
'totalReports': 1
}, },
'body': 'I visited Tesla factory and talked with Elon Musk.', 'body': 'I visited Tesla factory and talked with Elon Musk.',
'date': '2018-01-01 00:00:00+00:00', 'date': '2018-01-01 00:00:00+00:00',
...@@ -57,7 +58,8 @@ snapshots['test_is_draft 1'] = { ...@@ -57,7 +58,8 @@ snapshots['test_is_draft 1'] = {
'extra': '{"movies": 1}', 'extra': '{"movies": 1}',
'firstName': 'Winston', 'firstName': 'Winston',
'id': 'QXV0aG9yOjE=', 'id': 'QXV0aG9yOjE=',
'lastName': 'Wolfe' 'lastName': 'Wolfe',
'totalReports': 0
}, },
'body': 'Niel deGrasse Tyson just visited me...', 'body': 'Niel deGrasse Tyson just visited me...',
'date': '2018-01-03 00:00:00+00:00', 'date': '2018-01-03 00:00:00+00:00',
......
...@@ -5,7 +5,7 @@ import re ...@@ -5,7 +5,7 @@ import re
from openlobby.core.models import Report from openlobby.core.models import Report
from ..dummy import prepare_author from ..dummy import prepare_author
from ..utils import call_api 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')]
...@@ -54,6 +54,7 @@ def test_full_report(client, snapshot): ...@@ -54,6 +54,7 @@ def test_full_report(client, snapshot):
id id
firstName firstName
lastName lastName
totalReports
extra extra
} }
} }
...@@ -81,12 +82,10 @@ def test_full_report(client, snapshot): ...@@ -81,12 +82,10 @@ def test_full_report(client, snapshot):
# published date is set on save, changing between test runs, so we strip it # published date is set on save, changing between test runs, so we strip it
# from snapshot # from snapshot
published = response['data']['createReport']['report']['published'] published = strip_value(response, 'data', 'createReport', 'report', 'published')
response['data']['createReport']['report']['published'] = '__STRIPPED__'
# strip random ID from snapshot and check it # strip random ID from snapshot and check it
id = response['data']['createReport']['report']['id'] id = strip_value(response, 'data', 'createReport', 'report', 'id')
response['data']['createReport']['report']['id'] = '__STRIPPED__'
assert re.match(r'\w+', id) assert re.match(r'\w+', id)
snapshot.assert_match(response) snapshot.assert_match(response)
...@@ -155,6 +154,7 @@ def test_is_draft(client, snapshot): ...@@ -155,6 +154,7 @@ def test_is_draft(client, snapshot):
id id
firstName firstName
lastName lastName
totalReports
extra extra
} }
} }
...@@ -183,12 +183,10 @@ def test_is_draft(client, snapshot): ...@@ -183,12 +183,10 @@ def test_is_draft(client, snapshot):
# published date is set on save, changing between test runs, so we strip it # published date is set on save, changing between test runs, so we strip it
# from snapshot # from snapshot
published = response['data']['createReport']['report']['published'] published = strip_value(response, 'data', 'createReport', 'report', 'published')
response['data']['createReport']['report']['published'] = '__STRIPPED__'
# strip random ID from snapshot and check it # strip random ID from snapshot and check it
id = response['data']['createReport']['report']['id'] id = strip_value(response, 'data', 'createReport', 'report', 'id')
response['data']['createReport']['report']['id'] = '__STRIPPED__'
assert re.match(r'\w+', id) assert re.match(r'\w+', id)
snapshot.assert_match(response) snapshot.assert_match(response)
......
...@@ -13,3 +13,13 @@ def call_api(client, query, input=None, username=None): ...@@ -13,3 +13,13 @@ def call_api(client, query, input=None, username=None):
res = client.post('/graphql', {'query': query, 'variables': variables}, res = client.post('/graphql', {'query': query, 'variables': variables},
HTTP_AUTHORIZATION=auth_header) HTTP_AUTHORIZATION=auth_header)
return res.json() return res.json()
def strip_value(data, *path):
element = path[0]
value = data.get(element)
if len(path) == 1:
data[element] = '__STRIPPED__'
return value
else:
return strip_value(value, *path[1:])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment