Testing and integrating a package module
Taking a package development all the way to production: the three environments, the levels of testing, data import and its rejections, and the rollback plan.
- 25 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
Staging environment: what is it?
Show the answer
An installation close to production, kept apart from real users, where a change is tried on a recent copy of their data before it is delivered.
A module that works on an empty database can fail on real data and on the other installed modules. Staging reveals those failures at no cost.
This module test fails with
AssertionError: 25.0 != 20. What needs fixing?
```python
def test_total(self):
partner = self.env['res.partner'].create({'name': 'Dupont'})
loan = self.env['library.loan'].create({
'partner_id': partner.id,
'line_ids': [(0, 0, {'price': 10}), (0, 0, {'price': 15})],
})
self.assertEqual(loan.total, 20)`- The expected value: 10 plus 15 make 25, it is the test that is wrong
- The field computation: it must return 20 for the test to pass
- Nothing: a failing unit test can safely be left as it is
- The assertion:
assertTrue(loan.total)would then pass and be enough
Show the answer
The expected value: 10 plus 15 make 25, it is the test that is wrong
The message gives the value obtained (25.0) and the expected value (20): the code does add correctly. Weakening the assertion to make the test pass would empty it of value.
A change travels through three environments, in this order: …, … then ….
Show the answer
A change travels through three environments, in this order: development, staging then production.
You develop where breaking things is fine, test on a realistic copy, and only then touch the installation that users really use.
Integration test: what is it?
Show the answer
A test that checks that the module works with the standard and the other installed modules, following a scenario that crosses several of them.
A module can be right on its own and break its neighbour: a required field added to a standard model blocks invoicing, which only a full scenario reveals.
After the loan module was installed in production, no invoice can be validated any more. What is the cause and the fix?
- The staging database is too old; reloading it from production solves the problem, and invoices then just need revalidating
- The manifest has no version number; add one then reinstall the module, which unblocks the validation of invoices
- A field made required on a standard model blocks invoicing; give it a default value or drop the requirement, then test with invoicing
- The accounting group's rights are too broad; restrict them to what is strictly needed so that invoices validate again
Show the answer
A field made required on a standard model blocks invoicing; give it a default value or drop the requirement, then test with invoicing
Standard invoices are created without knowing the added field: if it is required, creation fails. The integration test with invoicing had never been run.