diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt index 6ce2a34..6e1616a 100644 --- a/docs/HISTORY.txt +++ b/docs/HISTORY.txt @@ -1,13 +1,20 @@ Changelog ========= -1.4.6 (unreleased) +1.4.7 (unreleased) ------------------ - Do not use key/value pairs in tipologia_bando and destinatari. [cekk] +1.4.6 (2024-09-09) +------------------ + +- Add effective and modified date to retrieveContentsOfFolderDeepening data. + [cekk] + + 1.4.5 (2024-04-15) ------------------ diff --git a/redturtle/bandi/browser/bando.py b/redturtle/bandi/browser/bando.py index cc2d209..518c945 100644 --- a/redturtle/bandi/browser/bando.py +++ b/redturtle/bandi/browser/bando.py @@ -14,9 +14,9 @@ from zope.interface import Interface from zope.schema.interfaces import IVocabularyFactory - try: from plone.restapi.serializer.utils import uid_to_url + from plone.restapi.serializer.converters import json_compatible HAS_PLONERESTAPI = True except ImportError: @@ -104,11 +104,17 @@ def retrieveContentsOfFolderDeepening(self, path_dfolder): siteid = api.portal.get().getId() for brain in brains: if not brain.getPath() == path_dfolder and not brain.exclude_from_nav: + effective = brain.effective + if effective.year() == 1969: + # content not yet published + effective = None dictfields = dict( title=brain.Title, description=brain.Description, url=brain.getURL(), path=brain.getPath(), + effective=effective, + modified=brain.modified, ) if brain.Type == "Link": dictfields["url"] = brain.getRemoteUrl @@ -128,9 +134,9 @@ def retrieveContentsOfFolderDeepening(self, path_dfolder): elif brain.Type == "File": obj_file = brain.getObject().file if obj_file: - dictfields[ - "url" - ] = f"{brain.getURL()}/@@download/file/{obj_file.filename}" # noqa E501 + dictfields["url"] = ( + f"{brain.getURL()}/@@download/file/{obj_file.filename}" # noqa E501 + ) obj_size = obj_file.size dictfields["filesize"] = self.getSizeString(obj_size) # else: @@ -139,6 +145,9 @@ def retrieveContentsOfFolderDeepening(self, path_dfolder): # icon = getMultiAdapter((self.context, self.request, obj), IContentIcon) # dictfields['icon'] = icon.html_tag() dictfields["type"] = brain.Type + + if HAS_PLONERESTAPI: + dictfields = json_compatible(dictfields) values.append(dictfields) return values diff --git a/redturtle/bandi/testing.py b/redturtle/bandi/testing.py index 6f9ea98..30dab14 100644 --- a/redturtle/bandi/testing.py +++ b/redturtle/bandi/testing.py @@ -1,17 +1,15 @@ # -*- coding: utf-8 -*- from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE -from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE from plone.app.testing import applyProfile from plone.app.testing import FunctionalTesting from plone.app.testing import IntegrationTesting from plone.app.testing import PloneSandboxLayer -from plone.testing import z2 +from plone.testing.zope import WSGI_SERVER_FIXTURE import redturtle.bandi -class RedTurtleBandiLayer(PloneSandboxLayer): - +class TestLayer(PloneSandboxLayer): defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,) def setUpZope(self, app, configurationContext): @@ -21,29 +19,24 @@ def setUpZope(self, app, configurationContext): self.loadZCML(package=redturtle.bandi) def setUpPloneSite(self, portal): - applyProfile(portal, 'redturtle.bandi:default') + applyProfile(portal, "redturtle.bandi:default") -REDTURTLE_BANDI_FIXTURE = RedTurtleBandiLayer() +FIXTURE = TestLayer() -REDTURTLE_BANDI_INTEGRATION_TESTING = IntegrationTesting( - bases=(REDTURTLE_BANDI_FIXTURE,), - name='RedTurtleBandiLayer:IntegrationTesting', +INTEGRATION_TESTING = IntegrationTesting( + bases=(FIXTURE,), + name="RedturtleBandiLayer:IntegrationTesting", ) -REDTURTLE_BANDI_FUNCTIONAL_TESTING = FunctionalTesting( - bases=(REDTURTLE_BANDI_FIXTURE,), - name='RedTurtleBandiLayer:FunctionalTesting', +FUNCTIONAL_TESTING = FunctionalTesting( + bases=(FIXTURE,), + name="RedturtleBandiLayer:FunctionalTesting", ) - -REDTURTLE_BANDI_ACCEPTANCE_TESTING = FunctionalTesting( - bases=( - REDTURTLE_BANDI_FIXTURE, - REMOTE_LIBRARY_BUNDLE_FIXTURE, - z2.ZSERVER_FIXTURE, - ), - name='RedTurtleBandiLayer:AcceptanceTesting', +RESTAPI_TESTING = FunctionalTesting( + bases=(FIXTURE, WSGI_SERVER_FIXTURE), + name="RedturtleBandiLayer:RestAPITesting", ) diff --git a/redturtle/bandi/tests/example.txt b/redturtle/bandi/tests/example.txt new file mode 100644 index 0000000..d6459e0 --- /dev/null +++ b/redturtle/bandi/tests/example.txt @@ -0,0 +1 @@ +xxx diff --git a/redturtle/bandi/tests/test_bando_view.py b/redturtle/bandi/tests/test_bando_view.py index d4896c8..26a49cc 100644 --- a/redturtle/bandi/tests/test_bando_view.py +++ b/redturtle/bandi/tests/test_bando_view.py @@ -1,14 +1,16 @@ # -*- coding: utf-8 -*- -from redturtle.bandi.testing import REDTURTLE_BANDI_INTEGRATION_TESTING from plone import api from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID +from plone.namedfile.file import NamedBlobFile +from redturtle.bandi.testing import INTEGRATION_TESTING +import os import unittest class BandoViewTest(unittest.TestCase): - layer = REDTURTLE_BANDI_INTEGRATION_TESTING + layer = INTEGRATION_TESTING def setUp(self): self.portal = self.layer["portal"] @@ -104,3 +106,31 @@ def test_tipologia_bando_in_right_view(self): ) self.assertIn("Announcement type", view_new()) self.assertIn("Altro", view_new()) + + def test_dates_in_attachments(self): + folder = api.content.create( + container=self.bando, type="Bando Folder Deepening", title="attachments" + ) + + filename = os.path.join(os.path.dirname(__file__), "example.txt") + api.content.create( + container=folder, + type="File", + title="attachment", + file=NamedBlobFile( + data=open(filename, "rb").read(), + filename="example.txt", + contentType="text/plain", + ), + ) + + view = api.content.get_view( + name="bando_view", context=self.bando, request=self.request + ) + data = view.retrieveContentsOfFolderDeepening( + "/".join(folder.getPhysicalPath()) + ) + + self.assertEqual(len(data), 1) + self.assertIn("modified", data[0]) + self.assertIn("effective", data[0]) diff --git a/redturtle/bandi/tests/test_collection_criteria.py b/redturtle/bandi/tests/test_collection_criteria.py index ac34b7d..498f287 100644 --- a/redturtle/bandi/tests/test_collection_criteria.py +++ b/redturtle/bandi/tests/test_collection_criteria.py @@ -4,14 +4,14 @@ from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID from plone.app.testing import TEST_USER_NAME -from redturtle.bandi.testing import REDTURTLE_BANDI_FUNCTIONAL_TESTING +from redturtle.bandi.testing import FUNCTIONAL_TESTING import unittest class TestCollectionCriteria(unittest.TestCase): - layer = REDTURTLE_BANDI_FUNCTIONAL_TESTING + layer = FUNCTIONAL_TESTING def setUp(self): self.portal = self.layer["portal"] @@ -25,7 +25,7 @@ def setUp(self): container=self.portal, type="Bando", title="Bando with destinatari", - destinatari=[u"d1", u"d2", u"dà"], + destinatari=["d1", "d2", "dà"], ) self.bando2 = api.content.create( diff --git a/redturtle/bandi/tests/test_setup.py b/redturtle/bandi/tests/test_setup.py index 3a6e436..e5ef0b0 100644 --- a/redturtle/bandi/tests/test_setup.py +++ b/redturtle/bandi/tests/test_setup.py @@ -5,7 +5,7 @@ from plone.app.testing import TEST_USER_ID from plone.browserlayer import utils from redturtle.bandi.interfaces.browserlayer import IRedturtleBandiLayer -from redturtle.bandi.testing import REDTURTLE_BANDI_INTEGRATION_TESTING +from redturtle.bandi.testing import INTEGRATION_TESTING import unittest @@ -18,19 +18,19 @@ class TestSetup(unittest.TestCase): """Test that redturtle.bandi is properly installed.""" - layer = REDTURTLE_BANDI_INTEGRATION_TESTING + layer = INTEGRATION_TESTING 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 redturtle.bandi is installed.""" - self.assertTrue(self.installer.isProductInstalled('redturtle.bandi')) + self.assertTrue(self.installer.isProductInstalled("redturtle.bandi")) def test_browserlayer(self): """Test that IRedturtleBandiLayer is registered.""" @@ -40,24 +40,23 @@ def test_browserlayer(self): class TestUninstall(unittest.TestCase): - layer = REDTURTLE_BANDI_INTEGRATION_TESTING + layer = 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.uninstallProducts(['redturtle.bandi']) + setRoles(self.portal, TEST_USER_ID, ["Manager"]) + self.installer.uninstallProducts(["redturtle.bandi"]) setRoles(self.portal, TEST_USER_ID, roles_before) def test_product_uninstalled(self): """Test if redturtle.bandi is cleanly uninstalled.""" - self.assertFalse(self.installer.isProductInstalled('redturtle.bandi')) + self.assertFalse(self.installer.isProductInstalled("redturtle.bandi")) def test_browserlayer_removed(self): """Test that IRedturtleBandiLayer is removed.""" self.assertNotIn(IRedturtleBandiLayer, utils.registered_layers()) - diff --git a/setup.py b/setup.py index 72cfddc..16e7d90 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ import os from setuptools import setup, find_packages -version = "1.4.6.dev0" +version = "1.4.7.dev0" setup( name="redturtle.bandi", @@ -56,7 +56,8 @@ "plone.testing>=5.0.0", "plone.app.contenttypes", "plone.app.robotframework[debug]", - ] + "collective.MockMailHost", + ], }, test_suite="redturtle.bandi.tests.test_docs.test_suite", entry_points="""