I have written a baseclass to be used by django models. This baseclass adds some checks to the model, so I can be sure that they cannot be used in certain ways.
I want to test this baseclass, but in order to test all edge cases, I need to test an incorrect implementation (to make sure that wrong implementations are caught).
Due to the way Django works, I cannot write model classes inside tests directly like
class TestMyBaseClass:
def test_original_must_be_provided(self, db):
class MyModel(FlattenedProxyModel):
pass
# Create an instance
a = MyModel()
# Fail when trying to refresh info
with pytest.raises(MyError):
a.refresh_fields()
There will be cases where it will fail because there is no database table for this class (although this particular test will work, because the database is never accessed).
So the proper approach would be to use a Mock of a Django model. But how would that event work? I want a mock that extends my baseclass (uses it as a mixin) and it needs to respond appropriately to the isinstance(self, django.db.models.Model).
Any ideas?
Aucun commentaire:
Enregistrer un commentaire