common.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from datetime import datetime, timedelta, time
  4. from unittest.mock import patch
  5. from odoo.addons.event.tests.common import EventCase
  6. from odoo.addons.mail.tests.common import mail_new_test_user
  7. from odoo.fields import Datetime as FieldsDatetime, Date as FieldsDate
  8. from odoo.tests.common import TransactionCase
  9. class OnlineEventCase(EventCase):
  10. @classmethod
  11. def setUpClass(cls):
  12. super(OnlineEventCase, cls).setUpClass()
  13. cls.company_main = cls.env.user.company_id
  14. cls.user_event_web_manager = mail_new_test_user(
  15. cls.env,
  16. company_id=cls.company_admin.id,
  17. email='crm_manager@test.example.com',
  18. groups='event.group_event_manager,website.group_website_designer',
  19. login='user_event_web_manager',
  20. name='Martin Sales Manager',
  21. notification_type='inbox',
  22. )
  23. cls.event_customer.write({
  24. 'website_description': '<p>I am your best customer, %s</p>' % cls.event_customer.name,
  25. })
  26. cls.event_customer2.write({
  27. 'website_description': '<p>I am your best customer, %s</p>' % cls.event_customer2.name,
  28. })
  29. def _get_menus(self):
  30. return set(['Introduction', 'Location', 'Register', 'Community'])
  31. def _assert_website_menus(self, event, menus_in=None, menus_out=None):
  32. self.assertTrue(event.menu_id)
  33. if menus_in is None:
  34. menus_in = list(self._get_menus())
  35. menus = self.env['website.menu'].search([('parent_id', '=', event.menu_id.id)])
  36. self.assertTrue(len(menus) >= len(menus_in))
  37. self.assertTrue(all(menu_name in menus.mapped('name') for menu_name in menus_in))
  38. if menus_out:
  39. self.assertTrue(all(menu_name not in menus.mapped('name') for menu_name in menus_out))
  40. for page_specific in ['Introduction', 'Location']:
  41. view = self.env['ir.ui.view'].search(
  42. [('name', '=', page_specific + ' ' + event.name)]
  43. )
  44. if page_specific in menus_in:
  45. self.assertTrue(bool(view))
  46. else:
  47. self.assertFalse(bool(view))
  48. class TestEventOnlineCommon(OnlineEventCase):
  49. @classmethod
  50. def setUpClass(cls):
  51. super(TestEventOnlineCommon, cls).setUpClass()
  52. # Mock dates to have reproducible computed fields based on time
  53. cls.reference_now = datetime(2020, 7, 6, 10, 0, 0)
  54. cls.reference_today = datetime(2020, 7, 6)
  55. # event if 8-18 in Europe/Brussels (DST) (first day: begins at 9, last day: ends at 15)
  56. cls.event_0 = cls.env['event.event'].create({
  57. 'name': 'TestEvent',
  58. 'auto_confirm': True,
  59. 'date_begin': datetime.combine(cls.reference_now, time(7, 0)) - timedelta(days=1),
  60. 'date_end': datetime.combine(cls.reference_now, time(13, 0)) + timedelta(days=1),
  61. 'date_tz': 'Europe/Brussels',
  62. })