Removed try/fail antipattern from model_options tests.
This commit is contained in:
parent
bbe136e1a2
commit
7fec264e46
|
@ -5,42 +5,25 @@ from .models.default_related_name import Author, Book, Editor
|
||||||
|
|
||||||
class DefaultRelatedNameTests(TestCase):
|
class DefaultRelatedNameTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
@classmethod
|
||||||
self.author = Author.objects.create(first_name="Dave", last_name="Loper")
|
def setUpTestData(cls):
|
||||||
self.editor = Editor.objects.create(name="Test Editions",
|
cls.author = Author.objects.create(first_name='Dave', last_name='Loper')
|
||||||
bestselling_author=self.author)
|
cls.editor = Editor.objects.create(name='Test Editions', bestselling_author=cls.author)
|
||||||
self.book = Book.objects.create(title="Test Book", editor=self.editor)
|
cls.book = Book.objects.create(title='Test Book', editor=cls.editor)
|
||||||
self.book.authors.add(self.author)
|
cls.book.authors.add(cls.author)
|
||||||
self.book.save()
|
|
||||||
|
|
||||||
def test_no_default_related_name(self):
|
def test_no_default_related_name(self):
|
||||||
try:
|
self.assertEqual(list(self.author.editor_set.all()), [self.editor])
|
||||||
self.author.editor_set
|
|
||||||
except AttributeError:
|
|
||||||
self.fail("Author should have an editor_set relation.")
|
|
||||||
|
|
||||||
def test_default_related_name(self):
|
def test_default_related_name(self):
|
||||||
try:
|
self.assertEqual(list(self.author.books.all()), [self.book])
|
||||||
self.author.books
|
|
||||||
except AttributeError:
|
|
||||||
self.fail("Author should have a books relation.")
|
|
||||||
|
|
||||||
def test_related_name_overrides_default_related_name(self):
|
def test_related_name_overrides_default_related_name(self):
|
||||||
try:
|
self.assertEqual(list(self.editor.edited_books.all()), [self.book])
|
||||||
self.editor.edited_books
|
|
||||||
except AttributeError:
|
|
||||||
self.fail("Editor should have a edited_books relation.")
|
|
||||||
|
|
||||||
def test_inheritance(self):
|
def test_inheritance(self):
|
||||||
try:
|
# model_options is the name of the application for this test.
|
||||||
# Here model_options corresponds to the name of the application used
|
self.assertEqual(list(self.book.model_options_bookstores.all()), [])
|
||||||
# in this test
|
|
||||||
self.book.model_options_bookstores
|
|
||||||
except AttributeError:
|
|
||||||
self.fail("Book should have a model_options_bookstores relation.")
|
|
||||||
|
|
||||||
def test_inheritance_with_overridden_default_related_name(self):
|
def test_inheritance_with_overridden_default_related_name(self):
|
||||||
try:
|
self.assertEqual(list(self.book.editor_stores.all()), [])
|
||||||
self.book.editor_stores
|
|
||||||
except AttributeError:
|
|
||||||
self.fail("Book should have a editor_stores relation.")
|
|
||||||
|
|
Loading…
Reference in New Issue