[slapos_hypermedia] Change Base_getHateoasMaster about 'me' link.

So that it fits ERP5Document_getHateoas style.
parent 68284380
...@@ -90,16 +90,15 @@ portal = context.getPortalObject()\n ...@@ -90,16 +90,15 @@ portal = context.getPortalObject()\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\n if person is not None:\n
result_dict[\'_links\'][\'me\'] = {\n result_dict[\'_links\'][\'me\'] = {\n
"href": "urn:jio:get:%s" % person.getRelativeUrl(),\n "href": "urn:jio:get:%s/ERP5Document_getHateoas" % person.getRelativeUrl(),\n
}\n }\n
\n \n
else:\n else:\n
user = str(portal.portal_membership.getAuthenticatedMember())\n user = str(portal.portal_membership.getAuthenticatedMember())\n
if user != "Anonymous User":\n if user != "Anonymous User":\n
user_document = context.ERP5Site_getUserDocument(user)\n user_document = context.ERP5Site_getUserDocument(user)\n
result_dict[\'_links\'][\'action_object_jump\'] = {\n result_dict[\'_links\'][\'me\'] = {\n
\'href\': \'%s/ERP5Document_getHateoas\' % user_document.absolute_url(),\n \'href\': \'urn:jio:get:%s/ERP5Document_getHateoas\' % user_document.getRelativeUrl(),\n
\'title\': user_document.getPortalType()\n
}\n }\n
\n \n
response.setHeader(\'Content-Type\', mime_type)\n response.setHeader(\'Content-Type\', mime_type)\n
......
...@@ -17,6 +17,14 @@ def hateoasGetLinkFromLinks(links, title): ...@@ -17,6 +17,14 @@ def hateoasGetLinkFromLinks(links, title):
if action.get('title') == title: if action.get('title') == title:
return action return action
def getRelativeUrlFromUrn(urn):
urn_schema = 'urn:jio:get:'
try:
_, url = urn.split(urn_schema)
except ValueError:
return
return url
class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
def _makeUser(self): def _makeUser(self):
...@@ -42,10 +50,8 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -42,10 +50,8 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
"%s:%s" % (erp5_person.getReference(), erp5_person.getReference())) "%s:%s" % (erp5_person.getReference(), erp5_person.getReference()))
content_type = "application/hal+json" content_type = "application/hal+json"
# XXX Default home url. 'Hardcoded' in client.
api_scheme, api_netloc, api_path, api_query, \ api_scheme, api_netloc, api_path, api_query, \
api_fragment = urlparse.urlsplit('%s/Base_getHateoasMaster' % \ api_fragment = urlparse.urlsplit(self.portal.absolute_url())
self.portal.absolute_url())
def getNewHttpConnection(api_netloc): def getNewHttpConnection(api_netloc):
if api_scheme == 'https': if api_scheme == 'https':
...@@ -76,13 +82,17 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -76,13 +82,17 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Fetch the user hal # Fetch the user hal
##################################################### #####################################################
user_link_dict = home_page_hal['_links']['action_object_jump']
user_link_dict = home_page_hal['_links']['me']
self.assertNotEqual(user_link_dict, None) self.assertNotEqual(user_link_dict, None)
me_url = 'http://%s%s/web_site_module/hateoas/%s' % (
api_netloc, api_path, getRelativeUrlFromUrn(user_link_dict['href']))
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'], url=me_url,
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': content_type, 'Accept': content_type,
...@@ -396,10 +406,8 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -396,10 +406,8 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
remote_user = instance.getReference() remote_user = instance.getReference()
content_type = "application/hal+json" content_type = "application/hal+json"
# XXX Default home url. 'Hardcoded' in client.
api_scheme, api_netloc, api_path, api_query, \ api_scheme, api_netloc, api_path, api_query, \
api_fragment = urlparse.urlsplit('%s/Base_getHateoasMaster' % \ api_fragment = urlparse.urlsplit(self.portal.absolute_url())
self.portal.absolute_url())
def getNewHttpConnection(api_netloc): def getNewHttpConnection(api_netloc):
if api_scheme == 'https': if api_scheme == 'https':
...@@ -410,6 +418,7 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -410,6 +418,7 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
##################################################### #####################################################
# Access the master home page hal # Access the master home page hal
##################################################### #####################################################
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method='GET', method='GET',
...@@ -429,13 +438,17 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -429,13 +438,17 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
##################################################### #####################################################
# Fetch the instance hal # Fetch the instance hal
##################################################### #####################################################
user_link_dict = home_page_hal['_links']['action_object_jump']
user_link_dict = home_page_hal['_links']['me']
self.assertNotEqual(user_link_dict, None) self.assertNotEqual(user_link_dict, None)
me_url = str('http://%s%s/web_site_module/hateoas/%s' % (
api_netloc, api_path, getRelativeUrlFromUrn(user_link_dict['href'])))
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'], url=me_url,
headers={ headers={
'REMOTE_USER': remote_user, 'REMOTE_USER': remote_user,
'Accept': content_type, 'Accept': content_type,
...@@ -451,11 +464,11 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -451,11 +464,11 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
# Fetch instance informations # Fetch instance informations
##################################################### #####################################################
request_link_dict = hateoasGetLinkFromLinks( user_link_dict = hateoasGetLinkFromLinks(
instance_hal['_links']['action_object_slap'], instance_hal['_links']['action_object_slap'],
'getHateoasInformation' 'getHateoasInformation'
) )
self.assertNotEqual(request_link_dict, None) self.assertNotEqual(user_link_dict, None)
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
...@@ -476,11 +489,11 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -476,11 +489,11 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
##################################################### #####################################################
# Get instance news # Get instance news
##################################################### #####################################################
request_link_dict = hateoasGetLinkFromLinks( user_link_dict = hateoasGetLinkFromLinks(
instance_hal['_links']['action_object_slap'], instance_hal['_links']['action_object_slap'],
'getHateoasNews' 'getHateoasNews'
) )
self.assertNotEqual(request_link_dict, None) self.assertNotEqual(user_link_dict, None)
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
...@@ -502,15 +515,15 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -502,15 +515,15 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
# Get hosting subscription of instance # Get hosting subscription of instance
##################################################### #####################################################
# XXX can be simpler and doesn't need getHateoasRelatedHostingSubscription script # XXX can be simpler and doesn't need getHateoasRelatedHostingSubscription script
request_link_dict = hateoasGetLinkFromLinks( hosting_link_dict = hateoasGetLinkFromLinks(
instance_hal['_links']['action_object_slap'], instance_hal['_links']['action_object_slap'],
'getHateoasRelatedHostingSubscription' 'getHateoasRelatedHostingSubscription'
) )
self.assertNotEqual(request_link_dict, None) self.assertNotEqual(hosting_link_dict, None)
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=request_link_dict.get('method', 'GET'), method=hosting_link_dict.get('method', 'GET'),
url=request_link_dict['href'], url=hosting_link_dict['href'],
headers={ headers={
'REMOTE_USER': remote_user, 'REMOTE_USER': remote_user,
'Accept': content_type, 'Accept': content_type,
...@@ -526,15 +539,15 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -526,15 +539,15 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
self.tic() self.tic()
request_link_dict = hateoasGetLinkFromLinks( hosting_link_dict = hateoasGetLinkFromLinks(
subscription_hal['_links']['action_object_jump'], subscription_hal['_links']['action_object_jump'],
'Hosting Subscription' 'Hosting Subscription'
) )
self.assertNotEqual(request_link_dict, None) self.assertNotEqual(hosting_link_dict, None)
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=request_link_dict.get('method', 'GET'), method=hosting_link_dict.get('method', 'GET'),
url=request_link_dict['href'], url=hosting_link_dict['href'],
headers={ headers={
'REMOTE_USER': remote_user, 'REMOTE_USER': remote_user,
'Accept': content_type, 'Accept': content_type,
......
...@@ -354,9 +354,8 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin): ...@@ -354,9 +354,8 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
"self": { "self": {
"href": "http://example.org/bar" "href": "http://example.org/bar"
}, },
"action_object_jump": { "me": {
"href": "%s/ERP5Document_getHateoas" % person_user.absolute_url(), "href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(),
"title": "Person"
}, },
}, },
}, indent=2)) }, indent=2))
...@@ -381,9 +380,8 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin): ...@@ -381,9 +380,8 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
"self": { "self": {
"href": "http://example.org/bar" "href": "http://example.org/bar"
}, },
"action_object_jump": { "me": {
"href": "%s/ERP5Document_getHateoas" % self.software_instance.absolute_url(), "href": "urn:jio:get:%s/ERP5Document_getHateoas" % self.software_instance.getRelativeUrl(),
"title": "Software Instance"
}, },
}, },
}, indent=2)) }, indent=2))
......
5 6
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment