Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolveuid in blocks functional test (#865)
* Add functional resolveuid test that proves we do not store a resolveUID link in the database. * Add second assert to test the doc itself not just the response. * Fix Plone 4.3 on Travis. * fix block serializer for resolveuid * make tests broke for Timo ;) * Do not check the serialized output which does not contain the resolveUID. Co-authored-by: Andrea Cecchi <andrea.cecchi85@gmail.com>
- Loading branch information
Showing
4 changed files
with
162 additions
and
2 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
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,104 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.app.testing import login | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import TEST_USER_ID | ||
from plone.app.testing import TEST_USER_NAME | ||
from plone.app.testing import SITE_OWNER_NAME | ||
from plone.app.testing import SITE_OWNER_PASSWORD | ||
from plone.dexterity.fti import DexterityFTI | ||
from plone.restapi.behaviors import IBlocks | ||
from plone.uuid.interfaces import IUUID | ||
|
||
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
from plone.restapi.testing import RelativeSession | ||
from zope.interface import alsoProvides | ||
|
||
import transaction | ||
import unittest | ||
|
||
|
||
class TestResolveUIDFunctional(unittest.TestCase): | ||
|
||
layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer["portal"] | ||
self.request = self.layer["request"] | ||
login(self.portal, TEST_USER_NAME) | ||
setRoles(self.portal, TEST_USER_ID, ["Manager"]) | ||
fti = DexterityFTI("blockspage") | ||
self.portal.portal_types._setObject("blockspage", fti) | ||
fti.klass = "plone.dexterity.content.Container" | ||
fti.behaviors = ("volto.blocks",) | ||
self.fti = fti | ||
alsoProvides(self.request, IBlocks) | ||
self.portal_url = self.portal.absolute_url() | ||
|
||
self.api_session = RelativeSession(self.portal_url) | ||
self.api_session.headers.update({"Accept": "application/json"}) | ||
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) | ||
|
||
self.portal.invokeFactory("Document", id="target", title="Target") | ||
self.target = self.portal.target | ||
self.target_uuid = IUUID(self.target) | ||
|
||
transaction.commit() | ||
|
||
def tearDown(self): | ||
self.api_session.close() | ||
|
||
def test_resolveuid(self): | ||
self.api_session.post( | ||
"/", | ||
json={ | ||
"title": "Document", | ||
"@type": "blockspage", | ||
"blocks": { | ||
"ca5908a5-3f58-4cd5-beb7-9bd1539d6744": {"@type": "title"}, | ||
"791bf004-7c88-4278-8490-13b85c3fa4b4": { | ||
"@type": "text", | ||
"text": { | ||
"blocks": [ | ||
{ | ||
"key": "3bnq6", | ||
"text": "Link", | ||
"type": "unstyled", | ||
"depth": 0, | ||
"inlineStyleRanges": [], | ||
"entityRanges": [ | ||
{"offset": 0, "length": 4, "key": 0} | ||
], | ||
"data": {}, | ||
} | ||
], | ||
"entityMap": { | ||
"0": { | ||
"type": "LINK", | ||
"mutability": "MUTABLE", | ||
"data": { | ||
"url": "http://localhost:55001/plone/target" | ||
}, | ||
} | ||
}, | ||
}, | ||
}, | ||
}, | ||
"blocks_layout": { | ||
"items": [ | ||
"ca5908a5-3f58-4cd5-beb7-9bd1539d6744", | ||
"791bf004-7c88-4278-8490-13b85c3fa4b4", | ||
] | ||
}, | ||
}, | ||
) | ||
transaction.commit() | ||
self.assertEqual( | ||
"../resolveuid/{}".format(self.target_uuid), | ||
self.portal.document.blocks | ||
.get("791bf004-7c88-4278-8490-13b85c3fa4b4") | ||
.get("text") | ||
.get("entityMap") | ||
.get("0") | ||
.get("data") | ||
.get("url"), | ||
) |