Skip to content

Commit

Permalink
Merge branch 'master' into fix_indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk authored Sep 9, 2024
2 parents 8e150ea + 64a7d16 commit 059ff7e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 46 deletions.
9 changes: 8 additions & 1 deletion docs/HISTORY.txt
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
17 changes: 13 additions & 4 deletions redturtle/bandi/browser/bando.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
33 changes: 13 additions & 20 deletions redturtle/bandi/testing.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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",
)
1 change: 1 addition & 0 deletions redturtle/bandi/tests/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xxx
34 changes: 32 additions & 2 deletions redturtle/bandi/tests/test_bando_view.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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])
6 changes: 3 additions & 3 deletions redturtle/bandi/tests/test_collection_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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(
Expand Down
27 changes: 13 additions & 14 deletions redturtle/bandi/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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."""
Expand All @@ -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())

5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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="""
Expand Down

0 comments on commit 059ff7e

Please sign in to comment.