[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
return ""\n
\n
import json\n
result_dict = {\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
result_dict = json.loads(context.ERP5Document_getHateoas(REQUEST))\n
\n
portal = context.getPortalObject()\n
\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\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
else:\n
......@@ -98,7 +82,7 @@ else:\n
if user != "Anonymous User":\n
user_document = context.ERP5Site_getUserDocument(user)\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
response.setHeader(\'Content-Type\', mime_type)\n
......
......@@ -73,7 +73,7 @@ result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Computer"\n
},\n
"content": [],\n
......
......@@ -74,7 +74,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n
"content": [],\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
},\n
},\n
......
......@@ -84,7 +84,7 @@ result_dict = {\n
{\'href\': \'%s/ERP5Document_getHateoas\' % root_instance.getAbsoluteUrl()},\n
],\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
},\n
},\n
......
......@@ -88,7 +88,7 @@ result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\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
},\n
\'software_release\': {\n
......
......@@ -89,7 +89,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\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
},\n
},\n
......
......@@ -80,7 +80,7 @@ result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\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
},\n
\'action_object_jump\': {\n
......
......@@ -74,7 +74,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Person"\n
},\n
"content": [],\n
......
......@@ -74,7 +74,7 @@ result_dict = {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"href": "urn:jio:get:%s" % context.getRelativeUrl(),\n
"title": "Person"\n
},\n
"content": [],\n
......
......@@ -83,7 +83,7 @@ else:\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\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
},\n
},\n
......
......@@ -86,8 +86,12 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
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']))
traverse_url_template = home_page_hal['_links']['traverse']['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.request(
......@@ -442,8 +446,12 @@ class TestSlapOSHypermediaInstanceScenario(testSlapOSMixin):
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'])))
traverse_url_template = home_page_hal['_links']['traverse']['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.request(
......
......@@ -326,13 +326,11 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_links': {
"self": {
"href": "http://example.org/bar"
},
},
}, indent=2))
result = json.loads(result)
self.assertEquals(result['_links']['self'],
{"href": "http://example.org/bar"}
)
self.assertEqual(result['_links'].get('me'), None)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
......@@ -349,16 +347,13 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_links': {
"self": {
"href": "http://example.org/bar"
},
"me": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(),
},
},
}, indent=2))
result = json.loads(result)
self.assertEquals(result['_links']['me'],
{"href": "urn:jio:get:%s" % person_user.getRelativeUrl()}
)
self.assertEqual(result['_links']['self'],
{"href": "http://example.org/bar"}
)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
......@@ -375,16 +370,14 @@ class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_links': {
"self": {
"href": "http://example.org/bar"
},
"me": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % self.software_instance.getRelativeUrl(),
},
},
}, indent=2))
result = json.loads(result)
self.assertEquals(result['_links']['me'],
{"href": "urn:jio:get:%s" % self.software_instance.getRelativeUrl()}
)
self.assertEqual(result['_links']['self'],
{"href": "http://example.org/bar"}
)
class TestSlapOSPerson_requestHateoasHostingSubscription(TestSlapOSHypermediaMixin):
......@@ -541,7 +534,7 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(TestSlapOSHypermediaMix
"href": "http://example.org/foo",
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(),
"href": "urn:jio:get:%s" % person_user.getRelativeUrl(),
"title": "Person"
},
"content": [{
......@@ -621,7 +614,7 @@ class TestSlapOSHostingSubscription_getHateoasInstanceList(TestSlapOSHypermediaM
"title": "Template Software Instance"
}],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(),
"href": "urn:jio:get:%s" % subscription.getRelativeUrl(),
"title": "Hosting Subscription"
},
},
......@@ -697,7 +690,7 @@ class TestSlapOSHostingSubscription_getHateoasRootSoftwareInstance(TestSlapOSHyp
instance.absolute_url(),
}],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(),
"href": "urn:jio:get:%s" % subscription.getRelativeUrl(),
"title": "Hosting Subscription"
},
},
......@@ -783,7 +776,7 @@ class TestSlapOSInstance_getHateoasNews(TestSlapOSHypermediaMixin):
"href": "http://example.org/bar"
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
"href": "urn:jio:get:%s" % \
instance.getRelativeUrl(),
"title": "Software Instance"
},
......@@ -869,7 +862,7 @@ class TestSlapOSInstance_getHateoasRelatedHostingSubscription(TestSlapOSHypermed
"href": "http://example.org/bar"
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
"href": "urn:jio:get:%s" % \
instance.getRelativeUrl(),
"title": "Software Instance"
},
......@@ -959,7 +952,7 @@ class TestSlapOSInstance_getHateoasInformation(TestSlapOSHypermediaMixin):
"href": "http://foo.com/software.cfg",
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % instance.getRelativeUrl(),
"href": "urn:jio:get:%s" % instance.getRelativeUrl(),
"title": "Software Instance"
},
},
......@@ -1025,7 +1018,7 @@ class TestSlapOSPerson_getHateoasComputerList(TestSlapOSHypermediaMixin):
"href": "http://example.org/foo"
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
"href": "urn:jio:get:%s" % \
person_user.getRelativeUrl(),
"title": "Person"
},
......@@ -1104,7 +1097,7 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(TestSlapOSHypermedia
"title": "foo"
}],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % computer.getRelativeUrl(),
"href": "urn:jio:get:%s" % computer.getRelativeUrl(),
"title": "Computer"
},
},
......@@ -1168,7 +1161,7 @@ class TestSlapOSSoftwareInstallation_getHateoasInformation(TestSlapOSHypermediaM
"href": "http://foo.com/software.cfg",
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % software_installation.getRelativeUrl(),
"href": "urn:jio:get:%s" % software_installation.getRelativeUrl(),
"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