Improvements in the tests

This commit is contained in:
Pablo Martín 2013-11-26 20:34:25 +01:00
parent 0e62e07668
commit 6f53e6ac03
2 changed files with 8 additions and 3 deletions

View file

@ -20,7 +20,7 @@ from multiselectfield import MultiSelectField
CATEGORY_CHOICES = (
(1, 'Handbooks and manuals by discipline'),
(2, 'Business books2'),
(2, 'Business books'),
(3, 'Books of literary criticism'),
(4, 'Books about literary theory'),
(5, 'Books about literature')

View file

@ -36,12 +36,12 @@ class MultiSelectTestCase(TestCase):
form.save()
def test_object(self):
book = Book.objects.all()[0]
book = Book.objects.get(id=1)
self.assertEqual(book.get_tags_display(), 'Sex, Work, Happy')
self.assertEqual(book.get_categories_display(), 'Handbooks and manuals by discipline, Books of literary criticism, Books about literature')
def test_validate(self):
book = Book.objects.all()[0]
book = Book.objects.get(id=1)
Book._meta.get_field_by_name('tags')[0].clean(['sex', 'work'], book)
try:
Book._meta.get_field_by_name('tags')[0].clean(['sex1', 'work'], book)
@ -60,3 +60,8 @@ class MultiSelectTestCase(TestCase):
raise AssertionError()
except ValidationError:
pass
def test_serializer(self):
book = Book.objects.get(id=1)
self.assertEqual(Book._meta.get_field_by_name('tags')[0].value_to_string(book), 'sex,work,happy')
self.assertEqual(Book._meta.get_field_by_name('categories')[0].value_to_string(book), '1,3,5')