Purpose is to have a common event class for users and useful stuff (customers, products, ...) but lessen usage of common test data through sub modules. Indeed having a "global event type" test data updated in various addons is actually complicated to maintain. Sub add-ons are updated to use mainly the ``EventCase`` test class holding users and side data. Data specific to those modules (event type with some specific configuration notably) is created and used in tests in the given module only, and not through generic event_type_complex and event_0 test data anymore. With this commit tests are more localized to their add-on and modifying data in a given add-on has less chances to have unwanted side effect in other event submodules unit tests. Task-2703285 (Event performance improvements) Task-2703289 (Event testing and coverage) Part-of: odoo/odoo#81068
106 lines
3.8 KiB
Python
106 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields
|
|
from odoo.addons.mail.tests.common import mail_new_test_user
|
|
from odoo.tests import common
|
|
|
|
|
|
class EventCase(common.TransactionCase):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(EventCase, cls).setUpClass()
|
|
|
|
cls.admin_user = cls.env.ref('base.user_admin')
|
|
cls.admin_user.write({
|
|
'country_id': cls.env.ref('base.be').id,
|
|
'login': 'admin',
|
|
'notification_type': 'inbox',
|
|
})
|
|
cls.company_admin = cls.admin_user.company_id
|
|
# set country in order to format Belgian numbers
|
|
cls.company_admin.write({
|
|
'country_id': cls.env.ref('base.be').id,
|
|
})
|
|
|
|
# Test users to use through the various tests
|
|
cls.user_portal = mail_new_test_user(
|
|
cls.env,
|
|
company_id=cls.company_admin.id,
|
|
email='patrick.portal@test.example.com',
|
|
groups='base.group_portal',
|
|
login='portal_test',
|
|
name='Patrick Portal',
|
|
notification_type='email',
|
|
tz='Europe/Brussels',
|
|
)
|
|
cls.user_employee = mail_new_test_user(
|
|
cls.env,
|
|
company_id=cls.company_admin.id,
|
|
email='eglantine.employee@test.example.com',
|
|
groups='base.group_user',
|
|
login='user_employee',
|
|
name='Eglantine Employee',
|
|
notification_type='inbox',
|
|
tz='Europe/Brussels',
|
|
)
|
|
cls.user_eventregistrationdesk = mail_new_test_user(
|
|
cls.env,
|
|
company_id=cls.company_admin.id,
|
|
email='ursule.eventregistration@test.example.com',
|
|
login='user_eventregistrationdesk',
|
|
groups='base.group_user,event.group_event_registration_desk',
|
|
name='Ursule EventRegistration',
|
|
notification_type='inbox',
|
|
tz='Europe/Brussels',
|
|
)
|
|
cls.user_eventuser = mail_new_test_user(
|
|
cls.env,
|
|
company_id=cls.company_admin.id,
|
|
email='ursule.eventuser@test.example.com',
|
|
groups='base.group_user,event.group_event_user',
|
|
login='user_eventuser',
|
|
name='Ursule EventUser',
|
|
notification_type='inbox',
|
|
tz='Europe/Brussels',
|
|
)
|
|
cls.user_eventmanager = mail_new_test_user(
|
|
cls.env,
|
|
company_id=cls.company_admin.id,
|
|
email='martine.eventmanager@test.example.com',
|
|
groups='base.group_user,event.group_event_manager',
|
|
login='user_eventmanager',
|
|
name='Martine EventManager',
|
|
notification_type='inbox',
|
|
tz='Europe/Brussels',
|
|
)
|
|
|
|
cls.event_customer = cls.env['res.partner'].create({
|
|
'name': 'Constantin Customer',
|
|
'email': 'constantin@test.example.com',
|
|
'country_id': cls.env.ref('base.be').id,
|
|
'phone': '0485112233',
|
|
'mobile': False,
|
|
})
|
|
cls.event_customer2 = cls.env['res.partner'].create({
|
|
'name': 'Constantin Customer 2',
|
|
'email': 'constantin2@test.example.com',
|
|
'country_id': cls.env.ref('base.be').id,
|
|
'phone': '0456987654',
|
|
'mobile': '0456654321',
|
|
})
|
|
|
|
@classmethod
|
|
def _create_registrations(cls, event, reg_count):
|
|
# create some registrations
|
|
create_date = fields.Datetime.now()
|
|
registrations = cls.env['event.registration'].create([{
|
|
'create_date': create_date,
|
|
'event_id': event.id,
|
|
'name': 'Test Registration %s' % x,
|
|
'email': '_test_reg_%s@example.com' % x,
|
|
'phone': '04560000%s%s' % (x, x),
|
|
} for x in range(0, reg_count)])
|
|
return registrations
|