import unittest

import frappe
from frappe.www.list import get_list_context


class TestWebsite(unittest.TestCase):
	def test_get_context_hook_of_webform(self):
		create_custom_doctype()
		create_webform()

		# check context for apps without any hook
		context_list = get_list_context("", "Custom Doctype", "test-webform")
		self.assertFalse(context_list)

		# create a hook to get webform_context
		set_webform_hook(
			"webform_list_context",
			"frappe.www._test._test_webform.webform_list_context",
		)
		# check context for apps with hook
		context_list = get_list_context("", "Custom Doctype", "test-webform")
		self.assertTrue(context_list)


def create_custom_doctype():
	frappe.get_doc(
		{
			"doctype": "DocType",
			"name": "Custom Doctype",
			"module": "Core",
			"custom": 1,
			"fields": [{"label": "Title", "fieldname": "title", "fieldtype": "Data"}],
		}
	).insert(ignore_if_duplicate=True)


def create_webform():
	frappe.get_doc(
		{
			"doctype": "Web Form",
			"module": "Core",
			"title": "Test Webform",
			"route": "test-webform",
			"doc_type": "Custom Doctype",
			"web_form_fields": [
				{
					"doctype": "Web Form Field",
					"fieldname": "title",
					"fieldtype": "Data",
					"label": "Title",
				}
			],
		}
	).insert(ignore_if_duplicate=True)


def set_webform_hook(key, value):
	from frappe import hooks

	# reset hooks
	for hook in "webform_list_context":
		if hasattr(hooks, hook):
			delattr(hooks, hook)

	setattr(hooks, key, value)
	frappe.cache().delete_key("app_hooks")

@@ -40,80 +40,623 @@
 ppe.
-www.list import get_list_context%0A%0A%0Aclass TestWebsite(unittest.TestCase):
+utils import set_request%0Afrom frappe.website.serve import get_response%0Afrom frappe.www.list import get_list_context%0A%0A%0Aclass TestWebform(unittest.TestCase):%0A%09def test_webform_publish_functionality(self):%0A%09%09edit_profile = frappe.get_doc(%22Web Form%22, %22edit-profile%22)%0A%09%09# publish webform%0A%09%09edit_profile.published = True%0A%09%09edit_profile.save()%0A%09%09set_request(method=%22GET%22, path=%22update-profile%22)%0A%09%09response = get_response()%0A%09%09self.assertEqual(response.status_code, 200)%0A%0A%09%09# un-publish webform%0A%09%09edit_profile.published = False%0A%09%09edit_profile.save()%0A%09%09response = get_response()%0A%09%09self.assertEqual(response.status_code, 404)%0A
 %0A%09de

Add a case to cover webform publish functionality