Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Oct 29, 2019
1 parent db34b4e commit cdf60ba
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 113 deletions.
18 changes: 9 additions & 9 deletions src/plone/restapi/deserializer/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ def __call__(self, validate_all=False):
data["ordering"]["subset_ids"] = self.context.contentIds()
self.handle_ordering(data)

# Volto Tiles on the Plone Site root faker
if "tiles" in data:
if not getattr(self.context, "tiles", False):
# Volto Blocks on the Plone Site root faker
if "blocks" in data:
if not getattr(self.context, "blocks", False):
self.context.manage_addProperty(
"tiles", json.dumps(data["tiles"]), "string"
"blocks", json.dumps(data["blocks"]), "string"
) # noqa
else:
self.context.manage_changeProperties(
tiles=json.dumps(data["tiles"])
blocks=json.dumps(data["blocks"])
) # noqa

if "tiles_layout" in data:
if not getattr(self.context, "tiles_layout", False):
if "blocks_layout" in data:
if not getattr(self.context, "blocks_layout", False):
self.context.manage_addProperty(
"tiles_layout", json.dumps(data["tiles_layout"]), "string"
"blocks_layout", json.dumps(data["blocks_layout"]), "string"
) # noqa
else:
self.context.manage_changeProperties(
tiles_layout=json.dumps(data["tiles_layout"])
blocks_layout=json.dumps(data["blocks_layout"])
) # noqa

if "title" in data:
Expand Down
6 changes: 3 additions & 3 deletions src/plone/restapi/serializer/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def __call__(self, version=None):
"parent": {},
"is_folderish": True,
"description": self.context.description,
"tiles": json.loads(getattr(self.context, "tiles", "{}")),
"tiles_layout": json.loads(
getattr(self.context, "tiles_layout", "{}")
"blocks": json.loads(getattr(self.context, "blocks", "{}")),
"blocks_layout": json.loads(
getattr(self.context, "blocks_layout", "{}")
), # noqa
}

Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def getNonInstallableProfiles(self): # pragma: no cover
return [
u"plone.restapi:performance",
u"plone.restapi:testing",
u"plone.restapi:tiles",
u"plone.restapi:blocks",
u"plone.restapi:uninstall",
]

Expand Down
12 changes: 6 additions & 6 deletions src/plone/restapi/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ class PloneRestApIBlocksLayer(PloneSandboxLayer):
defaultBases = (PLONE_RESTAPI_DX_FIXTURE,)

def setUpPloneSite(self, portal):
applyProfile(portal, "plone.restapi:tiles")
applyProfile(portal, "plone.restapi:blocks")


PLONE_RESTAPI_TILES_FIXTURE = PloneRestApIBlocksLayer()
PLONE_RESTAPI_TILES_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_RESTAPI_TILES_FIXTURE,), name="PloneRestApIBlocksLayer:Integration"
PLONE_RESTAPI_BLOCKS_FIXTURE = PloneRestApIBlocksLayer()
PLONE_RESTAPI_BLOCKS_INTEGRATION_TESTING = IntegrationTesting(
bases=(PLONE_RESTAPI_BLOCKS_FIXTURE,), name="PloneRestApIBlocksLayer:Integration"
)
PLONE_RESTAPI_TILES_FUNCTIONAL_TESTING = FunctionalTesting(
bases=(PLONE_RESTAPI_TILES_FIXTURE, z2.ZSERVER_FIXTURE),
PLONE_RESTAPI_BLOCKS_FUNCTIONAL_TESTING = FunctionalTesting(
bases=(PLONE_RESTAPI_BLOCKS_FIXTURE, z2.ZSERVER_FIXTURE),
name="PloneRestApIBlocksLayer:Functional",
)

Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/jwt_logged_in.resp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Content-Type: application/json
},
"@id": "http://localhost:55001/plone/",
"@type": "Plone Site",
"blocks": {},
"blocks_layout": {},
"description": "",
"id": "plone",
"is_folderish": true,
Expand All @@ -29,7 +31,5 @@ Content-Type: application/json
],
"items_total": 1,
"parent": {},
"tiles": {},
"tiles_layout": {},
"title": "Plone site"
}
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/siteroot.resp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Content-Type: application/json
},
"@id": "http://localhost:55001/plone",
"@type": "Plone Site",
"blocks": {},
"blocks_layout": {},
"description": "",
"id": "plone",
"is_folderish": true,
Expand All @@ -29,7 +31,5 @@ Content-Type: application/json
],
"items_total": 1,
"parent": {},
"tiles": {},
"tiles_layout": {},
"title": "Plone site"
}
18 changes: 9 additions & 9 deletions src/plone/restapi/tests/test_behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import unittest


