def test_inherited_unique(self): title = 'Boss' Book.objects.create(title=title, author=self.writer, special_id=1) form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'special_id': u'1', 'isbn': '12345'}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors['special_id'], [u'Book with this Special id already exists.'])
def test_inherited_unique(self): title = "Boss" Book.objects.create(title=title, author=self.writer, special_id=1) form = DerivedBookForm({"title": "Other", "author": self.writer.pk, "special_id": u"1", "isbn": "12345"}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors["special_id"], [u"Book with this Special id already exists."])
def test_abstract_inherited_unique_together(self): title = 'Boss' isbn = '12345' dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn) form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'isbn': '9876', 'suffix1': u'0', 'suffix2': u'0'}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors['__all__'], [u'Derived book with this Suffix1 and Suffix2 already exists.'])
def test_abstract_inherited_unique(self): title = 'Boss' isbn = '12345' dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn) form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'isbn': isbn}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors['isbn'], [u'Derived book with this Isbn already exists.'])
def test_abstract_inherited_unique(self): title = "Boss" isbn = "12345" dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn) form = DerivedBookForm({"title": "Other", "author": self.writer.pk, "isbn": isbn}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors["isbn"], [u"Derived book with this Isbn already exists."])
def test_abstract_inherited_unique_together(self): title = "Boss" isbn = "12345" dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn) form = DerivedBookForm( {"title": "Other", "author": self.writer.pk, "isbn": "9876", "suffix1": u"0", "suffix2": u"0"} ) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors["__all__"], [u"Derived book with this Suffix1 and Suffix2 already exists."])
def test_inherited_unique_together(self): title = 'Boss' form = BookForm({'title': title, 'author': self.writer.pk}) self.assertTrue(form.is_valid()) form.save() form = DerivedBookForm({'title': title, 'author': self.writer.pk, 'isbn': '12345'}) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertEqual(form.errors['__all__'], [u'Book with this Title and Author already exists.'])