[slapos_hypermedia] Add Instance_getHateoasRelatedHostingSubscription.

parent 934020fd
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_slap</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slap</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>get_hateoas_related_hosting_subscription</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>2.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasRelatedHostingSubscription</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/Instance_getHateoasRelatedHostingSubscription</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n
return ""\n
\n
if context.getSlapState() == "stop_requested":\n
state = \'stopped\'\n
elif context.getSlapState() == "start_requested":\n
state = \'started\'\n
else:\n
state = \'destroyed\'\n
\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Software Instance",\n
},\n
\'action_object_jump\': {\n
"href": "%s/ERP5Document_getHateoas" % context.getSpecialiseValue().getAbsoluteUrl(),\n
"title": "Hosting Subscription",\n
}\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Instance_getHateoasRelatedHostingSubscription</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -792,6 +792,95 @@ class TestSlapOSInstance_getHateoasNews(TestSlapOSHypermediaMixin):
},
}, indent=2)))
class TestSlapOSInstance_getHateoasRelatedHostingSubscription(TestSlapOSHypermediaMixin):
def _makeInstance(self):
instance = self.portal.software_instance_module\
.template_software_instance.Base_createCloneDocument(batch_mode=1)
instance.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTHS-%s" % self.generateNewId(),
software_type=self.generateNewSoftwareType(),
url_string=self.generateNewSoftwareReleaseUrl(),
instance_xml=self.generateSafeXml(),
sla_xml=self.generateSafeXml(),
connection_xml=self.generateSafeXml(),
)
self.tic()
return instance
@changeSkin('Hal')
def test_getHateoasRelatedHostingSubscription_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Instance_getHateoasRelatedHostingSubscription
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasRelatedHostingSubscription_wrong_ACCEPT(self):
instance = self._makeInstance()
fake_request = do_fake_request("GET")
result = instance.Instance_getHateoasRelatedHostingSubscription(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasRelatedHostingSubscription_bad_method(self):
instance = self._makeInstance()
fake_request = do_fake_request("POST")
result = instance.Instance_getHateoasRelatedHostingSubscription(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasRelatedHostingSubscription_not_instance_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Instance_getHateoasRelatedHostingSubscription(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasRelatedHostingSubscription_result(self):
subscription = self._makeHostingSubscription()
instance= self._makeInstance()
instance.edit(specialise_value=subscription)
self.tic()
fake_request = do_fake_request("GET")
result = instance.Instance_getHateoasRelatedHostingSubscription(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_links': {
"self": {
"href": "http://example.org/bar"
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
instance.getRelativeUrl(),
"title": "Software Instance"
},
"action_object_jump": {
'href': "%s/ERP5Document_getHateoas" % subscription.getAbsoluteUrl(),
'title': "Hosting Subscription"
}
},
}, indent=2)))
class TestSlapOSInstance_getHateoasInformation(TestSlapOSHypermediaMixin):
......
......@@ -8,3 +8,4 @@ Person | request_hateoas_hosting_subscription
Software Installation | get_hateoas_information
Software Instance | get_hateoas_information
Software Instance | get_hateoas_news
Software Instance | get_hateoas_related_hosting_subscription
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