Skip to content

Commit

Permalink
Merge 672b82d into 3b2c9e9
Browse files Browse the repository at this point in the history
  • Loading branch information
tisto committed Apr 18, 2017
2 parents 3b2c9e9 + 672b82d commit 018e78e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/plone/restapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from AccessControl import allow_module
from AccessControl.Permissions import add_user_folders
from Products.PluggableAuthService.PluggableAuthService import (
registerMultiPlugin)
from Products.PluggableAuthService.PluggableAuthService import registerMultiPlugin # noqa
from plone.restapi.pas import plugin

import pkg_resources
Expand All @@ -11,27 +10,26 @@

try:
pkg_resources.get_distribution('plone.app.testing')
except pkg_resources.DistributionNotFound:
REGISTER_TEST_TYPES = False
else:
REGISTER_TEST_TYPES = True

except pkg_resources.DistributionNotFound: # pragma: no cover
REGISTER_TEST_TYPES = False

try:
pkg_resources.get_distribution('plone.app.contenttypes')
except pkg_resources.DistributionNotFound:
HAS_PLONE_APP_CONTENTTYPES = False
else:
HAS_PLONE_APP_CONTENTTYPES = True
except pkg_resources.DistributionNotFound: # pragma: no cover
HAS_PLONE_APP_CONTENTTYPES = False


def initialize(context):
registerMultiPlugin(plugin.JWTAuthenticationPlugin.meta_type)
context.registerClass(
plugin.JWTAuthenticationPlugin,
permission=add_user_folders,
constructors=(plugin.manage_addJWTAuthenticationPlugin,
plugin.addJWTAuthenticationPlugin),
constructors=(
plugin.manage_addJWTAuthenticationPlugin,
plugin.addJWTAuthenticationPlugin
),
visibility=None,
)

Expand All @@ -42,7 +40,9 @@ def initialize(context):
from plone.restapi.tests.attypes import PROJECTNAME

content_types, constructors, ftis = process_types(
listTypes(PROJECTNAME), PROJECTNAME)
listTypes(PROJECTNAME),
PROJECTNAME
)

utils.ContentInit(
'%s Content' % PROJECTNAME,
Expand Down
34 changes: 30 additions & 4 deletions src/plone/restapi/tests/test_content_local_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from plone.app.testing import TEST_USER_ID
from plone.app.testing import login
from plone.app.testing import setRoles
from plone.restapi.serializer.local_roles import SerializeLocalRolesToJson
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from zope.component import getGlobalSiteManager

import requests
import transaction
Expand Down Expand Up @@ -117,7 +119,7 @@ def test_set_local_roles_for_user(self):
self.assertEqual(
pas.getLocalRolesForDisplay(self.portal.folder1),
(('admin', ('Owner',), 'user', 'admin'),)
)
)

response = requests.post(
self.portal.folder1.absolute_url() + '/@sharing',
Expand All @@ -142,7 +144,7 @@ def test_set_local_roles_for_user(self):
(('admin', ('Owner',), 'user', 'admin'),
('test-user', (u'Reviewer', u'Reader'),
'user', u'test_user_1_'))
)
)

def test_unset_local_roles_for_user(self):
api.user.grant_roles(username=TEST_USER_ID,
Expand All @@ -155,7 +157,7 @@ def test_unset_local_roles_for_user(self):
pas.getLocalRolesForDisplay(self.portal.folder1),
(('admin', ('Owner',), 'user', 'admin'),
('test-user', ('Reviewer', 'Reader'), 'user', 'test_user_1_'))
)
)

response = requests.post(
self.portal.folder1.absolute_url() + '/@sharing',
Expand All @@ -180,7 +182,7 @@ def test_unset_local_roles_for_user(self):
(('admin', ('Owner',), 'user', 'admin'),
('test-user', (u'Reviewer',),
'user', u'test_user_1_'))
)
)

def test_get_local_roles_inherit_roles(self):
self.portal.folder1.__ac_local_roles_block__ = True
Expand Down Expand Up @@ -243,3 +245,27 @@ def test_get_available_roles(self):
response = response.json()
self.assertIn('available_roles', response)
self.assertIn('Reader', response['available_roles'])

def test_no_serializer_available_returns_501(self):
# This test unregisters the local_roles adapter. The testrunner can
# not auto-revert this on test tearDown. Therefore if we ever run
# into test isolation issues. Start to look here first.
gsm = getGlobalSiteManager()
gsm.unregisterAdapter(SerializeLocalRolesToJson, name='local_roles')

response = requests.get(
self.portal.folder1.absolute_url() + '/@sharing',
headers={'Accept': 'application/json'},
auth=(SITE_OWNER_NAME, SITE_OWNER_PASSWORD),
)

self.assertEqual(response.status_code, 501)
response = response.json()
self.assertIn('error', response)
self.assertEquals(
u'No serializer available.',
response['error']['message']
)

# we need to re-register the adapter here for following tests
gsm.registerAdapter(SerializeLocalRolesToJson, name='local_roles')
27 changes: 27 additions & 0 deletions src/plone/restapi/tests/test_upgrades.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from plone.app.upgrade.utils import loadMigrationProfile
from plone.restapi.testing import PLONE_RESTAPI_DX_INTEGRATION_TESTING
from Products.CMFCore.utils import getToolByName
from unittest import TestCase


class TestUpgrades(TestCase):

layer = PLONE_RESTAPI_DX_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.request = self.layer['request']

def test_migration_profile_to_0002_can_be_loaded(self):
loadMigrationProfile(
self.portal,
'profile-plone.restapi.upgrades:0002'
)
self.assertTrue(True)

def test_run_migration_profile_to_0002(self):
from plone.restapi.upgrades.to0002 import assign_use_api_permission
portal_setup = getToolByName(self.portal, 'portal_setup')
assign_use_api_permission(portal_setup)
self.assertTrue(True)

0 comments on commit 018e78e

Please sign in to comment.