Skip to content

Commit

Permalink
chore: black
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Apr 7, 2023
1 parent 216ab10 commit cd2d910
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 50 deletions.
2 changes: 1 addition & 1 deletion plone/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
2 changes: 1 addition & 1 deletion plone/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
27 changes: 13 additions & 14 deletions plone/app/intid/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
try:
# XXX here we must consider plone.app.multilingual as well!
import Products.LinguaPlone

Products.LinguaPlone
HAS_LINGUAPLONE = True
except ImportError:
Expand All @@ -23,22 +24,19 @@
def register_all_content_for_intids(portal):
"""Registers all existing content with the intid utility.
This will not be fast."""
cat = getToolByName(portal, 'portal_catalog', None)
cat = getToolByName(portal, "portal_catalog", None)
if cat is None:
return
intids = getUtility(IIntIds)
# Take advantage of paths stored in keyreferences in five.intid to optimize
# registration
registered_paths = {
ref.path for ref in intids.ids
if hasattr(ref, 'path')
}
registered_paths = {ref.path for ref in intids.ids if hasattr(ref, "path")}
# Count how many objects we register
registered = 0
existing = 0
query = {'object_provides': IContentish.__identifier__}
query = {"object_provides": IContentish.__identifier__}
if HAS_LINGUAPLONE:
query['Language'] = 'all'
query["Language"] = "all"
for brain in cat(query):
if brain.getPath() in registered_paths:
existing += 1
Expand All @@ -55,22 +53,23 @@ def register_all_content_for_intids(portal):


def add_intids(context):
addUtility(context, IIntIds, IntIds, ofs_name='intids',
findroot=False)
addUtility(context, IIntIds, IntIds, ofs_name="intids", findroot=False)


def installIntIds(context):
if context.readDataFile('install_intids.txt') is None:
if context.readDataFile("install_intids.txt") is None:
return
portal = context.getSite()
add_intids(portal)
return 'Added intid utility.'
return "Added intid utility."


def registerContent(context):
if context.readDataFile('intid_register_content.txt') is None:
if context.readDataFile("intid_register_content.txt") is None:
return
portal = context.getSite()
registered, existing = register_all_content_for_intids(portal)
return ('Assigned intids to {} content objects, {} objects '
'already had intids.'.format(registered, existing))
return (
"Assigned intids to {} content objects, {} objects "
"already had intids.".format(registered, existing)
)
6 changes: 3 additions & 3 deletions plone/app/intid/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@


class IntidSetupFixture(PloneSandboxLayer):
defaultBases = (PLONE_FIXTURE, )
defaultBases = (PLONE_FIXTURE,)

def setUpZope(self, app, configurationContext):
# pylint: disable=W0613
import plone.app.intid

self.loadZCML(package=plone.app.intid)


SETUP_TESTING = IntegrationTesting(
bases=(IntidSetupFixture(), ),
name='IntidSetupFixture:Setup'
bases=(IntidSetupFixture(),), name="IntidSetupFixture:Setup"
)
24 changes: 12 additions & 12 deletions plone/app/intid/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ class TestSetup(unittest.TestCase):
layer = SETUP_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.portal = self.layer["portal"]
# XXX below code is only needed if theres no Folder FTI already setup.
typetool = getToolByName(self.portal, 'portal_types')
if 'Folder' not in typetool.objectIds():
typetool = getToolByName(self.portal, "portal_types")
if "Folder" not in typetool.objectIds():
# XXX Check if this is needed for Plone 5.0! In 4.3 the FTI is
# already setup
fti = DexterityFTI('Folder')
typetool._setObject('Folder', fti)
fti = DexterityFTI("Folder")
typetool._setObject("Folder", fti)

def tearDown(self):
setRoles(self.portal, TEST_USER_ID, ['Member'])
setRoles(self.portal, TEST_USER_ID, ["Member"])

def test_already_installed(self):
"""plone.app.intid is a dependency of plone.app.linkintegrity
which is a dependency of CMFPlone, so it is always installed.
This tests if this is true.
"""
# we create a folder
setRoles(self.portal, TEST_USER_ID, ['Manager'])
folder_id = self.portal.invokeFactory('Folder', 'folder')
setRoles(self.portal, TEST_USER_ID, ["Manager"])
folder_id = self.portal.invokeFactory("Folder", "folder")
folder = self.portal[folder_id]
intids = getUtility(IIntIds)
self.assertIsNotNone(intids.getId(folder))

@unittest.skip('p.a.intid is always installed')
@unittest.skip("p.a.intid is always installed")
def test_install(self):
"""When p.app.intid is intalled it registers some utility
from zope.intid and five.intid and search in portal_catalog
Expand All @@ -50,8 +50,8 @@ def test_install(self):
from plone.app.testing import applyProfile

# we create a folder before the intallation of plone.app.intid
setRoles(self.portal, TEST_USER_ID, ['Manager'])
folder_id = self.portal.invokeFactory('Folder', 'folder')
setRoles(self.portal, TEST_USER_ID, ["Manager"])
folder_id = self.portal.invokeFactory("Folder", "folder")
folder = self.portal[folder_id]

# now we install manually the intid utilities
Expand All @@ -62,5 +62,5 @@ def test_install(self):
self.assertRaises(KeyError, intids.getId, folder)

# when we install p.app.intid our folder is referencend by intid
applyProfile(self.portal, 'plone.app.intid:default')
applyProfile(self.portal, "plone.app.intid:default")
self.assertIsNotNone(intids.getId(folder))
37 changes: 18 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import os


version = '1.1.5.dev0'
version = "1.1.5.dev0"

setup(
name='plone.app.intid',
name="plone.app.intid",
version=version,
description="Installation and migration support for five.intid within "
"Plone/CMF",
long_description='{}\n{}'.format(
description="Installation and migration support for five.intid within " "Plone/CMF",
long_description="{}\n{}".format(
open("README.rst").read(),
open(os.path.join("CHANGES.rst")).read(),
),
Expand All @@ -33,26 +32,26 @@
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
keywords='plone zope five intid',
author='Alec Mitchell',
author_email='apm13@columbia.edu',
url='https://github.com/plone/plone.app.intid',
license='GPL',
keywords="plone zope five intid",
author="Alec Mitchell",
author_email="apm13@columbia.edu",
url="https://github.com/plone/plone.app.intid",
license="GPL",
packages=find_packages(),
namespace_packages=['plone', 'plone.app'],
namespace_packages=["plone", "plone.app"],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'zope.intid',
'zope.lifecycleevent',
'five.intid>=1.0',
'Products.CMFCore',
"setuptools",
"zope.intid",
"zope.lifecycleevent",
"five.intid>=1.0",
"Products.CMFCore",
],
extras_require={
'test': [
'plone.app.testing',
'plone.dexterity',
"test": [
"plone.app.testing",
"plone.dexterity",
],
},
entry_points="""
Expand Down

0 comments on commit cd2d910

Please sign in to comment.