Hi! I feel a bit stuck trying to write a unit test for an abstract base class that I’ve written as a mixin for a model. The class is fairly simple, and using it works as expected:
class UidMixin(models.Model):
_uid = models.CharField(max_length=32, default=calculate_uid)
class Meta:
abstract = True
To test it, I need to set to derive a class from this one, and instantiate objects from this derived class. So in my tests, I have:
class SomeModel(FlatPage, UidMixin):
pass
class Meta:
app_label = "resolveuid"
@pytest.fixture
def db_setup():
SomeModel.objects.create(title="page-1")
But I’m struggling to get the database setup right, so my tests could actually eg instantiate the class and perform some tests on it. So far, I only get:
ERROR tests/test_uidmixin.py::test_testing_uid - django.db.utils.OperationalError: no such table: resolveuid_somemodel
I have added the app to the INSTALLED_APPS, but SomeModel isn’t part of that, obviously. I guess that this is why it doesn’t appear in the database. I have read this discussion already, but don’t see where I could put the migration. This also feels wrong because the abstract class does, by definition, not have anything of its own, except for derived classes that are using it.
How should I approach this problem, please?