Skip to content

[IMP] merge TransactionCase and SavepointCase#62031

Closed
rco-odoo wants to merge 9 commits intoodoo:masterfrom
odoo-dev:master-test-classes-rco
Closed

[IMP] merge TransactionCase and SavepointCase#62031
rco-odoo wants to merge 9 commits intoodoo:masterfrom
odoo-dev:master-test-classes-rco

Conversation

@rco-odoo
Copy link
Copy Markdown
Member

Essentially make both classes be the same one, and behave like SavepointCase.

@rco-odoo rco-odoo requested review from a team as code owners November 19, 2020 16:17
@robodoo robodoo added CI 🤖 Robodoo has seen passing statuses seen 🙂 labels Nov 19, 2020
@Julien00859 Julien00859 self-requested a review November 19, 2020 16:23
@yajo
Copy link
Copy Markdown
Contributor

yajo commented Nov 19, 2020

This is cool! 🎸

Are we supposed to have one of them be the "deprecated" flavor? I mean it because the code seems like the "ugly" kid is SavepointCase, but we've been doing efforts to migrate to SavepointCase since long ago, and it wouldn't be nice 😋

@C3POdoo C3POdoo added the RD research & development, internal work label Nov 19, 2020
@simahawk
Copy link
Copy Markdown
Contributor

Great initiative!

Are we supposed to have one of them be the "deprecated" flavor? I mean it because the code seems like the "ugly" kid is SavepointCase, but we've been doing efforts to migrate to SavepointCase since long ago, and it wouldn't be nice yum

Yeah that would be nice: keep SavepointCase class for a while and just deprecate it. It will help to not make all test suite break at once.

Copy link
Copy Markdown
Contributor

@d-fence d-fence left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (as far as I can allow myself to review)
Maybe we should adapt the docstrings accordingly to document the merged savepointcase behavior ?

Copy link
Copy Markdown
Member

@Julien00859 Julien00859 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @rco-odoo, is there static sphinx pages in the documentation we should also update or is it all generated from docstrings ?

@rco-odoo rco-odoo force-pushed the master-test-classes-rco branch 4 times, most recently from 55a373f to 04070fa Compare November 23, 2020 12:14
@rco-odoo rco-odoo requested a review from a team as a code owner November 23, 2020 13:35
@rco-odoo rco-odoo force-pushed the master-test-classes-rco branch 2 times, most recently from e2d7302 to 034487b Compare November 24, 2020 11:39
@rco-odoo rco-odoo requested a review from Julien00859 November 24, 2020 11:40
@rco-odoo
Copy link
Copy Markdown
Member Author

@Julien00859 I added the deprecation warning.
This forces me to replace all occurrences of SavepointCase by TransactionCase.

The now unique class behaves as the former class `SavepointCase`.  It is
now up to the developer to use `setUp` or `setUpClass` for preparing the
tests.
In unit tests, this avoids side effects from one test to another.  In
particular, a test modifying the user's company can make other tests
fail because `env.company` defaults to the user's company when nothing
else is available in the context.
Simply load translations in `setUpClass` instead of `setUp`.
As the same cursor is used by all tests, make sure to clear its `cache`
upon setup.
As the test explicitly commits the cursor (this is necessary to release
database locks), the teardown phase needs a valid savepoint.
One test method was setting `env.context` instead of creating a new
environment.
@rco-odoo rco-odoo force-pushed the master-test-classes-rco branch from 034487b to 859a999 Compare November 24, 2020 13:23
@rco-odoo
Copy link
Copy Markdown
Member Author

@robodoo rebase-ff r+

@robodoo
Copy link
Copy Markdown
Contributor

robodoo commented Nov 24, 2020

Merge method set to rebase and fast-forward

robodoo pushed a commit that referenced this pull request Nov 24, 2020
closes #62031

Related: odoo/enterprise#14872
Signed-off-by: Raphael Collet (rco) <[email protected]>
@robodoo robodoo closed this Nov 24, 2020
@robodoo robodoo temporarily deployed to merge November 24, 2020 15:49 Inactive
@yajo
Copy link
Copy Markdown
Contributor

yajo commented Nov 26, 2020

Well, my suggestion was more to deprecate TransactionCase. Otherwise we are supposed to use SavepointCase in Odoo 12-14 codebases, and then later on Odoo 15+ change it back to TransactionCase again. Going forward and backwards is not cool 😢

@fw-bot fw-bot deleted the master-test-classes-rco branch December 8, 2020 16:47
@rousseldenis
Copy link
Copy Markdown
Contributor

@rco-odoo @simahawk A good point should to improve common classes in order not to inherit from TransactionCase by default as it does not allow to inherit from it without launching all the test suites that inherit also.

IMHO the AccountInvoicingCommon class should inherit from nothing as it is there to create data and so on. Only tests classes that have 'test_' functions should inherit from TransactionCase.

https://github.com/odoo/odoo/blame/master/addons/account/tests/common.py#L11

@tfossoul
Copy link
Copy Markdown
Contributor

Hi @rco-odoo

I enriched the def action_signed(self) from the enterprise sign module for my customer.
In this fonction we have this line self.env.cr.commit()

def action_signed(self):
        self.write({'state': 'signed'})
        **self.env.cr.commit()**
        if not self.check_is_encrypted():
            # if the file is encrypted, we must wait that the document is decrypted
            self.send_completed_document()

When I run my test I see that the system is unable to rollback what have been done in the test because of the commit inside de action_signed.

I see in the sign tests the action_signed is not used. The workarround is a simple write state...

# sign the document
request_item.write({'state': 'completed'})

Do you have an idea to get rid of it ?

@rco-odoo
Copy link
Copy Markdown
Member Author

@tfossoul committing in the middle of a request is bad practice. You could try to avoid that commit by moving the subsequent action into a post-commit hook (cr.postcommit.add()). Post-commit hooks are never run by tests, simply because the cursor is never committed. This works well when the action sends some message to some 3rd party service.

If you cannot remove that commit statement, then I see two other possible solutions:

@tfossoul
Copy link
Copy Markdown
Contributor

@rco-odoo The "self.env.cr.commit()" line is part of odoo enterprise addons ;)

I suspect the cr.commit is done before trying to send completed document by mail synchronously via the force_send option of _message_send_mail function
Don't think it is usefull to force send the mails..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI 🤖 Robodoo has seen passing statuses RD research & development, internal work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants