Skip to content

Commit

Permalink
renamed default folders and uo field
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Aug 18, 2024
1 parent bc13d1e commit c9553e6
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 48 deletions.
65 changes: 39 additions & 26 deletions src/iosanita/contenttypes/events/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"Documento": {
"content": [
{
"id": "multimedia",
"title": "Multimedia",
"id": "immagini",
"title": "Immagini",
"type": "Document",
"allowed_types": ("Image",),
"allowed_types": ("Image", "Link"),
},
],
},
Expand All @@ -49,7 +49,7 @@
},
{
"id": "documenti",
"title": "Allegati",
"title": "Documenti",
"allowed_types": ("File",),
"publish": True,
},
Expand All @@ -58,20 +58,19 @@
"News Item": {
"content": [
{
"id": "multimedia",
"title": "Multimedia",
"allowed_types": (
"Image",
"Link",
),
"id": "immagini",
"title": "Immagini",
"allowed_types": ("Image", "Link"),
},
{
"id": "video",
"title": "Video",
"allowed_types": ("Link",),
},
{
"id": "documenti-allegati",
"title": "Documenti allegati",
"allowed_types": (
"File",
"Image",
),
"id": "documenti",
"title": "Documenti",
"allowed_types": ("File",),
},
],
},
Expand All @@ -83,14 +82,19 @@
"allowed_types": ("File",),
},
{
"id": "multimedia",
"title": "Multimedia",
"allowed_types": ("Image",),
"id": "immagini",
"title": "Immagini",
"allowed_types": ("Image", "Link"),
},
{
"id": "altri-documenti",
"title": "Altri documenti",
"allowed_types": ("File", "Image", "Link"),
"id": "video",
"title": "Video",
"allowed_types": ("Link",),
},
{
"id": "documenti",
"title": "Documenti",
"allowed_types": ("File",),
},
],
"allowed_types": [],
Expand All @@ -102,12 +106,16 @@
"title": "Modulistica",
"allowed_types": ("Link",),
},
{"id": "allegati", "title": "Allegati", "allowed_types": ("File", "Link")},
{
"id": "documenti",
"title": "Documenti",
"allowed_types": ("File",),
},
],
},
"UnitaOrganizzativa": {
"content": [
{"id": "allegati", "title": "Allegati", "allowed_types": ("File",)},
{"id": "documenti", "title": "Documenti", "allowed_types": ("File",)},
],
},
"Step": {
Expand All @@ -119,8 +127,13 @@
"content": [
{"id": "documenti", "title": "Documenti", "allowed_types": ("File",)},
{
"id": "multimedia",
"title": "Multimedia",
"id": "immagini",
"title": "Immagini",
"allowed_types": ("Image", "Link"),
},
{
"id": "video",
"title": "Video",
"allowed_types": ("Link",),
},
],
Expand Down
10 changes: 5 additions & 5 deletions src/iosanita/contenttypes/interfaces/unita_organizzativa.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class IUnitaOrganizzativa(model.Schema):
required=True,
)

