Skip to content

Commit ee4d13a

Browse files
committed
Switch from syrupy to snapshottest to support Python 3.5
Once we drop support for Python 3.5 we might consider moving back to syrupy again
1 parent 0712f9f commit ee4d13a

File tree

6 files changed

+133
-118
lines changed

6 files changed

+133
-118
lines changed

example/tests/__snapshots__/test_errors.ambr

-106
This file was deleted.

example/tests/snapshots/__init__.py

Whitespace-only changes.
+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# -*- coding: utf-8 -*-
2+
# snapshottest: v1 - https://goo.gl/zC4yUc
3+
from __future__ import unicode_literals
4+
5+
from snapshottest import Snapshot
6+
7+
8+
snapshots = Snapshot()
9+
10+
snapshots['test_first_level_attribute_error 1'] = {
11+
'errors': [
12+
{
13+
'code': 'required',
14+
'detail': 'This field is required.',
15+
'source': {
16+
'pointer': '/data/attributes/headline'
17+
},
18+
'status': '400'
19+
}
20+
]
21+
}
22+
23+
snapshots['test_first_level_custom_attribute_error 1'] = {
24+
'errors': [
25+
{
26+
'detail': 'Too short',
27+
'source': {
28+
'pointer': '/data/attributes/body-text'
29+
},
30+
'title': 'Too Short title'
31+
}
32+
]
33+
}
34+
35+
snapshots['test_second_level_array_error 1'] = {
36+
'errors': [
37+
{
38+
'code': 'required',
39+
'detail': 'This field is required.',
40+
'source': {
41+
'pointer': '/data/attributes/comments/0/body'
42+
},
43+
'status': '400'
44+
}
45+
]
46+
}
47+
48+
snapshots['test_second_level_dict_error 1'] = {
49+
'errors': [
50+
{
51+
'code': 'required',
52+
'detail': 'This field is required.',
53+
'source': {
54+
'pointer': '/data/attributes/comment/body'
55+
},
56+
'status': '400'
57+
}
58+
]
59+
}
60+
61+
snapshots['test_third_level_array_error 1'] = {
62+
'errors': [
63+
{
64+
'code': 'required',
65+
'detail': 'This field is required.',
66+
'source': {
67+
'pointer': '/data/attributes/comments/0/attachments/0/data'
68+
},
69+
'status': '400'
70+
}
71+
]
72+
}
73+
74+
snapshots['test_third_level_custom_array_error 1'] = {
75+
'errors': [
76+
{
77+
'code': 'invalid',
78+
'detail': 'Too short data',
79+
'source': {
80+
'pointer': '/data/attributes/comments/0/attachments/0/data'
81+
},
82+
'status': '400'
83+
}
84+
]
85+
}
86+
87+
snapshots['test_third_level_dict_error 1'] = {
88+
'errors': [
89+
{
90+
'code': 'required',
91+
'detail': 'This field is required.',
92+
'source': {
93+
'pointer': '/data/attributes/comments/0/attachment/data'
94+
},
95+
'status': '400'
96+
}
97+
]
98+
}
99+
100+
snapshots['test_many_third_level_dict_errors 1'] = {
101+
'errors': [
102+
{
103+
'code': 'required',
104+
'detail': 'This field is required.',
105+
'source': {
106+
'pointer': '/data/attributes/comments/0/attachment/data'
107+
},
108+
'status': '400'
109+
},
110+
{
111+
'code': 'required',
112+
'detail': 'This field is required.',
113+
'source': {
114+
'pointer': '/data/attributes/comments/0/body'
115+
},
116+
'status': '400'
117+
}
118+
]
119+
}
120+
121+
snapshots['test_deprecation_warning 1'] = 'Rendering nested serializer as relationship is deprecated. Use `ResourceRelatedField` instead if DummyNestedSerializer in serializer example.tests.test_errors.test_deprecation_warning.<locals>.DummySerializer should remain a relationship. Otherwise set JSON_API_SERIALIZE_NESTED_SERIALIZERS_AS_ATTRIBUTE to True to render nested serializer as nested json attribute'

