summaryrefslogtreecommitdiff
path: root/addons/website/tests/test_res_users.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website/tests/test_res_users.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website/tests/test_res_users.py')
-rw-r--r--addons/website/tests/test_res_users.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/addons/website/tests/test_res_users.py b/addons/website/tests/test_res_users.py
new file mode 100644
index 00000000..ef8d97ed
--- /dev/null
+++ b/addons/website/tests/test_res_users.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from psycopg2 import IntegrityError
+
+from odoo.tests.common import TransactionCase, new_test_user
+from odoo.exceptions import ValidationError
+from odoo.service.model import check
+from odoo.tools import mute_logger
+
+
+class TestWebsiteResUsers(TransactionCase):
+
+ def setUp(self):
+ super().setUp()
+ websites = self.env['website'].create([
+ {'name': 'Test Website'},
+ {'name': 'Test Website 2'},
+ ])
+ self.website_1, self.website_2 = websites
+
+ def test_no_website(self):
+ new_test_user(self.env, login='Pou', website_id=False)
+ with self.assertRaises(ValidationError):
+ new_test_user(self.env, login='Pou', website_id=False)
+
+ def test_websites_set_null(self):
+ user_1 = new_test_user(self.env, login='Pou', website_id=self.website_1.id)
+ user_2 = new_test_user(self.env, login='Pou', website_id=self.website_2.id)
+ with self.assertRaises(ValidationError):
+ (user_1 | user_2).write({'website_id': False})
+
+ def test_null_and_website(self):
+ new_test_user(self.env, login='Pou', website_id=self.website_1.id)
+ new_test_user(self.env, login='Pou', website_id=False)
+
+ def test_change_login(self):
+ new_test_user(self.env, login='Pou', website_id=self.website_1.id)
+ user_belle = new_test_user(self.env, login='Belle', website_id=self.website_1.id)
+ with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
+ user_belle.login = 'Pou'
+
+ def test_change_login_no_website(self):
+ new_test_user(self.env, login='Pou', website_id=False)
+ user_belle = new_test_user(self.env, login='Belle', website_id=False)
+ with self.assertRaises(ValidationError):
+ user_belle.login = 'Pou'
+
+ def test_same_website_message(self):
+
+ @check # Check decorator, otherwise translation is not applied
+ def check_new_test_user(dbname):
+ new_test_user(self.env(context={'land': 'en_US'}), login='Pou', website_id=self.website_1.id)
+
+ new_test_user(self.env, login='Pou', website_id=self.website_1.id)
+
+ # Should be a ValidationError (with a nice translated error message),
+ # not an IntegrityError
+ with self.assertRaises(ValidationError), mute_logger('odoo.sql_db'):
+ check_new_test_user(self.env.registry._db.dbname)