-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! [IMP] database_cleanup: improve tests
- Loading branch information
Showing
9 changed files
with
178 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from contextlib import contextmanager | ||
from odoo.modules.registry import Registry | ||
from odoo.tests import TransactionCase | ||
|
||
import odoo | ||
from odoo.tests import common | ||
from odoo.tests.common import BaseCase, tagged | ||
|
||
ADMIN_USER_ID = common.ADMIN_USER_ID | ||
|
||
|
||
@contextmanager | ||
def environment(): | ||
"""Return an environment with a new cursor for the current database; the | ||
cursor is committed and closed after the context block. | ||
""" | ||
registry = odoo.registry(common.get_db_name()) | ||
with registry.cursor() as cr: | ||
yield odoo.api.Environment(cr, ADMIN_USER_ID, {}) | ||
|
||
|
||
# Use post_install to get all models loaded more info: odoo/odoo#13458 | ||
@tagged("post_install", "-at_install") | ||
class Common(BaseCase): | ||
class Common(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
super(Common, self).setUp() | ||
# this reloads our registry, and we don't want to run tests twice | ||
# we also need the original registry for further tests, so save a | ||
# reference to it | ||
self.original_registry = Registry.registries[self.env.cr.dbname] | ||
|
||
def tearDown(self): | ||
super(Common, self).tearDown() | ||
# Force rollback to avoid unstable test database | ||
self.env.cr.rollback() | ||
# reset afterwards | ||
Registry.registries[self.env.cr.dbname] = self.original_registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.