Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e0d206

Browse files
committedOct 28, 2021
Migrate to syrupy snapshot testing
1 parent c4337f1 commit 6e0d206

File tree

8 files changed

+817
-789
lines changed

8 files changed

+817
-789
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# name: test_first_level_attribute_error
2+
<class 'dict'> {
3+
'errors': <class 'list'> [
4+
<class 'dict'> {
5+
'code': 'required',
6+
'detail': 'This field is required.',
7+
'source': <class 'dict'> {
8+
'pointer': '/data/attributes/headline',
9+
},
10+
'status': '400',
11+
},
12+
],
13+
}
14+
---
15+
# name: test_first_level_custom_attribute_error
16+
<class 'dict'> {
17+
'errors': <class 'list'> [
18+
<class 'dict'> {
19+
'detail': 'Too short',
20+
'source': <class 'dict'> {
21+
'pointer': '/data/attributes/body-text',
22+
},
23+
'title': 'Too Short title',
24+
},
25+
],
26+
}
27+
---
28+
# name: test_many_third_level_dict_errors
29+
<class 'dict'> {
30+
'errors': <class 'list'> [
31+
<class 'dict'> {
32+
'code': 'required',
33+
'detail': 'This field is required.',
34+
'source': <class 'dict'> {
35+
'pointer': '/data/attributes/comments/0/attachment/data',
36+
},
37+
'status': '400',
38+
},
39+
<class 'dict'> {
40+
'code': 'required',
41+
'detail': 'This field is required.',
42+
'source': <class 'dict'> {
43+
'pointer': '/data/attributes/comments/0/body',
44+
},
45+
'status': '400',
46+
},
47+
],
48+
}
49+
---
50+
# name: test_relationship_errors_has_correct_pointers
51+
<class 'dict'> {
52+
'errors': <class 'list'> [
53+
<class 'dict'> {
54+
'code': 'incorrect_type',
55+
'detail': 'Incorrect type. Expected resource identifier object, received str.',
56+
'source': <class 'dict'> {
57+
'pointer': '/data/relationships/author',
58+
},
59+
'status': '400',
60+
},
61+
],
62+
}
63+
---
64+
# name: test_second_level_array_error
65+
<class 'dict'> {
66+
'errors': <class 'list'> [
67+
<class 'dict'> {
68+
'code': 'required',
69+
'detail': 'This field is required.',
70+
'source': <class 'dict'> {
71+
'pointer': '/data/attributes/comments/0/body',
72+
},
73+
'status': '400',
74+
},
75+
],
76+
}
77+
---
78+
# name: test_second_level_dict_error
79+
<class 'dict'> {
80+
'errors': <class 'list'> [
81+
<class 'dict'> {
82+
'code': 'required',
83+
'detail': 'This field is required.',
84+
'source': <class 'dict'> {
85+
'pointer': '/data/attributes/comment/body',
86+
},
87+
'status': '400',
88+
},
89+
],
90+
}
91+
---
92+
# name: test_third_level_array_error
93+
<class 'dict'> {
94+
'errors': <class 'list'> [
95+
<class 'dict'> {
96+
'code': 'required',
97+
'detail': 'This field is required.',
98+
'source': <class 'dict'> {
99+
'pointer': '/data/attributes/comments/0/attachments/0/data',
100+
},
101+
'status': '400',
102+
},
103+
],
104+
}
105+
---
106+
# name: test_third_level_custom_array_error
107+
<class 'dict'> {
108+
'errors': <class 'list'> [
109+
<class 'dict'> {
110+
'code': 'invalid',
111+
'detail': 'Too short data',
112+
'source': <class 'dict'> {
113+
'pointer': '/data/attributes/comments/0/attachments/0/data',
114+
},
115+
'status': '400',
116+
},
117+
],
118+
}
119+
---
120+
# name: test_third_level_dict_error
121+
<class 'dict'> {
122+
'errors': <class 'list'> [
123+
<class 'dict'> {
124+
'code': 'required',
125+
'detail': 'This field is required.',
126+
'source': <class 'dict'> {
127+
'pointer': '/data/attributes/comments/0/attachment/data',
128+
},
129+
'status': '400',
130+
},
131+
],
132+
}
133+
---

‎example/tests/__snapshots__/test_openapi.ambr

+669
Large diffs are not rendered by default.

‎example/tests/snapshots/__init__.py

Whitespace-only changes.

‎example/tests/snapshots/snap_test_errors.py

-107
This file was deleted.

‎example/tests/snapshots/snap_test_openapi.py

-667
This file was deleted.

‎example/tests/test_errors.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_first_level_attribute_error(client, some_blog, snapshot):
7979
},
8080
}
8181
}
82-
snapshot.assert_match(perform_error_test(client, data))
82+
assert snapshot == perform_error_test(client, data)
8383

8484

