Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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
  • Loading branch information
sliverc committed Aug 25, 2020
commit ee4d13a15a8ec30a5886c401bb7d27e50626aed2
106 changes: 0 additions & 106 deletions example/tests/__snapshots__/test_errors.ambr

This file was deleted.

Empty file.
121 changes: 121 additions & 0 deletions example/tests/snapshots/snap_test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# -*- coding: utf-8 -*-
# snapshottest: v1 - https://goo.gl/zC4yUc
from __future__ import unicode_literals

from snapshottest import Snapshot


snapshots = Snapshot()

snapshots['test_first_level_attribute_error 1'] = {
'errors': [
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/headline'
},
'status': '400'
}
]
}

snapshots['test_first_level_custom_attribute_error 1'] = {
'errors': [
{
'detail': 'Too short',
'source': {
'pointer': '/data/attributes/body-text'
},
'title': 'Too Short title'
}
]
}

snapshots['test_second_level_array_error 1'] = {
'errors': [
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/comments/0/body'
},
'status': '400'
}
]
}

snapshots['test_second_level_dict_error 1'] = {
'errors': [
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/comment/body'
},
'status': '400'
}
]
}

snapshots['test_third_level_array_error 1'] = {
'errors': [
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/comments/0/attachments/0/data'
},
'status': '400'
}
]
}

snapshots['test_third_level_custom_array_error 1'] = {
'errors': [
{
'code': 'invalid',
'detail': 'Too short data',
'source': {
'pointer': '/data/attributes/comments/0/attachments/0/data'
},
'status': '400'
}
]
}

snapshots['test_third_level_dict_error 1'] = {
'errors': [
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/comments/0/attachment/data'
},
'status': '400'
}
]
}

snapshots['test_many_third_level_dict_errors 1'] = {
'errors': [
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/comments/0/attachment/data'
},
'status': '400'
},
{
'code': 'required',
'detail': 'This field is required.',
'source': {
'pointer': '/data/attributes/comments/0/body'
},
'status': '400'
}
]
}

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'
21 changes: 10 additions & 11 deletions example/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def perform_error_test(client, data):
url = reverse('entries-nested-list')
response = client.post(url, data=data)

errors = response.data
return errors
return response.json()


def test_first_level_attribute_error(client, some_blog, snapshot):
Expand All @@ -83,7 +82,7 @@ def test_first_level_attribute_error(client, some_blog, snapshot):
}
}
}
assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_first_level_custom_attribute_error(client, some_blog, snapshot):
Expand All @@ -98,7 +97,7 @@ def test_first_level_custom_attribute_error(client, some_blog, snapshot):
}
}
with override_settings(JSON_API_FORMAT_FIELD_NAMES='dasherize'):
assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_second_level_array_error(client, some_blog, snapshot):
Expand All @@ -117,7 +116,7 @@ def test_second_level_array_error(client, some_blog, snapshot):
}
}

assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_second_level_dict_error(client, some_blog, snapshot):
Expand All @@ -133,7 +132,7 @@ def test_second_level_dict_error(client, some_blog, snapshot):
}
}

assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_third_level_array_error(client, some_blog, snapshot):
Expand All @@ -157,7 +156,7 @@ def test_third_level_array_error(client, some_blog, snapshot):
}
}

assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_third_level_custom_array_error(client, some_blog, snapshot):
Expand All @@ -182,7 +181,7 @@ def test_third_level_custom_array_error(client, some_blog, snapshot):
}
}

assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_third_level_dict_error(client, some_blog, snapshot):
Expand All @@ -203,7 +202,7 @@ def test_third_level_dict_error(client, some_blog, snapshot):
}
}

assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


def test_many_third_level_dict_errors(client, some_blog, snapshot):
Expand All @@ -223,7 +222,7 @@ def test_many_third_level_dict_errors(client, some_blog, snapshot):
}
}

assert snapshot == perform_error_test(client, data)
snapshot.assert_match(perform_error_test(client, data))


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

assert len(recwarn) == 1
warning = recwarn.pop(DeprecationWarning)
assert snapshot == str(warning.message)
snapshot.assert_match(str(warning.message))
2 changes: 1 addition & 1 deletion requirements/requirements-testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pytest==6.0.1
pytest-cov==2.10.1
pytest-django==3.9.0
pytest-factoryboy==2.0.3
syrupy==0.6.1
snapshottest==0.5.1
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ universal = 1
ignore = F405,W504
max-line-length = 100
exclude =
snapshots
build/lib,
docs/conf.py,
migrations,
Expand Down