-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from collective/issue-42-blog-rename
Rename Blog fti to BlogFolder
- Loading branch information
Showing
11 changed files
with
180 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rename Blog fti to BlogFolder, allowing contents with id blog to be added [@ericof] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from collective.blog import logger | ||
from plone import api | ||
from Products.GenericSetup.tool import SetupTool | ||
|
||
|
||
TYPES_MAPPING = (("Blog", "BlogFolder"),) | ||
|
||
|
||
def _migrate_existing_content(old_pt: str, new_pt: str) -> int: | ||
"""Update existing content items.""" | ||
with api.env.adopt_roles(["Manager"]): | ||
# Search catalog as Manager | ||
brains = api.content.find(portal_type=old_pt) | ||
total = len(brains) | ||
logger.info(f"Convert {total} {old_pt} instances to {new_pt}") | ||
for brain in brains: | ||
obj = brain.getObject() | ||
obj.portal_type = new_pt | ||
obj.reindexObject( | ||
idxs=[ | ||
"portal_type", | ||
"Type", | ||
], | ||
) | ||
return total | ||
|
||
|
||
def recatalog_portal_type(setup_tool: SetupTool): | ||
"""Recatalog portal type for existing content items.""" | ||
for old_pt, new_pt in TYPES_MAPPING: | ||
items = _migrate_existing_content(old_pt, new_pt) | ||
logger.info(f"Converted {items} {old_pt} instances") | ||
logger.info("Upgrade complete") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from collective.blog import PACKAGE_NAME | ||
from plone import api | ||
|
||
import pytest | ||
|
||
|
||
PROFILE_ID = f"profile-{PACKAGE_NAME}:default" | ||
|
||
|
||
@pytest.fixture | ||
def do_rollback(portal): | ||
"""Rollback profile config.""" | ||
|
||
def func(src: str): | ||
with api.env.adopt_roles(["Manager"]): | ||
setup_tool = portal.portal_setup | ||
setup_tool.setLastVersionForProfile(PROFILE_ID, src) | ||
|
||
return func | ||
|
||
|
||
@pytest.fixture | ||
def do_upgrade(portal): | ||
def func(dest: str): | ||
with api.env.adopt_roles(["Manager"]): | ||
setup_tool = portal.portal_setup | ||
setup_tool.upgradeProfile(PROFILE_ID, dest=dest) | ||
|
||
return func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from collective.blog.content.blog import Blog | ||
from collective.blog.upgrades.v1002 import TYPES_MAPPING | ||
from copy import deepcopy | ||
from plone import api | ||
from plone.dexterity.fti import DexterityFTI | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def modify_ftis(portal, get_fti): | ||
"""Modify fti""" | ||
|
||
def func(): | ||
with api.env.adopt_roles(["Manager"]): | ||
# Rename new content type back to its old name | ||
types_tool = portal.portal_types | ||
for old_pt, new_pt in TYPES_MAPPING: | ||
types_tool.manage_renameObject(new_pt, old_pt) | ||
fti = get_fti(old_pt) | ||
fti.title = old_pt | ||
|
||
return func | ||
|
||
|
||
@pytest.fixture | ||
def old_blog_factory(portal, blogs_payload): | ||
def func() -> Blog: | ||
with api.env.adopt_roles(["Manager"]): | ||
payload = deepcopy(blogs_payload[0]) | ||
payload["type"] = "Blog" | ||
payload["id"] = "old-blog" | ||
return api.content.create(portal, **payload) | ||
|
||
return func | ||
|
||
|
||
class TestUpgradeV1002: | ||
src: str = "1001" | ||
dest: str = "1002" | ||
|
||
@pytest.fixture(autouse=True) | ||
def _init(self, get_fti, do_rollback, do_upgrade, modify_ftis, old_blog_factory): | ||
do_rollback(self.src) | ||
modify_ftis() | ||
self.get_fti = get_fti | ||
self.old_blog = old_blog_factory() | ||
self.upgrade = do_upgrade | ||
|
||
def test_blog_fti_available_in_1001(self): | ||
assert isinstance(self.get_fti("Blog"), DexterityFTI) | ||
assert self.get_fti("BlogFolder") is None | ||
|
||
def test_blogfolder_fti_available_in_1002(self, do_upgrade): | ||
do_upgrade(self.dest) | ||
assert isinstance(self.get_fti("BlogFolder"), DexterityFTI) | ||
assert self.get_fti("Blog") is None | ||
|
||
def test_old_blogs_migrated(self, do_upgrade): | ||
with api.env.adopt_roles(["Manager"]): | ||
brains = api.content.find(portal_type="BlogFolder") | ||
assert len(brains) == 0 | ||
# Upgrade | ||
do_upgrade(self.dest) | ||
with api.env.adopt_roles(["Manager"]): | ||
brains = api.content.find(portal_type="BlogFolder") | ||
assert len(brains) == 1 | ||
assert self.old_blog.portal_type == "BlogFolder" | ||
assert self.old_blog.Type() == "BlogFolder" |