diff --git a/frappe/core/doctype/document_naming_settings/test_document_naming_settings.py b/frappe/core/doctype/document_naming_settings/test_document_naming_settings.py index 98ce9e738b..bcd3197112 100644 --- a/frappe/core/doctype/document_naming_settings/test_document_naming_settings.py +++ b/frappe/core/doctype/document_naming_settings/test_document_naming_settings.py @@ -2,6 +2,7 @@ # See license.txt import frappe +from frappe.core.doctype.doctype.test_doctype import new_doctype from frappe.core.doctype.document_naming_settings.document_naming_settings import ( DocumentNamingSettings, ) @@ -11,6 +12,25 @@ from frappe.utils import cint class TestNamingSeries(FrappeTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.ns_doctype = ( + new_doctype( + fields=[ + { + "label": "Series", + "fieldname": "naming_series", + "fieldtype": "Select", + "options": f"\n{frappe.generate_hash()}-.###", + } + ], + autoname="naming_series:", + ) + .insert() + .name + ) + def setUp(self): self.dns: DocumentNamingSettings = frappe.get_doc("Document Naming Settings") @@ -23,7 +43,7 @@ class TestNamingSeries(FrappeTestCase): return VALID_SERIES + exisiting_series def test_naming_preview(self): - self.dns.transaction_type = "Webhook" + self.dns.transaction_type = self.ns_doctype self.dns.try_naming_series = "AXBZ.####" serieses = self.dns.preview_series().split("\n") @@ -35,23 +55,22 @@ class TestNamingSeries(FrappeTestCase): def test_get_transactions(self): naming_info = self.dns.get_transactions_and_prefixes() - self.assertIn("Webhook", naming_info["transactions"]) + self.assertIn(self.ns_doctype, naming_info["transactions"]) - existing_naming_series = frappe.get_meta("Webhook").get_field("naming_series").options + existing_naming_series = frappe.get_meta(self.ns_doctype).get_field("naming_series").options for series in existing_naming_series.split("\n"): self.assertIn(NamingSeries(series).get_prefix(), naming_info["prefixes"]) def test_default_naming_series(self): - self.assertIn("HOOK", get_default_naming_series("Webhook")) self.assertIsNone(get_default_naming_series("DocType")) def test_updates_naming_options(self): - self.dns.transaction_type = "Webhook" + self.dns.transaction_type = self.ns_doctype test_series = "KOOHBEW.###" self.dns.naming_series_options = self.dns.get_options() + "\n" + test_series self.dns.update_series() - self.assertIn(test_series, frappe.get_meta("Webhook").get_naming_series_options()) + self.assertIn(test_series, frappe.get_meta(self.ns_doctype).get_naming_series_options()) def test_update_series_counter(self): for series in self.get_valid_serieses(): diff --git a/frappe/integrations/doctype/webhook/test_webhook.py b/frappe/integrations/doctype/webhook/test_webhook.py index 7235447662..2edf2fcf5c 100644 --- a/frappe/integrations/doctype/webhook/test_webhook.py +++ b/frappe/integrations/doctype/webhook/test_webhook.py @@ -14,7 +14,10 @@ from frappe.tests.utils import FrappeTestCase @contextmanager def get_test_webhook(config): - wh = frappe.get_doc(config).insert() + wh = frappe.get_doc(config) + if not wh.name: + wh.name = frappe.generate_hash() + wh.insert() wh.reload() try: yield wh @@ -37,6 +40,7 @@ class TestWebhook(FrappeTestCase): def create_sample_webhooks(cls): samples_webhooks_data = [ { + "name": frappe.generate_hash(), "webhook_doctype": "User", "webhook_docevent": "after_insert", "request_url": "https://httpbin.org/post", @@ -44,6 +48,7 @@ class TestWebhook(FrappeTestCase): "enabled": True, }, { + "name": frappe.generate_hash(), "webhook_doctype": "User", "webhook_docevent": "after_insert", "request_url": "https://httpbin.org/post", diff --git a/frappe/integrations/doctype/webhook/webhook.json b/frappe/integrations/doctype/webhook/webhook.json index cfb2a2e01c..404e0be944 100644 --- a/frappe/integrations/doctype/webhook/webhook.json +++ b/frappe/integrations/doctype/webhook/webhook.json @@ -1,13 +1,12 @@ { "actions": [], - "autoname": "naming_series:", + "autoname": "prompt", "creation": "2017-09-08 16:16:13.060641", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ "sb_doc_events", - "naming_series", "webhook_doctype", "cb_doc_events", "webhook_docevent", @@ -46,6 +45,7 @@ { "fieldname": "webhook_doctype", "fieldtype": "Link", + "in_list_view": 1, "label": "DocType", "options": "DocType", "reqd": 1, @@ -136,12 +136,6 @@ "label": "JSON Request Body", "options": "JSON" }, - { - "fieldname": "naming_series", - "fieldtype": "Select", - "label": "Naming Series", - "options": "\nHOOK-.####" - }, { "fieldname": "sb_security", "fieldtype": "Section Break", @@ -218,11 +212,11 @@ "link_fieldname": "webhook" } ], - "modified": "2023-05-22 16:30:10.740512", + "modified": "2023-06-02 17:25:12.598232", "modified_by": "Administrator", "module": "Integrations", "name": "Webhook", - "naming_rule": "By \"Naming Series\" field", + "naming_rule": "Set by user", "owner": "Administrator", "permissions": [ { @@ -241,6 +235,5 @@ "sort_field": "modified", "sort_order": "DESC", "states": [], - "title_field": "webhook_doctype", "track_changes": 1 } \ No newline at end of file