diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_sale/tests/test_website_sale_visitor.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_sale/tests/test_website_sale_visitor.py')
| -rw-r--r-- | addons/website_sale/tests/test_website_sale_visitor.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/addons/website_sale/tests/test_website_sale_visitor.py b/addons/website_sale/tests/test_website_sale_visitor.py new file mode 100644 index 00000000..7f24f33d --- /dev/null +++ b/addons/website_sale/tests/test_website_sale_visitor.py @@ -0,0 +1,53 @@ +# coding: utf-8 +from odoo.addons.website_sale.controllers.main import WebsiteSale +from odoo.addons.website.tools import MockRequest +from odoo.tests import TransactionCase, tagged + +@tagged('post_install', '-at_install') +class WebsiteSaleVisitorTests(TransactionCase): + + def setUp(self): + super().setUp() + self.website = self.env.ref('website.default_website') + self.WebsiteSaleController = WebsiteSale() + self.cookies = {} + + def test_create_visitor_on_tracked_product(self): + self.WebsiteSaleController = WebsiteSale() + existing_visitors = self.env['website.visitor'].search([]) + existing_tracks = self.env['website.track'].search([]) + + product = self.env['product.product'].create({ + 'name': 'Storage Box', + 'website_published': True, + }) + + with MockRequest(self.env, website=self.website): + self.cookies = self.WebsiteSaleController.products_recently_viewed_update(product.id) + + 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) + + 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', + 'website_published': True, + 'list_price': 320.0, + }) + + with MockRequest(self.env, website=self.website, cookies=self.cookies): + self.WebsiteSaleController.products_recently_viewed_update(product.id) + + 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") |
