def import_example_content(context): portal = api.portal.get() if "news" in portal.objectIds(): api.content.delete(obj=portal["news"]) if "events" in portal.objectIds(): api.content.delete(obj=portal["events"]) if "Members" in portal.objectIds(): api.content.delete(obj=portal["Members"]) # enable content non-globally addable types just for initial content # creation TEMP_ENABLE_CONTENT_TYPES = ["Folder"] for content_type in TEMP_ENABLE_CONTENT_TYPES: enable_content_type(portal, content_type) content_creator_from_folder( folder_name=os.path.join(os.path.dirname(__file__), "content_creator"), base_image_path=os.path.join(os.path.dirname(__file__), "content_images"), ) # disable again content non-globally addable types just for initial content # creation for content_type in TEMP_ENABLE_CONTENT_TYPES: disable_content_type(portal, content_type)
def test_repeat_creation_twice(self): path = os.path.join(os.path.dirname(__file__), "content") blocks = { "d3f1c443-583f-4e8e-a682-3bf25752a300": { "@type": "title" }, "7624cf59-05d0-4055-8f55-5fd6597d84b0": { "@type": "text" }, } blocks_layout = { "items": [ "d3f1c443-583f-4e8e-a682-3bf25752a300", "7624cf59-05d0-4055-8f55-5fd6597d84b0", ] } with api.env.adopt_roles(["Manager"]): content_creator_from_folder(folder_name=path) self.assertEqual(blocks, json.loads(self.portal.blocks)) self.assertEqual(blocks_layout, json.loads(self.portal.blocks_layout)) self.portal["a-folder"]["a-document-1"].title = "the modified title" with api.env.adopt_roles(["Manager"]): content_creator_from_folder(folder_name=path) self.assertEqual(self.portal["a-folder"]["a-document-1"].title, "Test Document 1")
def test_content_from_folder_with_excludes(self): path = os.path.join(os.path.dirname(__file__), "content") with api.env.adopt_roles(["Manager"]): content_creator_from_folder(folder_name=path, exclude=["a-folder.a-document-1"]) self.assertEqual(["front-page", "a-folder"], self.portal.contentIds()) self.assertEqual( ["a-document-2", "a-document-3", "the-last-document"], self.portal["a-folder"].contentIds(), )
def test_refresh_objects_created_by_structure(self): path = os.path.join(os.path.dirname(__file__), "content_with_refresh") with api.env.adopt_roles(["Manager"]): content_creator_from_folder(folder_name=path) content_structure = load_json( os.path.join(os.path.dirname(__file__), "content_with_refresh", "content.json")) refresh_objects_created_by_structure(api.portal.get(), content_structure) self.assertTrue("resolveuid" in json.dumps(self.portal["a-folder"] ["a-document"].blocks)) pass
def import_content(context): """Import example content""" portal = api.portal.get() # users api.user.create( email="*****@*****.**", username="******", password="******", roles=("Manager", ), properties=None, ) users = [] for user in users: api.user.create( email="*****@*****.**", username=user, password="******", roles=("Site Administrator", ), properties=None, ) # Delete Plone content if "Members" in portal.objectIds(): api.content.delete(obj=portal["Members"]) if "news" in portal.objectIds(): api.content.delete(obj=portal["news"]) if "events" in portal.objectIds(): api.content.delete(obj=portal["events"]) # enable content non-globally addable types just for initial content # creation TEMP_ENABLE_CONTENT_TYPES = ["Folder"] for content_type in TEMP_ENABLE_CONTENT_TYPES: enable_content_type(portal, content_type) content_creator_from_folder( folder_name=os.path.join(os.path.dirname(__file__), "content_creator"), base_image_path=os.path.join(os.path.dirname(__file__), "content_creator/images"), ) # disable again content non-globally addable types just for initial content # creation for content_type in TEMP_ENABLE_CONTENT_TYPES: disable_content_type(portal, content_type)
def test_content_from_folder_siteroot(self): path = os.path.join(os.path.dirname(__file__), "content") blocks = { "d3f1c443-583f-4e8e-a682-3bf25752a300": { "@type": "title" }, "7624cf59-05d0-4055-8f55-5fd6597d84b0": { "@type": "text" }, } blocks_layout = { "items": [ "d3f1c443-583f-4e8e-a682-3bf25752a300", "7624cf59-05d0-4055-8f55-5fd6597d84b0", ] } with api.env.adopt_roles(["Manager"]): content_creator_from_folder(folder_name=path) self.assertEqual(blocks, json.loads(self.portal.blocks)) self.assertEqual(blocks_layout, json.loads(self.portal.blocks_layout))