Files
odoo_source/addons/auth_signup/tests/test_auth_signup.py
T
flvr-odoo 960eb211f0 [FIX] auth_signup: added a check for internal_user
add a write permission check on internal user to quietly dismiss the
error upon landing on the user page

closes odoo/odoo#127094

X-original-commit: ec85785b4629b474d96d070a5a8b44b9ba5f9dcb
Signed-off-by: Vranckx Florian (flvr) <flvr@odoo.com>
2023-07-04 07:55:16 +02:00

66 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from unittest.mock import patch
import odoo
from odoo.tests import HttpCase
from odoo import http
from odoo.exceptions import AccessError
class TestAuthSignupFlow(HttpCase):
def setUp(self):
super(TestAuthSignupFlow, self).setUp()
res_config = self.env['res.config.settings']
self.default_values = res_config.default_get(list(res_config.fields_get()))
def _activate_free_signup(self):
self.default_values.update({'auth_signup_uninvited': 'b2c'})
def _get_free_signup_url(self):
return '/web/signup'
def test_confirmation_mail_free_signup(self):
"""
Check if a new user is informed by email when he is registered
"""
# Activate free signup
self._activate_free_signup()
# Get csrf_token
self.authenticate(None, None)
csrf_token = http.Request.csrf_token(self)
# Values from login form
name = 'toto'
payload = {
'login': 'toto@example.com',
'name': name,
'password': 'mypassword',
'confirm_password': 'mypassword',
'csrf_token': csrf_token,
}
# Override unlink to not delete the email if the send works.
with patch.object(odoo.addons.mail.models.mail_mail.MailMail, 'unlink', lambda self: None):
# Call the controller
url_free_signup = self._get_free_signup_url()
self.url_open(url_free_signup, data=payload)
# Check if an email is sent to the new userw
new_user = self.env['res.users'].search([('name', '=', name)])
self.assertTrue(new_user)
mail = self.env['mail.message'].search([('message_type', '=', 'email'), ('model', '=', 'res.users'), ('res_id', '=', new_user.id)], limit=1)
self.assertTrue(mail, "The new user must be informed of his registration")
def test_compute_signup_url(self):
user = self.env.ref('base.user_demo')
user.groups_id -= self.env.ref('base.group_partner_manager')
partner = self.env.ref('base.partner_demo_portal')
partner.signup_prepare()
with self.assertRaises(AccessError):
partner.with_user(user.id).signup_url