From 07feee96bd9a34639b37331705630cf8b0eab6c1 Mon Sep 17 00:00:00 2001 From: koenigsley Date: Fri, 20 Oct 2023 20:08:05 +0300 Subject: [PATCH 1/2] test: add list detail and tuple detail tests --- tests/views_test.py | 61 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/tests/views_test.py b/tests/views_test.py index ab0435d..b99e7cf 100644 --- a/tests/views_test.py +++ b/tests/views_test.py @@ -11,35 +11,70 @@ class ViewsTestCase(unittest.TestCase): def test_exception_handler_returns_correct_response_if_detail_is_str(self): - exc = APIException('error') + exc = APIException('You are not authenticated') context = {} response = exception_handler(exc, context) expected = { 'errors': [ { 'field': None, - 'messages': ['error'], - } - ] + 'messages': ['You are not authenticated'], + }, + ], } self.assertEqual(expected, response.data) - def test_exception_handler_returns_correct_response_if_detail_is_detail_dict(self): - exc = APIException({'detail': 'error'}) + def test_exception_handler_returns_correct_response_if_detail_is_dict_which_contains_detail_key(self): + exc = APIException({'detail': 'Permisssion denied'}) context = {} response = exception_handler(exc, context) expected = { 'errors': [ { 'field': None, - 'messages': ['error'], - } - ] + 'messages': ['Permisssion denied'], + }, + ], } self.assertEqual(expected, response.data) - def test_exception_handler_returns_correct_response_if_detail_is_dict_with_list(self): - exc = APIException({'name': ['This field is required', 'This field can not be null']}) + def test_exception_handler_returns_correct_response_if_detail_is_list(self): + exc = APIException(['Invalid name', 'Invalid age']) + context = {} + response = exception_handler(exc, context) + expected = { + 'errors': [ + { + 'field': None, + 'messages': ['Invalid name', 'Invalid age'], + }, + ], + } + self.assertEqual(expected, response.data) + + def test_exception_handler_returns_correct_response_if_detail_is_tuple(self): + exc = APIException(('Invalid name', 'Invalid age')) + context = {} + response = exception_handler(exc, context) + expected = { + 'errors': [ + { + 'field': None, + 'messages': ['Invalid name', 'Invalid age'], + }, + ], + } + self.assertEqual(expected, response.data) + + def test_exception_handler_returns_correct_response_if_detail_is_dict_which_contains_list_value(self): + exc = APIException( + { + 'name': [ + 'This field is required', + 'This field can not be null', + ], + }, + ) context = {} response = exception_handler(exc, context) expected = { @@ -47,7 +82,7 @@ def test_exception_handler_returns_correct_response_if_detail_is_dict_with_list( { 'field': 'name', 'messages': ['This field is required', 'This field can not be null'], - } - ] + }, + ], } self.assertEqual(expected, response.data) From 1376569dbc0bc1b93048e4560cd21a7e628101a0 Mon Sep 17 00:00:00 2001 From: koenigsley Date: Fri, 20 Oct 2023 20:09:55 +0300 Subject: [PATCH 2/2] build: bump package version from 0.0.5 to 0.0.6 --- rest_framework_verbose_errors/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework_verbose_errors/__init__.py b/rest_framework_verbose_errors/__init__.py index c8d467a..db9c098 100644 --- a/rest_framework_verbose_errors/__init__.py +++ b/rest_framework_verbose_errors/__init__.py @@ -1,4 +1,4 @@ -VERSION = (0, 0, 5) +VERSION = (0, 0, 6) __version__ = '.'.join(str(number) for number in VERSION)