chore: Rename Doctype Test and more explicit comment
- Better decription of why the fix is done, what case it handles - Test for Renaming Doctype and Record having same name as DocType
This commit is contained in:
parent
856754bae6
commit
841f2f4a36
2 changed files with 44 additions and 3 deletions
|
|
@ -251,8 +251,14 @@ def update_link_field_values(link_fields, old, new, doctype):
|
|||
else:
|
||||
parent = field['parent']
|
||||
|
||||
# because the table hasn't been renamed yet!
|
||||
if field['parent'] == new and doctype == "DocType":
|
||||
# Handles the case where one of the link fields belongs to
|
||||
# the DocType being renamed.
|
||||
# Here this field could have the current DocType as its value too.
|
||||
|
||||
# In this case while updating link field value, the field's parent
|
||||
# or the current DocType table name hasn't been renamed yet,
|
||||
# so consider it's old name.
|
||||
if parent == new and doctype == "DocType":
|
||||
parent = old
|
||||
|
||||
frappe.db.sql("""
|
||||
|
|
|
|||
|
|
@ -288,4 +288,39 @@ class TestDocument(unittest.TestCase):
|
|||
self.assertEqual(merged_todo_doc.priority, second_todo_doc.priority)
|
||||
|
||||
for docname in available_documents:
|
||||
frappe.delete_doc(doctype, docname)
|
||||
frappe.delete_doc(doctype, docname)
|
||||
|
||||
def test_rename_doctype(self):
|
||||
from frappe.core.doctype.doctype.test_doctype import new_doctype
|
||||
|
||||
fields =[{
|
||||
"label": "Linked To",
|
||||
"fieldname": "linked_to_doctype",
|
||||
"fieldtype": "Link",
|
||||
"options": "DocType",
|
||||
"unique": 0
|
||||
}]
|
||||
if not frappe.db.exists("DocType", "Rename This"):
|
||||
new_doctype("Rename This", unique=0, fields=fields).insert()
|
||||
|
||||
to_rename_record = frappe.get_doc({
|
||||
"doctype": "Rename This",
|
||||
"linked_to_doctype": "Rename This"
|
||||
})
|
||||
to_rename_record.insert()
|
||||
|
||||
# Rename doctype
|
||||
self.assertEqual("Renamed Doc", frappe.rename_doc("DocType", "Rename This", "Renamed Doc", force=True))
|
||||
|
||||
# Test if Doctype value has changed in Link field
|
||||
renamed_doctype_record = frappe.get_doc("Renamed Doc", to_rename_record.name)
|
||||
self.assertEqual(renamed_doctype_record.linked_to_doctype, "Renamed Doc")
|
||||
|
||||
# Test if there are conflicts between a record and a DocType
|
||||
# having the same name
|
||||
old_name = to_rename_record.name
|
||||
new_name = "ToDo"
|
||||
self.assertEqual(new_name, frappe.rename_doc("Renamed Doc", old_name, new_name, force=True))
|
||||
|
||||
frappe.delete_doc_if_exists("Renamed Doc", "ToDo")
|
||||
frappe.delete_doc_if_exists("DocType", "Renamed Doc")
|
||||
Loading…
Add table
Reference in a new issue