Skip to Content
Menu
This question has been flagged
3 Replies
9961 Zobrazenia

When testing a model (models.Model), we use the ORM to create instances of the model and make assertions about its behavior. Since an abstract model (models.AbstractModel) can not be created, how do you test an abstract model?

Avatar
Zrušiť
Best Answer

Hi Tyler,

Abstract is a generic model that implements some feature that can then be inherited by regular models in order to make that feature available in them.
So if you want to test abstract model you need to inherit this inside regular model(models.model).
For reference you can look for mail.thread.

Avatar
Zrušiť
Autor

It just seems awkward to have to subclass an AbstractModel in order to test it. There ought to be a way to unit test the AbstractModel when it contains logic that will be inherited by other classes.

Best Answer

Usually you create a dummy class that inherits the abstract class and use it for unit testing but in Odoo you don't want test tables in your database. So the trick is to create a distinct module for the sole testing purpose and which you will install on a test database but not on a production database. For example, the mass_mailing application does not have any unit test for its abstract classes. The tests are located in another module called test_mass_mailing which has a models package with some test classes.

Avatar
Zrušiť
Related Posts Replies Zobrazenia Aktivita
1
dec 22
8208
0
aug 21
4
1
mar 19
18785
3
máj 18
4832
2
nov 16
3623