Files
odoo_source/addons/website/tests/test_get_current_website.py
T
Romain Derie 507db4e179 [REM] website: remove multi-website by country
Short summary:
- People can now use the snippets option to show/hide based on country
- We never use / test / maintain this feature, if it still works since
  its introduction 4 years ago that's by luck
- It is probably barely used, we never got a single question or issue
  about it

-----------

When we introduced the multi-website feature, it came with 2 main use
cases:
1. Multi website by domain -> Every website has its own domain and based
   on that we serve the expected website
2. Multi website by geoip -> Multiple website can have the same domain
   and based on GEOIP/country we serve the expected website

We never really supported, highlighted or promoted the geoip case.
We actually never use it ourselves when doing tests, and we don't
consider it when doing specs / improvements.
At most, only a very few people know about it in Odoo.

That GEOIP case is probably not useful at all, as displaying a whole new
website based on lang is not easy since nothing can be shared out of the
box -> Every website has its own COW records.

For instance, one could think of having its main website A and another
website B on which he just added 3 products specific to that website B
country.
But such a case won't even work properly, as any adaption on website A
won't be reflected on website B (design, theme etc).

closes odoo/odoo#99938

Related: odoo/upgrade#3892
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-09-15 18:22:00 +02:00

88 lines
3.8 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged
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.website
website1.domain = ''
website2 = Website.create({'name': 'My Website 2'})
# CASE: no domain: get first
self.assertEqual(Website._get_current_website_id(''), website1.id)
# setup domain
website1.domain = 'my-site-1.fr'
website2.domain = 'https://my2ndsite.com:80'
# CASE: domain set: get matching domain
self.assertEqual(Website._get_current_website_id('my-site-1.fr'), website1.id)
# CASE: domain set: get matching domain (scheme and port supported)
self.assertEqual(Website._get_current_website_id('my-site-1.fr:8069'), website1.id)
self.assertEqual(Website._get_current_website_id('my2ndsite.com:80'), website2.id)
self.assertEqual(Website._get_current_website_id('my2ndsite.com:8069'), website2.id)
self.assertEqual(Website._get_current_website_id('my2ndsite.com'), website2.id)
# CASE: domain set, wrong domain: get first
self.assertEqual(Website._get_current_website_id('test.com'), website1.id)
# CASE: subdomain: not supported
self.assertEqual(Website._get_current_website_id('www.my2ndsite.com'), website1.id)
# CASE: domain set: get by domain in priority
self.assertEqual(Website._get_current_website_id('my2ndsite.com'), website2.id)
self.assertEqual(Website._get_current_website_id('my-site-1.fr'), website1.id)
# CASE: overlapping domain: get exact match
website1.domain = 'site-1.com'
website2.domain = 'even-better-site-1.com'
self.assertEqual(Website._get_current_website_id('site-1.com'), website1.id)
self.assertEqual(Website._get_current_website_id('even-better-site-1.com'), website2.id)
# CASE: case insensitive
website1.domain = 'Site-1.com'
website2.domain = 'Even-Better-site-1.com'
self.assertEqual(Website._get_current_website_id('sitE-1.com'), website1.id)
self.assertEqual(Website._get_current_website_id('even-beTTer-site-1.com'), website2.id)
# CASE: same domain, different port
website1.domain = 'site-1.com:80'
website2.domain = 'site-1.com:81'
self.assertEqual(Website._get_current_website_id('site-1.com:80'), website1.id)
self.assertEqual(Website._get_current_website_id('site-1.com:81'), website2.id)
self.assertEqual(Website._get_current_website_id('site-1.com:82'), website1.id)
self.assertEqual(Website._get_current_website_id('site-1.com'), website1.id)
def test_02_signup_user_website_id(self):
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'})
self.assertTrue(user.website_id == user.partner_id.website_id == website)