summaryrefslogtreecommitdiff
path: root/addons/website_event_track/tests
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-08-20 14:03:52 +0000
committerThibault Delavallée <tde@odoo.com>2020-08-21 17:30:13 +0000
commitde8a5652b27da2f659b1378831c6d712ff40b488 (patch)
tree0b8f4acaace303f6f0100151bc0e570fb606b530 /addons/website_event_track/tests
parent1163013ed6bf191a9e1548866a4df699f72b5bf4 (diff)
[REM] website_event_track_session: merge into website_event_track
PURPOSE Clean organization and models linked to Event Online feature introduced in semi stable saas-13.3 at odoo/odoo@981f95bbf46658eda9f2d33751b9310cc67d86aa and odoo/enterprise@14722028ae0773c3710ea48ce48ff44703e83b5a Also clean website event menu not being available in website event but only in website event track, which implies some extra-code to manage it. In short: merge website_event_online in website_event, website_event_track _(online/session) in website_event_track. RATIONALE _online modules have been added to extend content of website_event and website_event_track without having any impact on those module. First step of cleaning is to move this content directly in base module. track_session module is mainly a rewrite of track module. Second step of cleaning is to move its content directly in website_event_track. SPECIFICATIONS Move all content of website event track session to website event tracK. It was mainly of rewriting of views and can now be safely merged into the base track module. Update dependencies accordingly. LINKS Task ID-2319779 COM odoo/odoo#56067 ENT odoo/enterprise#12520 UPG odoo/upgrade#1654
Diffstat (limited to 'addons/website_event_track/tests')
-rw-r--r--addons/website_event_track/tests/__init__.py1
-rw-r--r--addons/website_event_track/tests/test_track_internals.py123
2 files changed, 124 insertions, 0 deletions
diff --git a/addons/website_event_track/tests/__init__.py b/addons/website_event_track/tests/__init__.py
index 12b9da864c8..aac974d7656 100644
--- a/addons/website_event_track/tests/__init__.py
+++ b/addons/website_event_track/tests/__init__.py
@@ -2,4 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import common
+from . import test_track_internals
from . import test_website_event
diff --git a/addons/website_event_track/tests/test_track_internals.py b/addons/website_event_track/tests/test_track_internals.py
new file mode 100644
index 00000000000..e2af8c0c6fe
--- /dev/null
+++ b/addons/website_event_track/tests/test_track_internals.py
@@ -0,0 +1,123 @@
+# -*- 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_track.tests.common import TestEventTrackOnlineCommon
+
+
+class TestTrackSuggestions(TestEventTrackOnlineCommon):
+
+ 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)")