diff --git a/src/collective/ocrmypdf/__init__.py b/src/collective/ocrmypdf/__init__.py index 4864457..aa5b680 100644 --- a/src/collective/ocrmypdf/__init__.py +++ b/src/collective/ocrmypdf/__init__.py @@ -3,4 +3,4 @@ from zope.i18nmessageid import MessageFactory -_ = MessageFactory('collective.ocrmypdf') +_ = MessageFactory("collective.ocrmypdf") diff --git a/src/collective/ocrmypdf/configure.zcml b/src/collective/ocrmypdf/configure.zcml index 1076ddd..a1f7f6a 100644 --- a/src/collective/ocrmypdf/configure.zcml +++ b/src/collective/ocrmypdf/configure.zcml @@ -43,4 +43,6 @@ + + diff --git a/src/collective/ocrmypdf/locales/update.py b/src/collective/ocrmypdf/locales/update.py index 09e8f8d..c732d1c 100644 --- a/src/collective/ocrmypdf/locales/update.py +++ b/src/collective/ocrmypdf/locales/update.py @@ -5,12 +5,12 @@ import subprocess -domain = 'collective.ocrmypdf' -os.chdir(pkg_resources.resource_filename(domain, '')) -os.chdir('../../../') -target_path = 'src/collective/ocrmypdf/' -locale_path = target_path + 'locales/' -i18ndude = './bin/i18ndude' +domain = "collective.ocrmypdf" +os.chdir(pkg_resources.resource_filename(domain, "")) +os.chdir("../../../") +target_path = "src/collective/ocrmypdf/" +locale_path = target_path + "locales/" +i18ndude = "./bin/i18ndude" # ignore node_modules files resulting in errors excludes = '"*.html *json-schema*.xml"' @@ -18,15 +18,15 @@ def locale_folder_setup(): os.chdir(locale_path) - languages = [d for d in os.listdir('.') if os.path.isdir(d)] + languages = [d for d in os.listdir(".") if os.path.isdir(d)] for lang in languages: folder = os.listdir(lang) - if 'LC_MESSAGES' in folder: + if "LC_MESSAGES" in folder: continue else: - lc_messages_path = lang + '/LC_MESSAGES/' + lc_messages_path = lang + "/LC_MESSAGES/" os.mkdir(lc_messages_path) - cmd = 'msginit --locale={0} --input={1}.pot --output={2}/LC_MESSAGES/{3}.po'.format( # NOQA: E501 + cmd = "msginit --locale={0} --input={1}.pot --output={2}/LC_MESSAGES/{3}.po".format( # NOQA: E501 lang, domain, lang, @@ -37,11 +37,11 @@ def locale_folder_setup(): shell=True, ) - os.chdir('../../../../') + os.chdir("../../../../") def _rebuild(): - cmd = '{i18ndude} rebuild-pot --pot {locale_path}/{domain}.pot --exclude {excludes} --create {domain} {target_path}'.format( # NOQA: E501 + cmd = "{i18ndude} rebuild-pot --pot {locale_path}/{domain}.pot --exclude {excludes} --create {domain} {target_path}".format( # NOQA: E501 i18ndude=i18ndude, locale_path=locale_path, domain=domain, @@ -55,7 +55,7 @@ def _rebuild(): def _sync(): - cmd = '{0} sync --pot {1}/{2}.pot {3}*/LC_MESSAGES/{4}.po'.format( + cmd = "{0} sync --pot {1}/{2}.pot {3}*/LC_MESSAGES/{4}.po".format( i18ndude, locale_path, domain, diff --git a/src/collective/ocrmypdf/setuphandlers.py b/src/collective/ocrmypdf/setuphandlers.py index 27abce1..ce308f6 100644 --- a/src/collective/ocrmypdf/setuphandlers.py +++ b/src/collective/ocrmypdf/setuphandlers.py @@ -5,7 +5,6 @@ @implementer(INonInstallable) class HiddenProfiles(object): - def getNonInstallableProfiles(self): """Hide uninstall profile from site-creation and quickinstaller.""" return [ diff --git a/src/collective/ocrmypdf/subscribers/__init__.py b/src/collective/ocrmypdf/subscribers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/collective/ocrmypdf/subscribers/configure.zcml b/src/collective/ocrmypdf/subscribers/configure.zcml new file mode 100644 index 0000000..3f3d188 --- /dev/null +++ b/src/collective/ocrmypdf/subscribers/configure.zcml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/src/collective/ocrmypdf/subscribers/file_modified_ocr.py b/src/collective/ocrmypdf/subscribers/file_modified_ocr.py new file mode 100644 index 0000000..3577067 --- /dev/null +++ b/src/collective/ocrmypdf/subscribers/file_modified_ocr.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + + +def handler(obj, event): + """Event handler""" + print("{0} on object {1}".format(event.__class__, obj.absolute_url())) diff --git a/src/collective/ocrmypdf/testing.py b/src/collective/ocrmypdf/testing.py index b85dd40..013e623 100644 --- a/src/collective/ocrmypdf/testing.py +++ b/src/collective/ocrmypdf/testing.py @@ -19,13 +19,15 @@ def setUpZope(self, app, configurationContext): # The z3c.autoinclude feature is disabled in the Plone fixture base # layer. import plone.app.dexterity + self.loadZCML(package=plone.app.dexterity) import plone.restapi + self.loadZCML(package=plone.restapi) self.loadZCML(package=collective.ocrmypdf) def setUpPloneSite(self, portal): - applyProfile(portal, 'collective.ocrmypdf:default') + applyProfile(portal, "collective.ocrmypdf:default") COLLECTIVE_OCRMYPDF_FIXTURE = CollectiveOcrmypdfLayer() @@ -33,13 +35,13 @@ def setUpPloneSite(self, portal): COLLECTIVE_OCRMYPDF_INTEGRATION_TESTING = IntegrationTesting( bases=(COLLECTIVE_OCRMYPDF_FIXTURE,), - name='CollectiveOcrmypdfLayer:IntegrationTesting', + name="CollectiveOcrmypdfLayer:IntegrationTesting", ) COLLECTIVE_OCRMYPDF_FUNCTIONAL_TESTING = FunctionalTesting( bases=(COLLECTIVE_OCRMYPDF_FIXTURE,), - name='CollectiveOcrmypdfLayer:FunctionalTesting', + name="CollectiveOcrmypdfLayer:FunctionalTesting", ) @@ -49,5 +51,5 @@ def setUpPloneSite(self, portal): REMOTE_LIBRARY_BUNDLE_FIXTURE, z2.ZSERVER_FIXTURE, ), - name='CollectiveOcrmypdfLayer:AcceptanceTesting', + name="CollectiveOcrmypdfLayer:AcceptanceTesting", ) diff --git a/src/collective/ocrmypdf/tests/test_robot.py b/src/collective/ocrmypdf/tests/test_robot.py index 0ab040c..0b186bc 100644 --- a/src/collective/ocrmypdf/tests/test_robot.py +++ b/src/collective/ocrmypdf/tests/test_robot.py @@ -13,18 +13,21 @@ def test_suite(): suite = unittest.TestSuite() current_dir = os.path.abspath(os.path.dirname(__file__)) - robot_dir = os.path.join(current_dir, 'robot') + robot_dir = os.path.join(current_dir, "robot") robot_tests = [ - os.path.join('robot', doc) for doc in os.listdir(robot_dir) - if doc.endswith('.robot') and doc.startswith('test_') + os.path.join("robot", doc) + for doc in os.listdir(robot_dir) + if doc.endswith(".robot") and doc.startswith("test_") ] for robot_test in robot_tests: robottestsuite = robotsuite.RobotTestSuite(robot_test) robottestsuite.level = ROBOT_TEST_LEVEL - suite.addTests([ - layered( - robottestsuite, - layer=COLLECTIVE_OCRMYPDF_ACCEPTANCE_TESTING, - ), - ]) + suite.addTests( + [ + layered( + robottestsuite, + layer=COLLECTIVE_OCRMYPDF_ACCEPTANCE_TESTING, + ), + ] + ) return suite diff --git a/src/collective/ocrmypdf/tests/test_setup.py b/src/collective/ocrmypdf/tests/test_setup.py index 25db958..6f848a8 100644 --- a/src/collective/ocrmypdf/tests/test_setup.py +++ b/src/collective/ocrmypdf/tests/test_setup.py @@ -23,24 +23,22 @@ class TestSetup(unittest.TestCase): def setUp(self): """Custom shared utility setup for tests.""" - self.portal = self.layer['portal'] + self.portal = self.layer["portal"] if get_installer: - self.installer = get_installer(self.portal, self.layer['request']) + self.installer = get_installer(self.portal, self.layer["request"]) else: - self.installer = api.portal.get_tool('portal_quickinstaller') + self.installer = api.portal.get_tool("portal_quickinstaller") def test_product_installed(self): """Test if collective.ocrmypdf is installed.""" - self.assertTrue(self.installer.is_product_installed( - 'collective.ocrmypdf')) + self.assertTrue(self.installer.is_product_installed("collective.ocrmypdf")) def test_browserlayer(self): """Test that ICollectiveOcrmypdfLayer is registered.""" from collective.ocrmypdf.interfaces import ICollectiveOcrmypdfLayer from plone.browserlayer import utils - self.assertIn( - ICollectiveOcrmypdfLayer, - utils.registered_layers()) + + self.assertIn(ICollectiveOcrmypdfLayer, utils.registered_layers()) class TestUninstall(unittest.TestCase): @@ -48,23 +46,23 @@ class TestUninstall(unittest.TestCase): layer = COLLECTIVE_OCRMYPDF_INTEGRATION_TESTING def setUp(self): - self.portal = self.layer['portal'] + self.portal = self.layer["portal"] if get_installer: - self.installer = get_installer(self.portal, self.layer['request']) + self.installer = get_installer(self.portal, self.layer["request"]) else: - self.installer = api.portal.get_tool('portal_quickinstaller') + self.installer = api.portal.get_tool("portal_quickinstaller") roles_before = api.user.get_roles(TEST_USER_ID) - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.installer.uninstall_product('collective.ocrmypdf') + setRoles(self.portal, TEST_USER_ID, ["Manager"]) + self.installer.uninstall_product("collective.ocrmypdf") setRoles(self.portal, TEST_USER_ID, roles_before) def test_product_uninstalled(self): """Test if collective.ocrmypdf is cleanly uninstalled.""" - self.assertFalse(self.installer.is_product_installed( - 'collective.ocrmypdf')) + self.assertFalse(self.installer.is_product_installed("collective.ocrmypdf")) def test_browserlayer_removed(self): """Test that ICollectiveOcrmypdfLayer is removed.""" from collective.ocrmypdf.interfaces import ICollectiveOcrmypdfLayer from plone.browserlayer import utils + self.assertNotIn(ICollectiveOcrmypdfLayer, utils.registered_layers()) diff --git a/src/collective/ocrmypdf/tests/test_subscriber_file_modified_ocr.py b/src/collective/ocrmypdf/tests/test_subscriber_file_modified_ocr.py new file mode 100644 index 0000000..76891c1 --- /dev/null +++ b/src/collective/ocrmypdf/tests/test_subscriber_file_modified_ocr.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from collective.ocrmypdf.testing import COLLECTIVE_OCRMYPDF_FUNCTIONAL_TESTING +from collective.ocrmypdf.testing import COLLECTIVE_OCRMYPDF_INTEGRATION_TESTING +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID + +import unittest + + +class SubscriberIntegrationTest(unittest.TestCase): + + layer = COLLECTIVE_OCRMYPDF_INTEGRATION_TESTING + + def setUp(self): + self.portal = self.layer["portal"] + setRoles(self.portal, TEST_USER_ID, ["Manager"]) + + +class SubscriberFunctionalTest(unittest.TestCase): + + layer = COLLECTIVE_OCRMYPDF_FUNCTIONAL_TESTING + + def setUp(self): + self.portal = self.layer["portal"] + setRoles(self.portal, TEST_USER_ID, ["Manager"])