I have a contenttype and hundreds of objects of this type. Now i must refactor this type (delete some fields). I can delete the field definitions in the code base and clean the objects in an upgrade step. But how can i test this scenario?
I found a piece of code in plone.restapi, but i don't know where this adapter is definied, for better understanding what happen.
def delete_field(context, request, name):
field = context.publishTraverse(request, name)
delete = queryMultiAdapter((field, request), name="delete")
delete()
Here is my Test snippet to construct the scenario:
class IBaseDummySchema(model.Schema):
prop1 = schema.TextLine(
title="Prop 1",
default=None
)
prop2 = schema.TextLine(
title="Prop 2",
default=None
)
class IDummyTypeSchema(IBaseDummySchema):
pass
class TestInterfaceUpgrade(BaseFunctionalTest):
def setUp(self):
import transaction
self.app = self.layer["app"]
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
fti = DexterityFTI("dummytype")
self.portal.portal_types._setObject("dummytype", fti)
fti.klass = "plone.dexterity.content.Item"
fti.schema = "my.addon.tests.test_interface_update.IDummyTypeSchema"
fti.global_allow = True
self.portal.portal_types['Plone Site'].allowed_content_types = ("Dummytype",)
self.portal.invokeFactory(
"dummytype",
id="dummy-object",
title="Dummy Object",
)
transaction.commit()
def test_remove_field_from_schema(self):
# field = self.portal.object1.publishTraverse(self.request, "prop2")
# delete = queryMultiAdapter((field, self.request), name="delete")
breakpoint()