example/tests/test_errors.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def perform_error_test(client, data):
6969
url = reverse('entries-nested-list')
7070
response = client.post(url, data=data)
7171

72-
errors = response.data
73-
return errors
72+
return response.json()
7473

7574

7675
def test_first_level_attribute_error(client, some_blog, snapshot):
@@ -83,7 +82,7 @@ def test_first_level_attribute_error(client, some_blog, snapshot):
8382
}
8483
}
8584
}
86-
assert snapshot == perform_error_test(client, data)
85+
snapshot.assert_match(perform_error_test(client, data))
8786

8887

8988
def test_first_level_custom_attribute_error(client, some_blog, snapshot):
@@ -98,7 +97,7 @@ def test_first_level_custom_attribute_error(client, some_blog, snapshot):
9897
}
9998
}
10099
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
101-
assert snapshot == perform_error_test(client, data)
100+
snapshot.assert_match(perform_error_test(client, data))
102101

103102

104103
def test_second_level_array_error(client, some_blog, snapshot):
@@ -117,7 +116,7 @@ def test_second_level_array_error(client, some_blog, snapshot):
117116
}
118117
}
119118

120-
assert snapshot == perform_error_test(client, data)
119+
snapshot.assert_match(perform_error_test(client, data))
121120

122121

123122
def test_second_level_dict_error(client, some_blog, snapshot):
@@ -133,7 +132,7 @@ def test_second_level_dict_error(client, some_blog, snapshot):
133132
}
134133
}
135134

136-
assert snapshot == perform_error_test(client, data)
135+
snapshot.assert_match(perform_error_test(client, data))
137136

138137

139138
def test_third_level_array_error(client, some_blog, snapshot):
@@ -157,7 +156,7 @@ def test_third_level_array_error(client, some_blog, snapshot):
157156
}
158157
}
159158

160-
assert snapshot == perform_error_test(client, data)
159+
snapshot.assert_match(perform_error_test(client, data))
161160

162161

163162
def test_third_level_custom_array_error(client, some_blog, snapshot):
@@ -182,7 +181,7 @@ def test_third_level_custom_array_error(client, some_blog, snapshot):
182181
}
183182
}
184183

185-
assert snapshot == perform_error_test(client, data)
184+
snapshot.assert_match(perform_error_test(client, data))
186185

187186

188187
def test_third_level_dict_error(client, some_blog, snapshot):
@@ -203,7 +202,7 @@ def test_third_level_dict_error(client, some_blog, snapshot):
203202
}
204203
}
205204

206-
assert snapshot == perform_error_test(client, data)
205+
snapshot.assert_match(perform_error_test(client, data))
207206

208207

209208
def test_many_third_level_dict_errors(client, some_blog, snapshot):
@@ -223,7 +222,7 @@ def test_many_third_level_dict_errors(client, some_blog, snapshot):
223222
}
224223
}
225224

226-
assert snapshot == perform_error_test(client, data)
225+
snapshot.assert_match(perform_error_test(client, data))
227226

228227

229228
@pytest.mark.filterwarnings('default::DeprecationWarning:rest_framework_json_api.serializers')
@@ -238,4 +237,4 @@ class DummySerializer(serializers.Serializer):
238237

239238
assert len(recwarn) == 1
240239
warning = recwarn.pop(DeprecationWarning)
241-
assert snapshot == str(warning.message)
240+
snapshot.assert_match(str(warning.message))

requirements/requirements-testing.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ pytest==6.0.1
55
pytest-cov==2.10.1
66
pytest-django==3.9.0
77
pytest-factoryboy==2.0.3
8-
syrupy==0.6.1
8+
snapshottest==0.5.1

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ universal = 1
88
ignore = F405,W504
99
max-line-length = 100
1010
exclude =
11+
snapshots
1112
build/lib,
1213
docs/conf.py,
1314
migrations,

0 commit comments

Comments
 (0)