-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 changed file
with
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import unittest | ||
|
||
from plone.app.testing import SITE_OWNER_NAME | ||
from plone.app.testing import TEST_USER_ID | ||
from plone.app.testing import login | ||
from plone.app.testing import setRoles | ||
from plone.dexterity.utils import iterSchemata | ||
from plone.restapi.interfaces import IFieldDeserializer | ||
from Products.CMFCore.utils import getToolByName | ||
from zope.component import getMultiAdapter | ||
|
||
from redturtle.volto.testing import REDTURTLE_VOLTO_API_FUNCTIONAL_TESTING | ||
|
||
|
||
class TestDXFieldDeserializer(unittest.TestCase): | ||
layer = REDTURTLE_VOLTO_API_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
# TODO | ||
# testare il deserializer della relazione passando il path dell'oggetto per mostrare che si rompe | ||
# testare il deserializer passando lo UID dell'oggetto per dimostrare che è corretto | ||
self.app = self.layer["app"] | ||
self.request = self.layer["request"] | ||
self.portal = self.layer["portal"] | ||
|
||
self.wftool = getToolByName(self.portal, "portal_workflow") | ||
|
||
# user | ||
setRoles(self.portal, TEST_USER_ID, ["Member"]) | ||
login(self.portal, SITE_OWNER_NAME) | ||
|
||
# folders | ||
self.portal.invokeFactory("Folder", id="folder", title="Private Folder") | ||
self.portal.folder.invokeFactory( | ||
"Folder", id="otherfolder", title="Other Folder" | ||
) | ||
self.wftool.doActionFor(self.portal.otherfolder, "publish") | ||
|
||
def deserialize(self, fieldname, value): | ||
for schema in iterSchemata(self.portal.doc1): | ||
if fieldname in schema: | ||
field = schema.get(fieldname) | ||
break | ||
deserializer = getMultiAdapter( | ||
(field, self.portal.doc1, self.request), IFieldDeserializer | ||
) | ||
return deserializer(value) | ||
|
||
def test_relationlist_deserialization_broke_with_id(self): | ||
# documents | ||
doc1 = self.portal.otherfolder.invokeFactory( | ||
"DXTestDocument", id="doc1", title="Referenceable Document" | ||
) | ||
self.wftool.doActionFor(self.portal.doc1, "publish") | ||
doc2 = self.portal.otherfolder.invokeFactory( | ||
"DXTestDocument", id="doc2", title="Referenceable Document" | ||
) | ||
self.wftool.doActionFor(self.portal.doc2, "publish") | ||
|
||
import pdb | ||
|
||
pdb.set_trace() | ||
|
||
value = self.deserialize( | ||
"test_relationlist_field", | ||
[str(doc1.UID()), str(doc2.UID())], | ||
) |