[FIX] website: fix test_01_get_current_website_id

Cause:

  The test fails because there is some demo data that added additional
  website(s) and when trying to retrieve the current website without
  domain, it might retrieve the wrong one.

Solution:

    Unlink unused website(s).

opw-2899680

closes odoo/odoo#96810

X-original-commit: 45dfbae7301effe0d96163d67218a7854c3bde6f
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
Nasreddin Boulif (bon)
2022-07-28 03:50:53 +02:00
committed by Romain Derie
parent 37d7247df5
commit 1ebba3ea27
@@ -8,13 +8,26 @@ from odoo.tests.common import TransactionCase
@tagged('post_install', '-at_install')
class TestGetCurrentWebsite(TransactionCase):
def setUp(self):
# Unlink unused website(s) to avoid messing with the expected results
self.website = self.env.ref('website.default_website')
for w in self.env['website'].search([('id', '!=', self.website.id)]):
try:
# Website are impossible to delete most often than not, as if
# there is critical business data linked to it, it will prevent
# the unlink. Could easily happen with a bridge module adding
# some custom data.
w.unlink()
except Exception:
pass
def test_01_get_current_website_id(self):
"""Make sure `_get_current_website_id works`."""
Website = self.env['website']
# clean initial state
website1 = self.env.ref('website.default_website')
website1 = self.website
website1.domain = ''
website1.country_group_ids = False
@@ -116,7 +129,7 @@ class TestGetCurrentWebsite(TransactionCase):
self.assertEqual(Website._get_current_website_id('site-1.com', False), website1.id)
def test_02_signup_user_website_id(self):
website = self.env.ref('website.default_website')
website = self.website
website.specific_user_account = True
user = self.env['res.users'].create({'website_id': website.id, 'login': 'sad@mail.com', 'name': 'Hope Fully'})