From 2e7eba0a222c6cf1b5dec0d8a42bb12d912bfd37 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 20 Nov 2023 10:34:21 +0100 Subject: [PATCH] Fix test --- .../plone/ioprenoto/adapters/stringinterp.py | 6 +- .../ioprenoto/tests/test_stringinterp.py | 67 ++++++++----------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/design/plone/ioprenoto/adapters/stringinterp.py b/src/design/plone/ioprenoto/adapters/stringinterp.py index 79b2c44..61f645e 100644 --- a/src/design/plone/ioprenoto/adapters/stringinterp.py +++ b/src/design/plone/ioprenoto/adapters/stringinterp.py @@ -73,10 +73,12 @@ def safe_call(self): next( iter( getattr( - self.context.getPrenotazioniFolder(), "uffici_correlati", [] + self.context.getPrenotazioniFolder(), + "uffici_correlati", + None, ) + or [None] ), - None, ), "to_object", None, diff --git a/src/design/plone/ioprenoto/tests/test_stringinterp.py b/src/design/plone/ioprenoto/tests/test_stringinterp.py index 8e28b88..480927d 100644 --- a/src/design/plone/ioprenoto/tests/test_stringinterp.py +++ b/src/design/plone/ioprenoto/tests/test_stringinterp.py @@ -1,23 +1,19 @@ # -*- coding: utf-8 -*- -from datetime import date -from datetime import datetime -from design.plone.ioprenoto.testing import DESIGN_PLONE_IOPRENOTO_FUNCTIONAL_TESTING +import unittest +from datetime import date, datetime + +import transaction from plone import api -from plone.app.testing import setRoles -from plone.app.testing import TEST_USER_ID +from plone.app.testing import TEST_USER_ID, setRoles from plone.registry.interfaces import IRegistry -from plone.stringinterp.interfaces import IContextWrapper -from plone.stringinterp.interfaces import IStringSubstitution +from plone.stringinterp.interfaces import IContextWrapper, IStringSubstitution from plone.volto.interfaces import IVoltoSettings from redturtle.prenotazioni.adapters.booker import IBooker from z3c.relationfield.relation import RelationValue -from zope.component import getAdapter -from zope.component import getUtility -from zope.component import queryUtility +from zope.component import getAdapter, getUtility, queryUtility from zope.intid.interfaces import IIntIds -import transaction -import unittest +from design.plone.ioprenoto.testing import DESIGN_PLONE_IOPRENOTO_FUNCTIONAL_TESTING class TestStringinterp(unittest.TestCase): @@ -29,6 +25,21 @@ def setUp(self): self.portal_url = self.portal.absolute_url() setRoles(self.portal, TEST_USER_ID, ["Manager"]) + self.unita_organizzativa = api.content.create( + container=self.portal, + type="UnitaOrganizzativa", + title="UO", + ) + self.servizio = api.content.create( + container=self.portal, + type="Servizio", + title="Servizio", + ufficio_responsabile=[ + RelationValue( + to_id=queryUtility(IIntIds).getId(self.unita_organizzativa) + ) + ], + ) self.folder_prenotazioni = api.content.create( container=self.portal, type="PrenotazioniFolder", @@ -36,6 +47,11 @@ def setUp(self): description="", daData=date.today(), gates=["Gate A"], + uffici_correlati=[ + RelationValue( + to_id=queryUtility(IIntIds).getId(self.unita_organizzativa) + ) + ], ) week_table = self.folder_prenotazioni.week_table week_table[0]["morning_start"] = "0700" @@ -70,31 +86,6 @@ def setUp(self): "title": "foo", } ) - self.unita_organizzativa = api.content.create( - container=self.portal, - type="UnitaOrganizzativa", - title="UO", - ) - self.servizio = api.content.create( - container=self.portal, - type="Servizio", - title="Servizio", - ufficio_responsabile=[ - RelationValue( - to_id=queryUtility(IIntIds).getId(self.unita_organizzativa) - ) - ], - ) - self.prenotazioni_folder = api.content.create( - container=self.portal, - type="PrenotazioniFolder", - title="Prenotazioni Folder", - uffici_correlati=[ - RelationValue( - to_id=queryUtility(IIntIds).getId(self.unita_organizzativa) - ) - ], - ) transaction.commit() @@ -151,5 +142,5 @@ def test_unita_organizzativa_title(self): getAdapter( self.prenotazione, IStringSubstitution, "unita_organizzativa_title" )(), - self.folder_prenotazioni.Title(), + self.unita_organizzativa.Title(), )