Пример #1
0
	def test_raw_assets_are_loaded(self):
		content = get_response_content('/_test/assets/js_asset.min.js')
		# minified js files should not be passed through jinja renderer
		self.assertEqual("//{% if title %} {{title}} {% endif %}\nconsole.log('in');", content)

		content = get_response_content('/_test/assets/css_asset.css')
		self.assertEqual("""body{color:red}""", content)
Пример #2
0
	def test_breadcrumbs(self):
		content = get_response_content('/_test/_test_folder/_test_page')
		self.assertIn('<span itemprop="name">Test Folder</span>', content)
		self.assertIn('<span itemprop="name"> Test Page</span>', content)

		content = get_response_content('/_test/_test_folder/index')
		self.assertIn('<span itemprop="name"> Test</span>', content)
		self.assertIn('<span itemprop="name">Test Folder</span>', content)
Пример #3
0
	def test_safe_render(self):
		content = get_response_content('/_test/_test_safe_render_on')
		self.assertNotIn("Safe Render On", content)
		self.assertIn("frappe.exceptions.ValidationError: Illegal template", content)

		content = get_response_content('/_test/_test_safe_render_off')
		self.assertIn("Safe Render Off", content)
		self.assertIn("test.__test", content)
		self.assertNotIn("frappe.exceptions.ValidationError: Illegal template", content)
Пример #4
0
	def test_json_sidebar_data(self):
		frappe.flags.look_for_sidebar = False
		content = get_response_content('/_test/_test_folder/_test_page')
		self.assertNotIn('Test Sidebar', content)
		clear_website_cache()
		frappe.flags.look_for_sidebar = True
		content = get_response_content('/_test/_test_folder/_test_page')
		self.assertIn('Test Sidebar', content)
		frappe.flags.look_for_sidebar = False
Пример #5
0
	def test_index_and_next_comment(self):
		content = get_response_content('/_test/_test_folder')
		# test if {index} was rendered
		self.assertIn('<a href="/_test/_test_folder/_test_page"> Test Page</a>', content)

		self.assertIn('<a href="/_test/_test_folder/_test_toc">Test TOC</a>', content)

		content = get_response_content('/_test/_test_folder/_test_page')
		# test if {next} was rendered
		self.assertIn('Next: <a class="btn-next" href="/_test/_test_folder/_test_toc">Test TOC</a>', content)
Пример #6
0
	def test_custom_base_template_path(self):
		content = get_response_content('/_test/_test_folder/_test_page')
		# assert the text in base template is rendered
		self.assertIn('<h1>This is for testing</h1>', content)

		# assert template block rendered
		self.assertIn('<p>Test content</p>', content)
Пример #7
0
	def get_document_to_index(self, route):
		"""Render a page and parse it using BeautifulSoup

		Args:
			path (str): route of the page to be parsed

		Returns:
			document (_dict): A dictionary with title, path and content
		"""
		frappe.set_user("Guest")
		frappe.local.no_cache = True

		try:
			set_request(method="GET", path=route)
			content = get_response_content(route)
			soup = BeautifulSoup(content, "html.parser")
			page_content = soup.find(class_="page_content")
			text_content = page_content.text if page_content else ""
			title = soup.title.text.strip() if soup.title else route

			return frappe._dict(title=title, content=text_content, path=route)
		except Exception:
			pass
		finally:
			frappe.set_user("Administrator")
Пример #8
0
def add_route_to_global_search(route):
    from bs4 import BeautifulSoup
    from frappe.website.serve import get_response_content
    from frappe.utils import set_request
    frappe.set_user('Guest')
    frappe.local.no_cache = True

    try:
        set_request(method='GET', path=route)
        content = get_response_content(route)
        soup = BeautifulSoup(content, 'html.parser')
        page_content = soup.find(class_='page_content')
        text_content = page_content.text if page_content else ''
        title = soup.title.text.strip() if soup.title else route

        value = dict(doctype='Static Web Page',
                     name=route,
                     content=text_content,
                     published=1,
                     title=title,
                     route=route)
        sync_value_in_queue(value)
    except Exception:
        pass

    frappe.set_user('Administrator')
Пример #9
0
    def test_content_type(self):
        web_page = frappe.get_doc(
            dict(doctype='Web Page',
                 title='Test Content Type',
                 published=1,
                 content_type='Rich Text',
                 main_section='rich text',
                 main_section_md='# h1\nmarkdown content',
                 main_section_html='<div>html content</div>')).insert()

        self.assertIn('rich text', get_response_content('/test-content-type'))

        web_page.content_type = 'Markdown'
        web_page.save()
        self.assertIn('markdown content',
                      get_response_content('/test-content-type'))

        web_page.content_type = 'HTML'
        web_page.save()
        self.assertIn('html content',
                      get_response_content('/test-content-type'))

        web_page.delete()
Пример #10
0
	def test_custom_page_renderer(self):
		import frappe.hooks
		frappe.hooks.page_renderer = ['frappe.tests.test_website.CustomPageRenderer']
		frappe.cache().delete_key('app_hooks')
		set_request(method='GET', path='/custom')
		response = get_response()
		self.assertEqual(response.status_code, 3984)

		set_request(method='GET', path='/new')
		content = get_response_content()
		self.assertIn("<div>Custom Page Response</div>", content)

		set_request(method='GET', path='/random')
		response = get_response()
		self.assertEqual(response.status_code, 404)

		delattr(frappe.hooks, 'page_renderer')
		frappe.cache().delete_key('app_hooks')
Пример #11
0
	def test_get_context_without_context_object(self):
		content = get_response_content('/_test/_test_no_context')
		self.assertIn("Custom Content", content)
Пример #12
0
	def test_colocated_assets(self):
		content = get_response_content('/_test/_test_folder/_test_page')
		self.assertIn("<script>console.log('test data');</script>", content)
		self.assertIn("background-color: var(--bg-color);", content)
Пример #13
0
	def test_printview_page(self):
		content = get_response_content('/Language/en')
		self.assertIn('<div class="print-format">', content)
		self.assertIn('<div>Language</div>', content)
Пример #14
0
 def test_error_page_rendering(self):
     content = get_response_content("error")
     self.assertIn("Error", content)
Пример #15
0
 def test_webform_render(self):
     content = get_response_content('request-data')
     self.assertIn('<h2>Request Data</h2>', content)
     self.assertIn('data-doctype="Web Form"', content)
     self.assertIn('data-path="request-data"', content)
     self.assertIn('source-type="Generator"', content)