Skip to content

Commit

Permalink
test: prop setter syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 11, 2024
1 parent 0fcd032 commit 9245062
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 4 additions & 3 deletions frappe/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ def _insert(data):
case "Property Setter":
# Property setter implement their own deduplication, we can just sync them as is
for d in data[key]:
if d.get(doctype_fieldname) == doc_type:
d["doctype"] = custom_doctype
if d.get("doc_type") == doc_type:
d["doctype"] = "Property Setter"
doc = frappe.get_doc(d)
doc.flags.validate_fields_for_doctype = False
doc.insert()
case "Custom DocPerm":
# Docperm have no "sync" as of now.
# TODO/XXX: Docperm have no "sync" as of now. They get OVERRIDDEN on sync.
frappe.db.delete("Custom DocPerm", {"parent": doc_type})

for d in data[key]:
Expand Down
17 changes: 15 additions & 2 deletions frappe/tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from frappe import scrub
from frappe.core.doctype.doctype.test_doctype import new_doctype
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
from frappe.model.meta import trim_table
from frappe.modules import export_customizations, export_module_json, get_module_path
from frappe.modules.utils import export_doc, sync_customizations
Expand Down Expand Up @@ -87,16 +88,23 @@ def test_export_customizations(self):
os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable"
)
def test_sync_customizations(self):
with note_customizations() as custom_field:
with note_customizations() as (custom_field, property_setter):
file_path = export_customizations(module="Custom", doctype="Note", sync_on_migrate=True)
custom_field.db_set("modified", now_datetime())
custom_field.reload()

# Untracked property setter
custom_prop_setter = make_property_setter(
"Note", fieldname="content", property="bold", value="1", property_type="Check"
)

self.assertTrue(file_path.endswith("/custom/custom/note.json"))
self.assertTrue(os.path.exists(file_path))
last_modified_before = custom_field.modified

sync_customizations(app="frappe")
self.assertTrue(property_setter.doctype, property_setter.name)
self.assertTrue(custom_prop_setter.doctype, custom_prop_setter.name)

self.assertTrue(file_path.endswith("/custom/custom/note.json"))
self.assertTrue(os.path.exists(file_path))
Expand Down Expand Up @@ -173,8 +181,13 @@ def note_customizations():
"fieldtype": "Data",
}
custom_field = create_custom_field("Note", df=df)
yield custom_field

property_setter = make_property_setter(
"Note", fieldname="content", property="bold", value="1", property_type="Check"
)
yield custom_field, property_setter
finally:
custom_field.delete()
property_setter.delete()
trim_table("Note", dry_run=False)
delete_path(frappe.get_module_path("Desk", "Note"))

0 comments on commit 9245062

Please sign in to comment.