[slapos_hypermedia] Base_getHateoasMaster extends ERP5Document_getHateoas +...

[slapos_hypermedia] Base_getHateoasMaster extends ERP5Document_getHateoas + all URNs return resource, not script.
parent 9484b049
...@@ -67,30 +67,14 @@ elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n ...@@ -67,30 +67,14 @@ elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
return ""\n return ""\n
\n \n
import json\n import json\n
result_dict = {\n result_dict = json.loads(context.ERP5Document_getHateoas(REQUEST))\n
# \'title\': \'Vifib SlapOS Master\',\n
# \'description\': \'Reference implementation of the SlapOS Master specifications.\',\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# "http://slapos.org/reg/edit": {\n
# "href": "/edit",\n
# "method": "PUT",\n
# "type": "application/json; class=slapos.org.master",\n
# },\n
# "http://slapos.org/reg/create": {\n
# "href": "/new",\n
# "method": "POST",\n
# "type": "application/json; class=slapos.org.person",\n
# },\n
},\n
}\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \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/ERP5Document_getHateoas" % person.getRelativeUrl(),\n "href": "urn:jio:get:%s" % person.getRelativeUrl(),\n
}\n }\n
\n \n
else:\n else:\n
...@@ -98,7 +82,7 @@ else:\n ...@@ -98,7 +82,7 @@ else:\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\'][\'me\'] = {\n result_dict[\'_links\'][\'me\'] = {\n
\'href\': \'urn:jio:get:%s/ERP5Document_getHateoas\' % user_document.getRelativeUrl(),\n \'href\': \'urn:jio:get:%s\' % user_document.getRelativeUrl(),\n
}\n }\n
\n \n
response.setHeader(\'Content-Type\', mime_type)\n response.setHeader(\'Content-Type\', mime_type)\n
......
...@@ -73,7 +73,7 @@ result_dict = {\n ...@@ -73,7 +73,7 @@ result_dict = {\n
\'_links\': {\n \'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Computer"\n "title": "Computer"\n
},\n },\n
"content": [],\n "content": [],\n
......
...@@ -74,7 +74,7 @@ result_dict = {\n ...@@ -74,7 +74,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
"content": [],\n "content": [],\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Hosting Subscription"\n "title": "Hosting Subscription"\n
},\n },\n
},\n },\n
......
...@@ -84,7 +84,7 @@ result_dict = {\n ...@@ -84,7 +84,7 @@ result_dict = {\n
{\'href\': \'%s/ERP5Document_getHateoas\' % root_instance.getAbsoluteUrl()},\n {\'href\': \'%s/ERP5Document_getHateoas\' % root_instance.getAbsoluteUrl()},\n
],\n ],\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Hosting Subscription"\n "title": "Hosting Subscription"\n
},\n },\n
},\n },\n
......
...@@ -88,7 +88,7 @@ result_dict = {\n ...@@ -88,7 +88,7 @@ result_dict = {\n
\'_links\': {\n \'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance",\n "title": "Software Instance",\n
},\n },\n
\'software_release\': {\n \'software_release\': {\n
......
...@@ -89,7 +89,7 @@ result_dict = {\n ...@@ -89,7 +89,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n # XXX current type\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance"\n "title": "Software Instance"\n
},\n },\n
},\n },\n
......
...@@ -80,7 +80,7 @@ result_dict = {\n ...@@ -80,7 +80,7 @@ result_dict = {\n
\'_links\': {\n \'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Instance",\n "title": "Software Instance",\n
},\n },\n
\'action_object_jump\': {\n \'action_object_jump\': {\n
......
...@@ -74,7 +74,7 @@ result_dict = {\n ...@@ -74,7 +74,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n # XXX current type\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Person"\n "title": "Person"\n
},\n },\n
"content": [],\n "content": [],\n
......
...@@ -74,7 +74,7 @@ result_dict = {\n ...@@ -74,7 +74,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n # XXX current type\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Person"\n "title": "Person"\n
},\n },\n
"content": [],\n "content": [],\n
......
...@@ -83,7 +83,7 @@ else:\n ...@@ -83,7 +83,7 @@ else:\n
\'_links\': {\n \'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n "self": { "href": context.Base_getRequestUrl() },\n
"index": {\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n "href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Software Installation"\n "title": "Software Installation"\n
},\n },\n
},\n },\n
......
...@@ -86,8 +86,12 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -86,8 +86,12 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
user_link_dict = home_page_hal['_links']['me'] 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' % ( traverse_url_template = home_page_hal['_links']['traverse']['href']
api_netloc, api_path, getRelativeUrlFromUrn(user_link_dict['href'])) me_relative_url = getRelativeUrlFromUrn(user_link_dict['href'])
me_url = traverse_url_template.replace(
'{&relative_url,view}',
'&relative_url=%s&view=view' % me_relative_url
)
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
...@@ -442,8 +446,12 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin): ...@@ -442,8 +446,12 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
user_link_dict = home_page_hal['_links']['me'] 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' % ( traverse_url_template = home_page_hal['_links']['traverse']['href']
api_netloc, api_path, getRelativeUrlFromUrn(user_link_dict['href']))) me_relative_url = getRelativeUrlFromUrn(user_link_dict['href'])
me_url = traverse_url_template.replace(
'{&relative_url,view}',
'&relative_url=%s&view=view' % me_relative_url
)
connection = getNewHttpConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
......
...@@ -326,13 +326,11 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin): ...@@ -326,13 +326,11 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json" "application/hal+json"
) )
self.assertEquals(result, json.dumps({ result = json.loads(result)
'_links': { self.assertEquals(result['_links']['self'],
"self": { {"href": "http://example.org/bar"}
"href": "http://example.org/bar" )
}, self.assertEqual(result['_links'].get('me'), None)
},
}, indent=2))
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
...@@ -349,16 +347,13 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin): ...@@ -349,16 +347,13 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json" "application/hal+json"
) )
self.assertEquals(result, json.dumps({ result = json.loads(result)
'_links': { self.assertEquals(result['_links']['me'],
"self": { {"href": "urn:jio:get:%s" % person_user.getRelativeUrl()}
"href": "http://example.org/bar" )
}, self.assertEqual(result['_links']['self'],
"me": { {"href": "http://example.org/bar"}
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(), )
},
},
}, indent=2))
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
...@@ -375,16 +370,14 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin): ...@@ -375,16 +370,14 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json" "application/hal+json"
) )
self.assertEquals(result, json.dumps({ result = json.loads(result)
'_links': { self.assertEquals(result['_links']['me'],
"self": { {"href": "urn:jio:get:%s" % self.software_instance.getRelativeUrl()}
"href": "http://example.org/bar" )
}, self.assertEqual(result['_links']['self'],
"me": { {"href": "http://example.org/bar"}
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % self.software_instance.getRelativeUrl(), )
},
},
}, indent=2))
class TestSlapOSPerson_requestHateoasHostingSubscription(TestSlapOSHypermediaMixin): class TestSlapOSPerson_requestHateoasHostingSubscription(TestSlapOSHypermediaMixin):
...@@ -541,7 +534,7 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(TestSlapOSHypermediaMix ...@@ -541,7 +534,7 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(TestSlapOSHypermediaMix
"href": "http://example.org/foo", "href": "http://example.org/foo",
}, },
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(), "href": "urn:jio:get:%s" % person_user.getRelativeUrl(),
"title": "Person" "title": "Person"
}, },
"content": [{ "content": [{
...@@ -621,7 +614,7 @@ class TestSlapOSHostingSubscription_getHateoasInstanceList(TestSlapOSHypermediaM ...@@ -621,7 +614,7 @@ class TestSlapOSHostingSubscription_getHateoasInstanceList(TestSlapOSHypermediaM
"title": "Template Software Instance" "title": "Template Software Instance"
}], }],
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(), "href": "urn:jio:get:%s" % subscription.getRelativeUrl(),
"title": "Hosting Subscription" "title": "Hosting Subscription"
}, },
}, },
...@@ -697,7 +690,7 @@ class TestSlapOSHostingSubscription_getHateoasRootSoftwareInstance(TestSlapOSHyp ...@@ -697,7 +690,7 @@ class TestSlapOSHostingSubscription_getHateoasRootSoftwareInstance(TestSlapOSHyp
instance.absolute_url(), instance.absolute_url(),
}], }],
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(), "href": "urn:jio:get:%s" % subscription.getRelativeUrl(),
"title": "Hosting Subscription" "title": "Hosting Subscription"
}, },
}, },
...@@ -783,7 +776,7 @@ class TestSlapOSInstance_getHateoasNews(TestSlapOSHypermediaMixin): ...@@ -783,7 +776,7 @@ class TestSlapOSInstance_getHateoasNews(TestSlapOSHypermediaMixin):
"href": "http://example.org/bar" "href": "http://example.org/bar"
}, },
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \ "href": "urn:jio:get:%s" % \
instance.getRelativeUrl(), instance.getRelativeUrl(),
"title": "Software Instance" "title": "Software Instance"
}, },
...@@ -869,7 +862,7 @@ class TestSlapOSInstance_getHateoasRelatedHostingSubscription(TestSlapOSHypermed ...@@ -869,7 +862,7 @@ class TestSlapOSInstance_getHateoasRelatedHostingSubscription(TestSlapOSHypermed
"href": "http://example.org/bar" "href": "http://example.org/bar"
}, },
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \ "href": "urn:jio:get:%s" % \
instance.getRelativeUrl(), instance.getRelativeUrl(),
"title": "Software Instance" "title": "Software Instance"
}, },
...@@ -959,7 +952,7 @@ class TestSlapOSInstance_getHateoasInformation(TestSlapOSHypermediaMixin): ...@@ -959,7 +952,7 @@ class TestSlapOSInstance_getHateoasInformation(TestSlapOSHypermediaMixin):
"href": "http://foo.com/software.cfg", "href": "http://foo.com/software.cfg",
}, },
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % instance.getRelativeUrl(), "href": "urn:jio:get:%s" % instance.getRelativeUrl(),
"title": "Software Instance" "title": "Software Instance"
}, },
}, },
...@@ -1025,7 +1018,7 @@ class TestSlapOSPerson_getHateoasComputerList(TestSlapOSHypermediaMixin): ...@@ -1025,7 +1018,7 @@ class TestSlapOSPerson_getHateoasComputerList(TestSlapOSHypermediaMixin):
"href": "http://example.org/foo" "href": "http://example.org/foo"
}, },
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \ "href": "urn:jio:get:%s" % \
person_user.getRelativeUrl(), person_user.getRelativeUrl(),
"title": "Person" "title": "Person"
}, },
...@@ -1104,7 +1097,7 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(TestSlapOSHypermedia ...@@ -1104,7 +1097,7 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(TestSlapOSHypermedia
"title": "foo" "title": "foo"
}], }],
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % computer.getRelativeUrl(), "href": "urn:jio:get:%s" % computer.getRelativeUrl(),
"title": "Computer" "title": "Computer"
}, },
}, },
...@@ -1168,7 +1161,7 @@ class TestSlapOSSoftwareInstallation_getHateoasInformation(TestSlapOSHypermediaM ...@@ -1168,7 +1161,7 @@ class TestSlapOSSoftwareInstallation_getHateoasInformation(TestSlapOSHypermediaM
"href": "http://foo.com/software.cfg", "href": "http://foo.com/software.cfg",
}, },
"index": { "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % software_installation.getRelativeUrl(), "href": "urn:jio:get:%s" % software_installation.getRelativeUrl(),
"title": "Software Installation" "title": "Software Installation"
}, },
}, },
......
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