Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
eikichi18 committed Dec 27, 2023
1 parent 1e381ba commit 7524112
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/redturtle/volto/tests/test_dxfield_deserializer.py
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())],
)

0 comments on commit 7524112

Please sign in to comment.