Skip to content

DB Models

We have tested the Model Schemas using SQL and the ORM in 01.

We can test the other properties of the model such as the __str_, verbose_plural etc to ensure that our models give us the right data.

We can testthe Genre Model:

#models.py
    def __str__(self):
        """String for representing the Model object (in Admin site etc.)"""
        return f"Genre: {self.name}"

class TestGenre(TestCase):

    @classmethod
    def setUpTestData(cls):
        cls.genre_obj = Genre.objects.create(name="TestGenre")
        console.print(cls.genre_obj.__dict__)

    def test_MDL_201_genre_str(self):

        self.assertEqual(str(self.genre_obj), f"Genre: {self.genre_obj.name}")

    def test_MDL_202_genre_str_dunder(self):

        self.assertEqual(self.genre_obj.__str__(), f"Genre: {self.genre_obj.name}")