Files
odoo_source/addons/website/tests/test_website_visitor.py
T
Christophe Monniez 8d5da6e4be [IMP] tests: log a warning when HttpCase test in at_install
When loading a page on an existing starting database, registry is not
fully loaded causing potential error when trying to access model
existing in database (views, menitem, ...) since model added in last
loaded module does not exist in registry.

Thus, executing browser js test may lead to errors when executed during
an update on a database with other modules installed.

HTTPCase should be executed post_install to ensure that registry is
fully loaded to avoid this problem.

Since HTTPCase are slower than other test, it is also a good idea to
execute them at the end, in order to prioritize fast fail.

With this commit, a warning is isued if such a test class is tagged to
run at install time.

While at it, remove deprecated at_install and post_install helpers and
remove the deprecated phantom_js alias.

closes odoo/odoo#39462

Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
2019-10-30 12:35:23 +00:00

58 lines
2.4 KiB
Python

# coding: utf-8
from odoo.tests import HttpCase, tagged
@tagged('-at_install', 'post_install')
class WebsiteVisitorTests(HttpCase):
def test_create_visitor_on_tracked_page(self):
Page = self.env['website.page']
View = self.env['ir.ui.view']
Visitor = self.env['website.visitor']
Track = self.env['website.track']
untracked_view = View.create({
'name': 'Base',
'type': 'qweb',
'arch': '''<t name="Homepage" t-name="website.base_view">
<t t-call="website.layout">
I am a generic page
</t>
</t>''',
'key': 'test.base_view',
'track': False,
})
tracked_view = View.create({
'name': 'Base',
'type': 'qweb',
'arch': '''<t name="Homepage" t-name="website.base_view">
<t t-call="website.layout">
I am a generic page
</t>
</t>''',
'key': 'test.base_view',
'track': True,
})
[untracked_view, tracked_view] = Page.create([
{
'view_id': untracked_view.id,
'url': '/untracked_view',
'website_published': True,
},
{
'view_id': tracked_view.id,
'url': '/tracked_view',
'website_published': True,
},
])
self.assertEqual(len(Visitor.search([])), 0, "No visitor at the moment")
self.assertEqual(len(Track.search([])), 0, "No track at the moment")
self.url_open(untracked_view.url)
self.assertEqual(len(Visitor.search([])), 0, "No visitor created after visiting an untracked view")
self.assertEqual(len(Track.search([])), 0, "No track created after visiting an untracked view")
self.url_open(tracked_view.url)
self.assertEqual(len(Visitor.search([])), 1, "A visitor should be created after visiting a tracked view")
self.assertEqual(len(Track.search([])), 1, "A track should be created after visiting a tracked view")
self.url_open(tracked_view.url)
self.assertEqual(len(Visitor.search([])), 1, "No visitor should be created after visiting another tracked view")
self.assertEqual(len(Track.search([])), 1, "No track should be created after visiting another tracked view before 30 min")