-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.dexterity.interfaces import IDexterityContent | ||
from plone.indexer.decorator import indexer | ||
|
||
|
||
@indexer(IDexterityContent) | ||
def uo_correlata_uid(context, **kw): | ||
""" """ | ||
return [ | ||
x.to_object.UID() | ||
for x in getattr(context.aq_base, "uo_correlata", []) | ||
if x.to_object | ||
] | ||
|
||
|
||
@indexer(IDexterityContent) | ||
def struttura_correlata_uid(context, **kw): | ||
""" """ | ||
return [ | ||
x.to_object.UID() | ||
for x in getattr(context.aq_base, "struttura_correlata", []) | ||
if x.to_object | ||
] |
74 changes: 74 additions & 0 deletions
74
src/iosanita/contenttypes/tests/test_struttura_correlata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Setup tests for this package.""" | ||
from iosanita.contenttypes.testing import INTEGRATION_TESTING | ||
from plone import api | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import TEST_USER_ID | ||
from z3c.relationfield import RelationValue | ||
from zope.component import getUtility | ||
from zope.event import notify | ||
from zope.intid.interfaces import IIntIds | ||
from zope.lifecycleevent import ObjectModifiedEvent | ||
|
||
import unittest | ||
|
||
|
||
class TestStrutturaCorrelata(unittest.TestCase): | ||
"""""" | ||
|
||
layer = INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.app = self.layer["app"] | ||
self.portal = self.layer["portal"] | ||
self.portal_url = self.portal.absolute_url() | ||
setRoles(self.portal, TEST_USER_ID, ["Manager"]) | ||
|
||
intids = getUtility(IIntIds) | ||
|
||
self.struttura1 = api.content.create( | ||
container=self.portal, type="Struttura", title="struttura 1" | ||
) | ||
self.struttura2 = api.content.create( | ||
container=self.portal, type="Struttura", title="struttura 2" | ||
) | ||
self.struttura_test = api.content.create( | ||
container=self.portal, | ||
type="Struttura", | ||
title="Test struttura", | ||
) | ||
self.servizio_test = api.content.create( | ||
container=self.portal, | ||
type="Servizio", | ||
title="Test servizio", | ||
) | ||
self.struttura_test.struttura_correlata = [ | ||
RelationValue(intids.getId(self.struttura1)) | ||
] | ||
self.servizio_test.struttura_correlata = [ | ||
RelationValue(intids.getId(self.struttura1)), | ||
RelationValue(intids.getId(self.struttura2)), | ||
] | ||
notify(ObjectModifiedEvent(self.struttura_test)) | ||
notify(ObjectModifiedEvent(self.servizio_test)) | ||
|
||
def test_struttura_correlata_reference_in_struttura_is_in_catalog(self): | ||
""" """ | ||
res = api.content.find(struttura_correlata_uid=self.struttura1.UID()) | ||
|
||
self.assertEqual(len(res), 2) | ||
uids = [x.UID for x in res] | ||
self.assertIn(self.struttura_test.UID(), uids) | ||
|
||
def test_struttura_correlata_reference_in_servizio_is_in_catalog(self): | ||
""" """ | ||
res = api.content.find(struttura_correlata_uid=self.struttura1.UID()) | ||
|
||
self.assertEqual(len(res), 2) | ||
uids = [x.UID for x in res] | ||
self.assertIn(self.servizio_test.UID(), uids) | ||
|
||
res = api.content.find(struttura_correlata_uid=self.struttura2.UID()) | ||
|
||
self.assertEqual(len(res), 1) | ||
self.assertEqual(self.servizio_test.UID(), res[0].UID) |