Challenge 1: Write a Model Test — Possible Solution ==================================================================== # catalog/tests.py from django.test import TestCase from .models import Author class AuthorModelTests(TestCase): def setUp(self): self.author = Author.objects.create( name="Octavia E. Butler", bio="American science fiction author.", ) def test_author_str_returns_name(self): self.assertEqual(str(self.author), "Octavia E. Butler") def test_author_was_saved_to_database(self): self.assertEqual(Author.objects.count(), 1) saved_author = Author.objects.get(pk=self.author.pk) self.assertEqual(saved_author.name, "Octavia E. Butler") WHY THIS WORKS -------------- - setUp() runs before EACH test method in the class, creating a fresh self.author every time — because Django's TestCase rolls back the database transaction after every test, test_author_was_saved_to_database never sees a leftover author from test_author_str_returns_name (or vice versa), even though both tests create an author with the same name. - self.assertEqual(str(self.author), "Octavia E. Butler") tests the model's __str__ method directly — Django's default admin display and shell repr both rely on __str__, so testing it directly catches a regression before it shows up as a confusing "Author object (1)" in the admin. - test_author_was_saved_to_database double-checks that create() actually persisted the object (not just built an unsaved instance) by re-fetching it fresh from the database via Author.objects.get(pk=...) rather than just inspecting the in-memory self.author object.