diff options
author | Tim Graham <timograham@gmail.com> | 2016-02-25 19:08:16 -0500 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-02-25 20:04:51 -0500 |
commit | 7fec264e46d2a757f06f857e513072d72686cf9d (patch) | |
tree | efda654d7e3ecefd3f42b7a212259294ab1f3390 /tests/model_options | |
parent | bbe136e1a2f9cbf3fd10d49fbe8558a5b394752c (diff) | |
download | django-7fec264e46d2a757f06f857e513072d72686cf9d.tar.gz |
Removed try/fail antipattern from model_options tests.
Diffstat (limited to 'tests/model_options')
-rw-r--r-- | tests/model_options/test_default_related_name.py | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/tests/model_options/test_default_related_name.py b/tests/model_options/test_default_related_name.py index 940e1c3eb8..ddfc659dda 100644 --- a/tests/model_options/test_default_related_name.py +++ b/tests/model_options/test_default_related_name.py @@ -5,42 +5,25 @@ from .models.default_related_name import Author, Book, Editor class DefaultRelatedNameTests(TestCase): - def setUp(self): - self.author = Author.objects.create(first_name="Dave", last_name="Loper") - self.editor = Editor.objects.create(name="Test Editions", - bestselling_author=self.author) - self.book = Book.objects.create(title="Test Book", editor=self.editor) - self.book.authors.add(self.author) - self.book.save() + @classmethod + def setUpTestData(cls): + cls.author = Author.objects.create(first_name='Dave', last_name='Loper') + cls.editor = Editor.objects.create(name='Test Editions', bestselling_author=cls.author) + cls.book = Book.objects.create(title='Test Book', editor=cls.editor) + cls.book.authors.add(cls.author) def test_no_default_related_name(self): - try: - self.author.editor_set - except AttributeError: - self.fail("Author should have an editor_set relation.") + self.assertEqual(list(self.author.editor_set.all()), [self.editor]) def test_default_related_name(self): - try: - self.author.books - except AttributeError: - self.fail("Author should have a books relation.") + self.assertEqual(list(self.author.books.all()), [self.book]) def test_related_name_overrides_default_related_name(self): - try: - self.editor.edited_books - except AttributeError: - self.fail("Editor should have a edited_books relation.") + self.assertEqual(list(self.editor.edited_books.all()), [self.book]) def test_inheritance(self): - try: - # Here model_options corresponds to the name of the application used - # in this test - self.book.model_options_bookstores - except AttributeError: - self.fail("Book should have a model_options_bookstores relation.") + # model_options is the name of the application for this test. + self.assertEqual(list(self.book.model_options_bookstores.all()), []) def test_inheritance_with_overridden_default_related_name(self): - try: - self.book.editor_stores - except AttributeError: - self.fail("Book should have a editor_stores relation.") + self.assertEqual(list(self.book.editor_stores.all()), []) |