summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-07-15 17:24:59 +0000
committerThibault Delavallée <tde@odoo.com>2020-07-22 11:13:18 +0000
commitf7e7a273cc6fbb67dd62c6d9bbfdf8bc687cbbce (patch)
tree678a06caac68d05dbca6e81b46a0b9308c450da9
parent97c6a79fba35a7fe4a42f9f19caf263d7ec3b458 (diff)
[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
-rw-r--r--addons/website_sale/tests/test_website_sale_visitor.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/addons/website_sale/tests/test_website_sale_visitor.py b/addons/website_sale/tests/test_website_sale_visitor.py
index c18e7ae4843..7f24f33d618 100644
--- a/addons/website_sale/tests/test_website_sale_visitor.py
+++ b/addons/website_sale/tests/test_website_sale_visitor.py
@@ -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")