8585
def test_first_level_custom_attribute_error(client, some_blog, snapshot):
@@ -94,7 +94,7 @@ def test_first_level_custom_attribute_error(client, some_blog, snapshot):
9494
}
9595
}
9696
with override_settings(JSON_API_FORMAT_FIELD_NAMES="dasherize"):
97-
snapshot.assert_match(perform_error_test(client, data))
97+
assert snapshot == perform_error_test(client, data)
9898

9999

100100
def test_second_level_array_error(client, some_blog, snapshot):
@@ -110,7 +110,7 @@ def test_second_level_array_error(client, some_blog, snapshot):
110110
}
111111
}
112112

113-
snapshot.assert_match(perform_error_test(client, data))
113+
assert snapshot == perform_error_test(client, data)
114114

115115

116116
def test_second_level_dict_error(client, some_blog, snapshot):
@@ -126,7 +126,7 @@ def test_second_level_dict_error(client, some_blog, snapshot):
126126
}
127127
}
128128

129-
snapshot.assert_match(perform_error_test(client, data))
129+
assert snapshot == perform_error_test(client, data)
130130

131131

132132
def test_third_level_array_error(client, some_blog, snapshot):
@@ -142,7 +142,7 @@ def test_third_level_array_error(client, some_blog, snapshot):
142142
}
143143
}
144144

145-
snapshot.assert_match(perform_error_test(client, data))
145+
assert snapshot == perform_error_test(client, data)
146146

147147

148148
def test_third_level_custom_array_error(client, some_blog, snapshot):
@@ -160,7 +160,7 @@ def test_third_level_custom_array_error(client, some_blog, snapshot):
160160
}
161161
}
162162

163-
snapshot.assert_match(perform_error_test(client, data))
163+
assert snapshot == perform_error_test(client, data)
164164

165165

166166
def test_third_level_dict_error(client, some_blog, snapshot):
@@ -176,7 +176,7 @@ def test_third_level_dict_error(client, some_blog, snapshot):
176176
}
177177
}
178178

179-
snapshot.assert_match(perform_error_test(client, data))
179+
assert snapshot == perform_error_test(client, data)
180180

181181

182182
def test_many_third_level_dict_errors(client, some_blog, snapshot):
@@ -192,7 +192,7 @@ def test_many_third_level_dict_errors(client, some_blog, snapshot):
192192
}
193193
}
194194

195-
snapshot.assert_match(perform_error_test(client, data))
195+
assert snapshot == perform_error_test(client, data)
196196

197197

198198
def test_relationship_errors_has_correct_pointers(client, some_blog, snapshot):
@@ -210,4 +210,4 @@ def test_relationship_errors_has_correct_pointers(client, some_blog, snapshot):
210210
}
211211
}
212212

213-
snapshot.assert_match(perform_error_test(client, data))
213+
assert snapshot == perform_error_test(client, data)

‎example/tests/test_openapi.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_path_without_parameters(snapshot):
3333
inspector.view = view
3434

3535
operation = inspector.get_operation(path, method)
36-
snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True))
36+
assert snapshot == json.dumps(operation, indent=2, sort_keys=True)
3737

3838

3939
def test_path_with_id_parameter(snapshot):
@@ -47,7 +47,7 @@ def test_path_with_id_parameter(snapshot):
4747
inspector.view = view
4848

4949
operation = inspector.get_operation(path, method)
50-
snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True))
50+
assert snapshot == json.dumps(operation, indent=2, sort_keys=True)
5151

5252

5353
def test_post_request(snapshot):
@@ -61,7 +61,7 @@ def test_post_request(snapshot):
6161
inspector.view = view
6262

6363
operation = inspector.get_operation(path, method)
64-
snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True))
64+
assert snapshot == json.dumps(operation, indent=2, sort_keys=True)
6565

6666

6767
def test_patch_request(snapshot):
@@ -75,7 +75,7 @@ def test_patch_request(snapshot):
7575
inspector.view = view
7676

7777
operation = inspector.get_operation(path, method)
78-
snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True))
78+
assert snapshot == json.dumps(operation, indent=2, sort_keys=True)
7979

8080

8181
def test_delete_request(snapshot):
@@ -89,7 +89,7 @@ def test_delete_request(snapshot):
8989
inspector.view = view
9090

9191
operation = inspector.get_operation(path, method)
92-
snapshot.assert_match(json.dumps(operation, indent=2, sort_keys=True))
92+
assert snapshot == json.dumps(operation, indent=2, sort_keys=True)
9393

9494

9595
@override_settings(

‎requirements/requirements-testing.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ pytest==6.2.5
55
pytest-cov==3.0.0
66
pytest-django==4.4.0
77
pytest-factoryboy==2.1.0
8-
snapshottest==0.6.0
8+
syrupy==1.4.7

0 commit comments

Comments
 (0)
Please sign in to comment.