Files
odoo_source/addons/website_event_track/tests/test_track_internals.py
T
Thibault Delavallée f3356904b6 [MOV] website_event(_track/exhibitor): move sponsor model directly into Online Exhibitors
RATIONALE

Events often have sponsors displayed on their front page. This should be
a real standalone feature of Online Event application. However currently it
cannot be used without tracks managements

PURPOSE

Purpose of this task is to allow to use and display sponsors on an Event front
page without using tracks. Moreover online and chat capabilities should be
part of a sponsor feature, located within website_event_exhibitor module.

SPECIFICATIONS

Move everything related to event.sponsor model from website_event_track
to website_event_exhibitor. Functionally feature should be the same as
before except that we should be able to configure and display sponsors
directly with website_event_exhibitor application without using tracks.

Website_event_exhibitor should also define the sponsor template used to
display sponsors below an event.

LINKS

Task ID-2326433
COM PR odoo/odoo#61781
ENT pr odoo/enterprise#14752
UPG PR odoo/upgrade#1931
2020-12-04 07:49:30 +00:00

124 lines
5.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime, timedelta
from unittest.mock import patch
from odoo import fields
from odoo.addons.website.models.website_visitor import WebsiteVisitor
from odoo.addons.website_event.tests.common import TestEventOnlineCommon
class TestTrackSuggestions(TestEventOnlineCommon):
def test_track_suggestion(self):
[location_1, location_2] = self.env['event.track.location'].create([
{'name': 'Location 1'},
{'name': 'Location 2'},
])
[tag_1, tag_2, tag_3, tag_4] = self.env['event.track.tag'].create([
{'name': 'Tag 1'}, {'name': 'Tag 2'}, {'name': 'Tag 3'}, {'name': 'Tag 4'}
])
date = fields.Datetime.from_string(datetime.now().strftime('%Y-%m-%d %H:00:00'))
[track_1, track_2, track_3, track_4, track_5, track_6] = self.env['event.track'].create([{
'name': 'Track 1',
'location_id': location_1.id,
'event_id': self.event_0.id,
'tag_ids': [(4, tag_1.id), (4, tag_2.id)],
'date': date + timedelta(hours=-1),
}, {
'name': 'Track 2',
'location_id': location_2.id,
'event_id': self.event_0.id,
'date': date,
}, {
'name': 'Track 3',
'location_id': location_2.id,
'event_id': self.event_0.id,
'tag_ids': [(4, tag_1.id), (4, tag_3.id), (4, tag_4.id)],
'date': date,
}, {
'name': 'Track 4',
'event_id': self.event_0.id,
'tag_ids': [(4, tag_1.id), (4, tag_2.id)],
'date': date,
}, {
'name': 'Track 5',
'event_id': self.event_0.id,
'tag_ids': [(4, tag_1.id), (4, tag_3.id)],
'wishlisted_by_default': True,
'date': date,
}, {
'name': 'Track 6',
'location_id': location_1.id,
'event_id': self.event_0.id,
'tag_ids': [(4, tag_1.id), (4, tag_3.id)],
'date': date,
}])
emp_visitor = self.env['website.visitor'].create({
'name': 'Visitor',
'partner_id': self.user_employee.partner_id.id
})
visitor_track = self.env['event.track.visitor'].create({
'visitor_id': emp_visitor.id,
'track_id': track_3.id,
'is_wishlisted': True,
})
with patch.object(WebsiteVisitor, '_get_visitor_from_request', lambda *args, **kwargs: emp_visitor), \
self.with_user('user_employee'):
current_track = self.env['event.track'].browse(track_1.id)
all_suggestions = current_track._get_track_suggestions()
self.assertEqual(
all_suggestions.ids,
(track_3 + track_5 + track_4 + track_6 + track_2).ids # whlst / wishlst def / tags count / location
)
track_suggestion = current_track._get_track_suggestions(limit=1)
self.assertEqual(track_suggestion, track_3,
'Returned track should be the manually wishlisted one')
# remove wishlist, keynote should be top
visitor_track.unlink()
track_suggestion = current_track._get_track_suggestions(limit=1)
self.assertEqual(
track_suggestion, track_5,
'Returned track should be the default wishlisted one')
# toggle wishlisted by default off through blacklist
track_5_visitor = self.env['event.track.visitor'].sudo().create({
'visitor_id': emp_visitor.id,
'track_id': track_5.id,
'is_blacklisted': True,
})
track_suggestion = current_track._get_track_suggestions(limit=1)
self.assertEqual(
track_suggestion, track_4,
'Returned track should the one with the most common tags as keynote is blacklisted')
track_5_visitor.unlink()
# remove keynote default, now based on tags
track_5.write({'wishlisted_by_default': False})
# all_suggestions.invalidate_cache(fnames=['is_reminder_on'])
track_suggestion = current_track._get_track_suggestions(limit=1)
self.assertEqual(
track_suggestion, track_4,
'Returned track should the one with the most common tags')
# remove tags, now based on location
all_suggestions.sudo().write({'tag_ids': [(5,)]})
track_suggestion = current_track._get_track_suggestions(limit=1)
self.assertEqual(
track_suggestion, track_6,
'Returned track should the one with matching location')
# remove location, now based o random
all_suggestions.sudo().write({'location_id': False})
track_suggestion = current_track._get_track_suggestions(limit=1)
self.assertTrue(
track_suggestion in [track_2, track_3, track_4, track_5, track_6],
"Returned track should the a random one (but not the one we're trying to get suggestion for)")