class TestTilesBehavior(unittest.TestCase):
class TestBlocksBehavior(unittest.TestCase):

layer = PLONE_RESTAPI_DX_INTEGRATION_TESTING

Expand All @@ -20,31 +20,31 @@ def setUp(self):
self.request = self.layer["request"]
login(self.portal, TEST_USER_NAME)
setRoles(self.portal, TEST_USER_ID, ["Manager"])
fti = DexterityFTI("tiledfolder")
self.portal.portal_types._setObject("tiledfolder", fti)
fti = DexterityFTI("blocksfolder")
self.portal.portal_types._setObject("blocksfolder", fti)
fti.klass = "plone.dexterity.content.Container"
fti.behaviors = ("plone.tiles",)
fti.behaviors = ("plone.restapi.behaviors.IBlocks",)
self.fti = fti
alsoProvides(self.request, IBlocks)

def test_basic_fields(self):
self.portal.invokeFactory(
"tiledfolder", id="tiledfolder", title=u"Folder with tiles"
"blocksfolder", id="blocksfolder", title=u"Folder with blocks"
)

self.portal["tiledfolder"].tiles = {
self.portal["blocksfolder"].blocks = {
"uuid1": {"@type": "title"},
"uuid2": {"@type": "description"},
}

self.portal["tiledfolder"].tiles_layout = {
self.portal["blocksfolder"].blocks_layout = {
"uuid1": {"@type": "title"},
"uuid2": {"@type": "description"},
}

def test_behavior_provides(self):
self.portal.invokeFactory(
"tiledfolder", id="tiledfolder", title=u"Folder with tiles"
"blocksfolder", id="blocksfolder", title=u"Folder with blocks"
)

IBlocks.providedBy(self.portal["tiledfolder"])
IBlocks.providedBy(self.portal["blocksfolder"])
99 changes: 99 additions & 0 deletions src/plone/restapi/tests/test_content_blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.utils import createContentInContainer
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession
from zope.component import queryUtility

import transaction
import unittest


class TestContentBlocks(unittest.TestCase):

layer = PLONE_RESTAPI_DX_FUNCTIONAL_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"])

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)

fti = queryUtility(IDexterityFTI, name="Document")
behavior_list = [a for a in fti.behaviors]
behavior_list.append("plone.restapi.behaviors.IBlocks")
behavior_list.append("plone.leadimage")
fti.behaviors = tuple(behavior_list)

self.doc = createContentInContainer(
self.portal, u"Document", id=u"doc", title=u"A document"
)
transaction.commit()

def tearDown(self):
self.api_session.close()

def test_patch_blocks_list(self):
response = self.api_session.patch(
"/doc",
json={
"blocks": {
"uuid1": {"@type": "title"},
"uuid2": {"@type": "description"},
}
},
)

self.assertEqual(response.status_code, 204)

response = self.api_session.get("/doc")
response = response.json()

self.assertEqual(
response["blocks"],
{"uuid1": {"@type": "title"}, "uuid2": {"@type": "description"}},
)

def test_patch_blocks_layout(self):
response = self.api_session.patch(
"/doc", json={"blocks_layout": {"items": ["#uuid1", "#uuid2"]}}
)

self.assertEqual(response.status_code, 204)

response = self.api_session.get("/doc")
response = response.json()

self.assertEqual(response["blocks_layout"], {"items": ["#uuid1", "#uuid2"]})

def test_get_blocks_layout_schema(self):
response = self.api_session.get("/@types/Document")

self.assertEqual(response.status_code, 200)
response = response.json()

# These are not failing because the patch operations doesn't validate
# fields right now
# def test_patch_blocks_list_wrong_type(self):
# response = self.api_session.patch(
# '/doc',
# json={
# "blocks": [{'uuid1': {'@type': 'title'}}]
# })
# self.assertEqual(response.status_code, 500)

# def test_patch_blocks_layout_wrong_type(self):
# response = self.api_session.patch(
# '/doc',
# json={
# "blocks_layout": {'uuid1': {'@type': 'title'}}
# })
# self.assertEqual(response.status_code, 500)
12 changes: 6 additions & 6 deletions src/plone/restapi/tests/test_profile_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import TEST_USER_ID
from plone.restapi.behaviors import IBlocks
from plone.restapi.testing import PLONE_RESTAPI_TILES_INTEGRATION_TESTING
from plone.restapi.testing import PLONE_RESTAPI_BLOCKS_INTEGRATION_TESTING
from Products.CMFCore.utils import getToolByName

import unittest


class TestProfileTiles(unittest.TestCase):
class TestProfileBlocks(unittest.TestCase):

layer = PLONE_RESTAPI_TILES_INTEGRATION_TESTING
layer = PLONE_RESTAPI_BLOCKS_INTEGRATION_TESTING

def setUp(self):
self.app = self.layer["app"]
Expand All @@ -21,11 +21,11 @@ def setUp(self):
setRoles(self.portal, TEST_USER_ID, ["Member"])
login(self.portal, SITE_OWNER_NAME)

def test_document_type_has_tiles_behavior_enabled(self):
def test_document_type_has_blocks_behavior_enabled(self):
self.portal.invokeFactory(
"Document", id="tileddoc", title="Document with Tiles"
"Document", id="blocksdoc", title="Document with blocks"
)
IBlocks.providedBy(self.portal["tileddoc"])
IBlocks.providedBy(self.portal["blocksdoc"])

def test_plone_restapi_base_profile_applied(self):
uf = getToolByName(self.portal, "acl_users")
Expand Down
20 changes: 10 additions & 10 deletions src/plone/restapi/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,25 +330,25 @@ def test_serialize_returns_site_root_common(self):
self.assertIn("title", self.serialize(self.portal))
self.assertIn("description", self.serialize(self.portal))

def test_serialize_returns_site_root_opt_in_tiles_not_present(self):
self.assertEqual(self.serialize(self.portal)["tiles"], {})
self.assertEqual(self.serialize(self.portal)["tiles_layout"], {})
def test_serialize_returns_site_root_opt_in_blocks_not_present(self):
self.assertEqual(self.serialize(self.portal)["blocks"], {})
self.assertEqual(self.serialize(self.portal)["blocks_layout"], {})

def test_serialize_returns_site_root_opt_in_tiles_present(self):
tiles = {
def test_serialize_returns_site_root_opt_in_blocks_present(self):
blocks = {
"0358abe2-b4f1-463d-a279-a63ea80daf19": {"@type": "description"},
"07c273fc-8bfc-4e7d-a327-d513e5a945bb": {"@type": "title"},
}
tiles_layout = {
blocks_layout = {
"items": [
"07c273fc-8bfc-4e7d-a327-d513e5a945bb",
"0358abe2-b4f1-463d-a279-a63ea80daf19",
]
}
self.portal.manage_addProperty("tiles", json.dumps(tiles), "string")
self.portal.manage_addProperty("blocks", json.dumps(blocks), "string")
self.portal.manage_addProperty(
"tiles_layout", json.dumps(tiles_layout), "string"
"blocks_layout", json.dumps(blocks_layout), "string"
)

self.assertEqual(self.serialize(self.portal)["tiles"], tiles)
self.assertEqual(self.serialize(self.portal)["tiles_layout"], tiles_layout)
self.assertEqual(self.serialize(self.portal)["blocks"], blocks)
self.assertEqual(self.serialize(self.portal)["blocks_layout"], blocks_layout)

0 comments on commit cdf60ba

Please sign in to comment.