Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
9964 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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.

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Des 22
8213
0
Agu 21
4
1
Mar 19
18789
3
Mei 18
4832
2
Nov 16
3630