[IMP] website_sale: make visitor test independent from demo

PURPOSE

Prepare Event Online support by providing fixes and preparatory cleaning
commits.

SPECIFICATIONS

Make visitor tests in website_sale independent from existing visitors and
specially about demo data. Adding demo data makes tests crash which is not
the expected assert of visitor tests.

LINKS

Task ID-2300907 (Event Bugprovements 2)
PR #54621

X-original-commit: 971f26a14d5cbafd65f4370eac14f4cd762b5b44
This commit is contained in:
Thibault Delavallée
2020-07-22 11:13:18 +00:00
parent 97c6a79fba
commit f7e7a273cc
@@ -14,11 +14,8 @@ class WebsiteSaleVisitorTests(TransactionCase):
def test_create_visitor_on_tracked_product(self):
self.WebsiteSaleController = WebsiteSale()
Visitor = self.env['website.visitor']
Track = self.env['website.track']
self.assertEqual(len(Visitor.search([])), 0, "No visitor at the moment")
self.assertEqual(len(Track.search([])), 0, "No track at the moment")
existing_visitors = self.env['website.visitor'].search([])
existing_tracks = self.env['website.track'].search([])
product = self.env['product.product'].create({
'name': 'Storage Box',
@@ -28,14 +25,18 @@ class WebsiteSaleVisitorTests(TransactionCase):
with MockRequest(self.env, website=self.website):
self.cookies = self.WebsiteSaleController.products_recently_viewed_update(product.id)
self.assertEqual(len(Visitor.search([])), 1, "A visitor should be created after visiting a tracked product")
self.assertEqual(len(Track.search([])), 1, "A track should be created after visiting a tracked product")
new_visitors = self.env['website.visitor'].search([('id', 'not in', existing_visitors.ids)])
new_tracks = self.env['website.track'].search([('id', 'not in', existing_tracks.ids)])
self.assertEqual(len(new_visitors), 1, "A visitor should be created after visiting a tracked product")
self.assertEqual(len(new_tracks), 1, "A track should be created after visiting a tracked product")
with MockRequest(self.env, website=self.website, cookies=self.cookies):
self.WebsiteSaleController.products_recently_viewed_update(product.id)
self.assertEqual(len(Visitor.search([])), 1, "No visitor should be created after visiting another tracked product")
self.assertEqual(len(Track.search([])), 1, "No track should be created after visiting the same tracked product before 30 min")
new_visitors = self.env['website.visitor'].search([('id', 'not in', existing_visitors.ids)])
new_tracks = self.env['website.track'].search([('id', 'not in', existing_tracks.ids)])
self.assertEqual(len(new_visitors), 1, "No visitor should be created after visiting another tracked product")
self.assertEqual(len(new_tracks), 1, "No track should be created after visiting the same tracked product before 30 min")
product = self.env['product.product'].create({
'name': 'Large Cabinet',
@@ -46,5 +47,7 @@ class WebsiteSaleVisitorTests(TransactionCase):
with MockRequest(self.env, website=self.website, cookies=self.cookies):
self.WebsiteSaleController.products_recently_viewed_update(product.id)
self.assertEqual(len(Visitor.search([])), 1, "No visitor should be created after visiting another tracked product")
self.assertEqual(len(Track.search([])), 2, "A track should be created after visiting another tracked product")
new_visitors = self.env['website.visitor'].search([('id', 'not in', existing_visitors.ids)])
new_tracks = self.env['website.track'].search([('id', 'not in', existing_tracks.ids)])
self.assertEqual(len(new_visitors), 1, "No visitor should be created after visiting another tracked product")
self.assertEqual(len(new_tracks), 2, "A track should be created after visiting another tracked product")