def test_product_list(self): template_items = frappe.get_all('Item', {'show_in_website': 1}) variant_items = frappe.get_all('Item', {'show_variant_in_website': 1}) products_settings = frappe.get_doc('Products Settings') products_settings.enable_field_filters = 1 products_settings.append('filter_fields', {'fieldname': 'item_group'}) products_settings.append('filter_fields', {'fieldname': 'stock_uom'}) products_settings.save() html = get_html_for_route('all-products') soup = BeautifulSoup(html, 'html.parser') products_list = soup.find(class_='products-list') items = products_list.find_all(class_='card') self.assertEqual(len(items), len(template_items + variant_items)) items_with_item_group = frappe.get_all('Item', {'item_group': '_Test Item Group Desktops', 'show_in_website': 1}) variants_with_item_group = frappe.get_all('Item', {'item_group': '_Test Item Group Desktops', 'show_variant_in_website': 1}) # mock query params frappe.form_dict = frappe._dict({ 'field_filters': '{"item_group":["_Test Item Group Desktops"]}' }) html = get_html_for_route('all-products') soup = BeautifulSoup(html, 'html.parser') products_list = soup.find(class_='products-list') items = products_list.find_all(class_='card') self.assertEqual(len(items), len(items_with_item_group + variants_with_item_group))
def test_sitemap(self): blogs = frappe.db.get_all('Blog Post', {'published': 1}, ['route'], limit=1) xml = get_html_for_route('sitemap.xml') self.assertTrue('/about</loc>' in xml) self.assertTrue('/contact</loc>' in xml) self.assertTrue(blogs[0].route in xml)
def test_sitemap(self): from frappe.test_runner import make_test_records make_test_records('Blog Post') blogs = frappe.db.get_all('Blog Post', {'published': 1}, ['route'], limit=1) xml = get_html_for_route('sitemap.xml') self.assertTrue('/about</loc>' in xml) self.assertTrue('/contact</loc>' in xml) self.assertTrue(blogs[0].route in xml)
def test_sitemap(self): from frappe.test_runner import make_test_records make_test_records("Blog Post") blogs = frappe.db.get_all("Blog Post", {"published": 1}, ["route"], limit=1) xml = get_html_for_route("sitemap.xml") self.assertTrue("/about</loc>" in xml) self.assertTrue("/contact</loc>" in xml) self.assertTrue(blogs[0].route in xml)
def test_dynamic_route(self): web_page = frappe.get_doc( dict(doctype='Web Page', title='Test Dynamic Route', published=1, dynamic_route=1, route='/doctype-view/<doctype>', content_type='HTML', dynamic_template=1, main_section_html='<div>{{ frappe.form_dict.doctype }}</div>') ).insert() try: from frappe.utils import get_html_for_route content = get_html_for_route('/doctype-view/DocField') self.assertIn('<div>DocField</div>', content) finally: web_page.delete()