-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GET/PUT registry_: Replace mock with a basic actual implementation.
- Loading branch information
Showing
6 changed files
with
84 additions
and
6 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
GET /plone/registry_/plone.app.event.first_weekday | ||
GET /plone/registry_/plone.app.querystring.field.path.title | ||
Accept: application/json | ||
|
||
HTTP 200 OK | ||
content-type: application/json | ||
|
||
"value" | ||
"Location" |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PUT /plone/registry_/ | ||
Accept: application/json | ||
|
||
{"key": "value"} | ||
{"plone.app.querystring.field.path.title": "Value"} | ||
|
||
HTTP 204 No Content | ||
|
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 |
---|---|---|
@@ -1,9 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.registry.interfaces import IRegistry | ||
from plone.rest import Service | ||
from zope.component import getUtility | ||
|
||
import json | ||
|
||
|
||
class RegistryUpdate(Service): | ||
|
||
def render(self): | ||
records_to_update = json.loads(self.request.get('BODY', '{}')) | ||
registry = getUtility(IRegistry) | ||
|
||
for key, value in records_to_update.items(): | ||
if key not in registry: | ||
raise Exception( | ||
"This endpoint is only intended to update existing " | ||
"records! Couldn't find key %r" % key) | ||
registry[key] = value | ||
self.request.response.setStatus(204) | ||
return None |
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,51 @@ | ||
# -*- 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.registry import field | ||
from plone.registry.interfaces import IRegistry | ||
from plone.registry.record import Record | ||
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
from plone.restapi.testing import RelativeSession | ||
from zope.component import getUtility | ||
|
||
import transaction | ||
import unittest | ||
|
||
|
||
class TestRegistry(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) | ||
|
||
registry = getUtility(IRegistry) | ||
record = Record(field.TextLine(title=u"Foo Bar"), u"Lorem Ipsum") | ||
registry.records['foo.bar'] = record | ||
transaction.commit() | ||
|
||
def test_get_registry_record(self): | ||
|
||
transaction.commit() | ||
|
||
response = self.api_session.get('/registry_/foo.bar') | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json(), 'Lorem Ipsum') | ||
|
||
def test_update_registry_record(self): | ||
registry = getUtility(IRegistry) | ||
payload = {'foo.bar': 'Lorem Ipsum'} | ||
response = self.api_session.put('/registry_', json=payload) | ||
|
||
self.assertEqual(response.status_code, 204) | ||
self.assertEqual(registry['foo.bar'], 'Lorem Ipsum') |