Debian Codegraph @

addons/website_sale/tests/test_sitemap.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo.fields import Command
4 from odoo.tests import HttpCase, tagged
5
6
7 @tagged('post_install', '-at_install')
8 class TestSitemap(HttpCase):
9
10 def setUp(self):
11 super(TestSitemap, self).setUp()
12
13 self.cats = self.env['product.public.category'].create([{
14 'name': 'Level 0',
15 }, {
16 'name': 'Level 1',
17 }, {
18 'name': 'Level 2',
19 }, {
20 'name': 'Level 2A',
21 }])
22 self.cats[3].parent_id = self.cats[1].id
23 self.cats[2].parent_id = self.cats[1].id
24 self.cats[1].parent_id = self.cats[0].id
25 # 'Level 2' cetegory must have at least one published product to be visible by public users
26 self.env['product.product'].create({
27 'name': 'Dummy product',
28 'list_price': 100.0,
29 'public_categ_ids': [Command.link(self.cats[2].id)],
30 'is_published': True,
31 })
32 # 'Level 2A' category will contains only archived products, so should be hidden to public users
33 prodA = self.env['product.product'].create({
34 'name': 'Dummy product A',
35 'list_price': 100.0,
36 'public_categ_ids': [Command.link(self.cats[3].id)],
37 'is_published': True,
38 })
39 prodA.product_tmpl_id.active = False
40
41 def test_01_shop_route_sitemap(self):
42 resp = self.url_open('/sitemap.xml')
43 level2_url = '/shop/category/level-0-level-1-level-2-%s' % self.cats[2].id
44 self.assertIn(level2_url, resp.text, "Category entry in sitemap should be prefixed by its parent hierarchy.")
45 level2A_url = '/shop/category/level-0-level-1-level-2a-%s' % self.cats[3].id
46 self.assertNotIn(level2A_url, resp.text, "Category entry with no active products should not be listed in sitemap.")