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