documenti = RelationList(
title=_("documenti_label", default="Documenti"),
documento_correlato = RelationList(
title=_("documento_correlato_label", default="Documenti"),
default=[],
description=_(
"documenti_help",
"documento_correlato_help",
default="Seleziona dei documenti correlati.",
),
value_type=RelationChoice(vocabulary="plone.app.vocabularies.Catalog"),
Expand Down Expand Up @@ -90,7 +90,7 @@ class IUnitaOrganizzativa(model.Schema):

#  custom widgets
form.widget(
"documenti",
"documento_correlato",
RelatedItemsFieldWidget,
vocabulary="plone.app.vocabularies.Catalog",
pattern_options={
Expand Down Expand Up @@ -149,7 +149,7 @@ class IUnitaOrganizzativa(model.Schema):
model.fieldset(
"documenti",
label=_("documenti_label", default="Documenti"),
fields=["documenti"],
fields=["documento_correlato"],
)
model.fieldset(
"servizi",
Expand Down
11 changes: 11 additions & 0 deletions src/iosanita/contenttypes/tests/test_ct_bando.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import RelativeSession
from zope.interface import alsoProvides
from Products.CMFPlone.interfaces import ISelectableConstrainTypes

import unittest

Expand Down Expand Up @@ -181,6 +182,16 @@ def test_bando_default_children(self):
self.assertEqual("Bando Folder Deepening", bando.graduatoria.portal_type)
self.assertEqual("Bando Folder Deepening", bando.documenti.portal_type)

def test_bando_graduatoria_has_no_filtered_addable_types(self):
bando = api.content.create(container=self.portal, type="Bando", title="xxx")
graduatoria = ISelectableConstrainTypes(bando["graduatoria"])
self.assertEqual(graduatoria.getConstrainTypesMode(), 0)

def test_bando_documenti_has_no_filtered_addable_types(self):
bando = api.content.create(container=self.portal, type="Bando", title="xxx")
documenti = ISelectableConstrainTypes(bando["documenti"])
self.assertEqual(documenti.getConstrainTypesMode(), 0)

def test_bando_default_children_disabled_with_marker_interface(self):
alsoProvides(self.request, IoSanitaMigrationMarker)
uo = api.content.create(container=self.portal, type="Bando", title="xxx")
Expand Down
30 changes: 30 additions & 0 deletions src/iosanita/contenttypes/tests/test_ct_documento.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
"""Setup tests for this package."""
from iosanita.contenttypes.testing import RESTAPI_TESTING
from iosanita.contenttypes.testing import INTEGRATION_TESTING
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import RelativeSession
from Products.CMFPlone.interfaces import ISelectableConstrainTypes

import unittest

Expand Down Expand Up @@ -145,3 +147,31 @@ def test_documento_fields_a_chi_si_rivolge_fieldset(self):
resp["fieldsets"][3]["fields"],
["a_chi_si_rivolge", "a_chi_si_rivolge_tassonomia"],
)


class TestDocumento(unittest.TestCase):
""""""

layer = INTEGRATION_TESTING

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.request = self.layer["request"]
self.portal_url = self.portal.absolute_url()
setRoles(self.portal, TEST_USER_ID, ["Manager"])

def test_documento_default_children(self):
documento = api.content.create(
container=self.portal, type="Documento", title="xxx"
)

self.assertEqual(documento.keys(), ["immagini"])

def test_documento_immagini_has_filtered_addable_types(self):
documento = api.content.create(
container=self.portal, type="Documento", title="xxx"
)
immagini = ISelectableConstrainTypes(documento["immagini"])
self.assertEqual(immagini.getConstrainTypesMode(), 1)
self.assertEqual(immagini.getLocallyAllowedTypes(), ["Link", "Image"])
25 changes: 25 additions & 0 deletions src/iosanita/contenttypes/tests/test_ct_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import RelativeSession
from zope.interface import alsoProvides
from Products.CMFPlone.interfaces import ISelectableConstrainTypes

import unittest

Expand Down Expand Up @@ -256,3 +257,27 @@ def test_event_default_children_disabled_with_marker_interface(self):
uo = api.content.create(container=self.portal, type="Event", title="xxx")

self.assertEqual(len(uo.keys()), 0)

def test_event_immagini_has_filtered_addable_types(self):
event = api.content.create(container=self.portal, type="Event", title="xxx")
immagini = ISelectableConstrainTypes(event["immagini"])
self.assertEqual(immagini.getConstrainTypesMode(), 1)
self.assertEqual(immagini.getLocallyAllowedTypes(), ["Link", "Image"])

def test_event_video_has_filtered_addable_types(self):
event = api.content.create(container=self.portal, type="Event", title="xxx")
video = ISelectableConstrainTypes(event["video"])
self.assertEqual(video.getConstrainTypesMode(), 1)
self.assertEqual(video.getLocallyAllowedTypes(), ["Link"])

def test_event_sponsor_has_filtered_addable_types(self):
event = api.content.create(container=self.portal, type="Event", title="xxx")
sponsor = ISelectableConstrainTypes(event["sponsor-evento"])
self.assertEqual(sponsor.getConstrainTypesMode(), 1)
self.assertEqual(sponsor.getLocallyAllowedTypes(), ["Link"])

def test_event_documenti_has_filtered_addable_types(self):
event = api.content.create(container=self.portal, type="Event", title="xxx")
documenti = ISelectableConstrainTypes(event["documenti"])
self.assertEqual(documenti.getConstrainTypesMode(), 1)
self.assertEqual(documenti.getLocallyAllowedTypes(), ["File"])
26 changes: 23 additions & 3 deletions src/iosanita/contenttypes/tests/test_ct_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from plone.restapi.testing import RelativeSession
from zope.component import queryMultiAdapter
from zope.interface import alsoProvides
from Products.CMFPlone.interfaces import ISelectableConstrainTypes

import unittest

Expand Down Expand Up @@ -147,10 +148,29 @@ def setUp(self):
def test_news_default_children(self):
news = api.content.create(container=self.portal, type="News Item", title="xxx")

self.assertEqual(news.keys(), ["multimedia", "documenti-allegati"])
self.assertEqual(news.keys(), ["immagini", "video", "documenti"])

self.assertEqual("Document", news["multimedia"].portal_type)
self.assertEqual("Document", news["documenti-allegati"].portal_type)
self.assertEqual("Document", news["immagini"].portal_type)
self.assertEqual("Document", news["video"].portal_type)
self.assertEqual("Document", news["documenti"].portal_type)

def test_news_immagini_has_filtered_addable_types(self):
news = api.content.create(container=self.portal, type="News Item", title="xxx")
immagini = ISelectableConstrainTypes(news["immagini"])
self.assertEqual(immagini.getConstrainTypesMode(), 1)
self.assertEqual(immagini.getLocallyAllowedTypes(), ["Link", "Image"])

def test_news_video_has_filtered_addable_types(self):
news = api.content.create(container=self.portal, type="News Item", title="xxx")
video = ISelectableConstrainTypes(news["video"])
self.assertEqual(video.getConstrainTypesMode(), 1)
self.assertEqual(video.getLocallyAllowedTypes(), ["Link"])

def test_news_documenti_has_filtered_addable_types(self):
news = api.content.create(container=self.portal, type="News Item", title="xxx")
documenti = ISelectableConstrainTypes(news["documenti"])
self.assertEqual(documenti.getConstrainTypesMode(), 1)
self.assertEqual(documenti.getLocallyAllowedTypes(), ["File"])

def test_news_default_children_disabled_with_marker_interface(self):
alsoProvides(self.request, IoSanitaMigrationMarker)
Expand Down
31 changes: 28 additions & 3 deletions src/iosanita/contenttypes/tests/test_ct_persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from plone.dexterity.utils import createContentInContainer
from plone.restapi.testing import RelativeSession
from zope.interface import alsoProvides
from Products.CMFPlone.interfaces import ISelectableConstrainTypes

import unittest

Expand Down Expand Up @@ -219,11 +220,35 @@ def test_persona_default_children(self):
persona = self.portal["dr-doe-john"]

self.assertEqual(
persona.keys(), ["curriculum-vitae", "multimedia", "altri-documenti"]
persona.keys(), ["curriculum-vitae", "immagini", "video", "documenti"]
)

def test_persona_immagini_has_filtered_addable_types(self):
persona = api.content.create(container=self.portal, type="Persona", title="xxx")
immagini = ISelectableConstrainTypes(persona["immagini"])
self.assertEqual(immagini.getConstrainTypesMode(), 1)
self.assertEqual(immagini.getLocallyAllowedTypes(), ["Link", "Image"])

def test_persona_video_has_filtered_addable_types(self):
persona = api.content.create(container=self.portal, type="Persona", title="xxx")
video = ISelectableConstrainTypes(persona["video"])
self.assertEqual(video.getConstrainTypesMode(), 1)
self.assertEqual(video.getLocallyAllowedTypes(), ["Link"])

def test_persona_curriculum_has_filtered_addable_types(self):
persona = api.content.create(container=self.portal, type="Persona", title="xxx")
curriculum = ISelectableConstrainTypes(persona["curriculum-vitae"])
self.assertEqual(curriculum.getConstrainTypesMode(), 1)
self.assertEqual(curriculum.getLocallyAllowedTypes(), ["File"])

def test_persona_documenti_has_filtered_addable_types(self):
persona = api.content.create(container=self.portal, type="Persona", title="xxx")
documenti = ISelectableConstrainTypes(persona["documenti"])
self.assertEqual(documenti.getConstrainTypesMode(), 1)
self.assertEqual(documenti.getLocallyAllowedTypes(), ["File"])

def test_persona_default_children_disabled_with_marker_interface(self):
alsoProvides(self.request, IoSanitaMigrationMarker)
uo = api.content.create(container=self.portal, type="Persona", title="xxx")
persona = api.content.create(container=self.portal, type="Persona", title="xxx")

self.assertEqual(len(uo.keys()), 0)
self.assertEqual(len(persona.keys()), 0)
19 changes: 18 additions & 1 deletion src/iosanita/contenttypes/tests/test_ct_servizio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import RelativeSession
from zope.interface import alsoProvides
from Products.CMFPlone.interfaces import ISelectableConstrainTypes

import unittest

Expand Down Expand Up @@ -252,10 +253,26 @@ def test_servizio_default_children(self):
container=self.portal, type="Servizio", title="xxx"
)

self.assertEqual(servizio.keys(), ["modulistica", "allegati"])
self.assertEqual(servizio.keys(), ["modulistica", "documenti"])

def test_servizio_default_children_disabled_with_marker_interface(self):
alsoProvides(self.request, IoSanitaMigrationMarker)
uo = api.content.create(container=self.portal, type="Servizio", title="xxx")

self.assertEqual(len(uo.keys()), 0)

def test_servizio_modulistica_has_filtered_addable_types(self):
servizio = api.content.create(
container=self.portal, type="Servizio", title="xxx"
)
modulistica = ISelectableConstrainTypes(servizio["modulistica"])
self.assertEqual(modulistica.getConstrainTypesMode(), 1)
self.assertEqual(modulistica.getLocallyAllowedTypes(), ["Link"])

def test_servizio_documenti_has_filtered_addable_types(self):
servizio = api.content.create(
container=self.portal, type="Servizio", title="xxx"
)
documenti = ISelectableConstrainTypes(servizio["documenti"])
self.assertEqual(documenti.getConstrainTypesMode(), 1)
self.assertEqual(documenti.getLocallyAllowedTypes(), ["File"])
Loading

0 comments on commit c9553e6

Please sign in to comment.