Skip to content

Commit

Permalink
test: test unicode in validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bmihelac committed Nov 21, 2018
1 parent 158b0ee commit f3f00b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 6 additions & 0 deletions tests/core/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import random
import string

from django.core.exceptions import ValidationError
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

Expand All @@ -14,6 +16,10 @@ class Author(models.Model):
def __str__(self):
return self.name

def clean(self):
if self.name == 'A.A.Milne':
raise ValidationError('Ова вриједност је страшна!')


@python_2_unicode_compatible
class Category(models.Model):
Expand Down
14 changes: 3 additions & 11 deletions tests/core/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,12 @@ class Meta:
self.assertIn('birthday', result.invalid_rows[0].field_specific_errors)

def test_import_data_raises_unicode_validation_errors_without_erroring(self):
russian_valueerror_msg = "Ова вриједност је страшна!"

class HarshRussianWidget(widgets.CharWidget):
def clean(self, value, row=None, *args, **kwargs):
raise ValueError(russian_valueerror_msg)

class AuthorResource(resources.ModelResource):

class Meta:
model = Author

@classmethod
def widget_from_django_field(cls, f, default=widgets.Widget):
return HarshRussianWidget
clean_model_instances = True

resource = AuthorResource()
dataset = tablib.Dataset(headers=['id', 'name', 'birthday'])
Expand All @@ -338,8 +330,8 @@ def widget_from_django_field(cls, f, default=widgets.Widget):
self.assertTrue(result.has_validation_errors())
self.assertIs(result.rows[0].import_type, results.RowResult.IMPORT_TYPE_INVALID)
self.assertEqual(
result.invalid_rows[0].field_specific_errors['name'],
[russian_valueerror_msg]
result.invalid_rows[0].non_field_specific_errors,
['Ова вриједност је страшна!']
)

def test_import_data_error_saving_model(self):
Expand Down

0 comments on commit f3f00b2

Please sign in to comment.