[slapos_hypermedia] Upgrade to new erp5_hal_json_style.

A few tests can be taken out of this BT to be put in erp5_hal_json_style.
parent 11eeb5d9
<?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_software_installation_list</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>50.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasSoftwareInstallationList</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}/Computer_getHateoasSoftwareInstallationList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_instance_list</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>2.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasInstanceList</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}/HostingSubscription_getHateoasInstanceList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_root_instance</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>2.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasRootInstance</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}/HostingSubscription_getHateoasRootSoftwareInstance</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_computer_list</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>15.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasComputerList</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}/Person_getHateoasComputerList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_hosting_subscription_list</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>15.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasHostingSubscriptionList</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}/Person_getHateoasHostingSubscriptionList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_information</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>15.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>getHateoasInformation</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}/Person_getHateoasInformation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_post</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slap_post</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>request_hateoas_hosting_subscription</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>15.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>requestHateoasHostingSubscription</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}/Person_requestHateoasHostingSubscription</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_information</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>getHateoasInformation</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}/SoftwareInstallation_getHateoasInformation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_information</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>getHateoasInformation</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_getHateoasInformation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_news</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>getHateoasNews</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_getHateoasNews</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Category" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_folders_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Delete_objects_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_slap</string>
<string>action_type/object_slap</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>object_slap</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Category</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>object_slap</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Category" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_folders_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Copy_or_Move_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Delete_objects_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_slap</string>
<string>action_type/object_slap</string>
<string>action_type/object_slap_post</string>
<string>action_type/object_slap_post</string>
<string>action_type/object_slap_post</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>object_slap_post</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Category</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>object_slap_post</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -56,23 +56,21 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.master\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
else:\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.master\',\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
"type": type },\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# "http://slapos.org/reg/edit": {\n
# "href": "/edit",\n
# "method": "PUT",\n
......@@ -83,21 +81,21 @@ else:\n
# "method": "POST",\n
# "type": "application/json; class=slapos.org.person",\n
# },\n
},\n
}\n
},\n
}\n
\n
portal = context.getPortalObject()\n
portal = context.getPortalObject()\n
\n
# XXX Handle also other kind of users: instance, computer, master\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\n
result_dict[\'_links\'][\'http://slapos.org/reg/me\'] = {\n
\'href\': \'%s/Person_getHateoas\' % person.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.person"\n
}\n
# XXX Handle also other kind of users: instance, computer, master\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\n
result_dict[\'_links\'][\'action_object_jump\'] = {\n
\'href\': \'%s/ERP5Document_getHateoas\' % person.absolute_url(),\n
\'title\': \'Person\'\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......
<?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
if REQUEST is not None:\n
raise Unauthorized\n
\n
# XXX requested to simulate in unit test for now\n
return context.REQUEST.get(\'BODY\')\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>Base_getRequestBody</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
if REQUEST is not None:\n
raise Unauthorized\n
\n
# XXX requested to simulate in unit test for now\n
return context.REQUEST.getHeader(name, default)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>name, default=None, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getRequestHeader</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
if REQUEST is not None:\n
raise Unauthorized\n
\n
# XXX requested to simulate in unit test for now\n
return context.REQUEST.getURL()\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>Base_getRequestUrl</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
if REQUEST is not None:\n
raise Unauthorized\n
\n
result = None\n
accept = context.Base_getRequestHeader(\'Accept\', default=\'\')\n
for accepted_type in accepted_type_list:\n
if accepted_type in accept:\n
# XXX Really simple and stupid matching.\n
# Better test to ensure best matching type\n
result = accepted_type\n
break\n
\n
if (result is None) and (\'*/*\' in accept):\n
result = accepted_type_list[0]\n
\n
return result\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>accepted_type_list, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_handleAcceptHeader</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -56,41 +56,43 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Computer":\n
response.setStatus(403)\n
return ""\n
else:\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.collection\',\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": type },\n
"item": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=\'Software Installation\',\n
default_aggregate_uid=context.getUid(),\n
validation_state=\'validated\',\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'item\'].append({\n
\'href\': \'%s/SoftwareInstallation_getHateoas\' % obj.absolute_url(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.software_installation\',\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": "Computer"\n
},\n
"content": [],\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=\'Software Installation\',\n
default_aggregate_uid=context.getUid(),\n
validation_state=\'validated\',\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getUrlString()\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......
......@@ -56,40 +56,42 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Hosting Subscription":\n
response.setStatus(403)\n
return ""\n
else:\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.collection\',\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": type },\n
"item": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=[\'Software Instance\', \'Slave Instance\'],\n
default_specialise_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'item\'].append({\n
\'href\': \'%s/Instance_getHateoas\' % obj.absolute_url(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.instance\',\n
})\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"content": [],\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Hosting Subscription"\n
},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type=[\'Software Instance\', \'Slave Instance\'],\n
default_specialise_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getTitle()\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......
......@@ -56,39 +56,42 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.hosting_subscription\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Hosting Subscription":\n
response.setStatus(403)\n
return ""\n
else:\n
\n
# XXX Set more properties on the document\n
\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.hosting_subscription\',\n
\'title\': context.getTitle(),\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.hosting_subscription" },\n
\n
"http://slapos.org/reg/instance": {\n
"href": "%s/HostingSubscription_getHateoasInstanceList" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.collection",\n
},\n
instance_list = context.getPredecessorValueList()\n
for instance in instance_list:\n
if instance.getTitle() == context.getTitle():\n
root_instance = instance\n
break\n
else:\n
raise Exception(\'Root instance not found.\')\n
\n
},\n
}\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
"content": [\n
{\'href\': \'%s/ERP5Document_getHateoas\' % root_instance.getAbsoluteUrl()},\n
],\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Hosting Subscription"\n
},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......@@ -97,7 +100,7 @@ else:\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>HostingSubscription_getHateoas</string> </value>
<value> <string>HostingSubscription_getHateoasRootSoftwareInstance</string> </value>
</item>
</dictionary>
</pickle>
......
<?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
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.instance\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n
return ""\n
else:\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
\'_class\': \'slapos.org.instance\',\n
\'title\': context.getTitle(),\n
\'slave\': context.getPortalType() == \'Slave Instance\',\n
\'software_type\': context.getSourceReference(),\n
\'parameter\': context.getInstanceXmlAsDict(),\n
\'sla\': context.getSlaXmlAsDict(),\n
\'connection\': context.getConnectionXmlAsDict(),\n
\'status\': state,\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.instance" },\n
"http://slapos.org/reg/news": { "href": "%s/Instance_getHateoasNews" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.news" },\n
"http://slapos.org/reg/release": { "href": context.getUrlString()},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\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_getHateoas</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -56,39 +56,49 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.computer\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Computer":\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n
return ""\n
else:\n
\n
# XXX Set more properties on the document\n
\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.computer\',\n
\'title\': context.getTitle(),\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.computer" },\n
\n
"http://slapos.org/reg/software": {\n
"href": "%s/Computer_getHateoasSoftwareInstallationList" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.collection",\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
},\n
import json\n
result_dict = {\n
\'title\': context.getTitle(),\n
\'slave\': context.getPortalType() == \'Slave Instance\',\n
\'software_type\': context.getSourceReference(),\n
\'parameter_dict\': context.getInstanceXmlAsDict(),\n
\'sla_dict\': context.getSlaXmlAsDict(),\n
\'connection_dict\': context.getConnectionXmlAsDict(),\n
\'requested_state\': state,\n
\'instance_guid\': context.getId(),\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
\'software_release\': {\n
"href": context.getUrlString(),\n
}\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......@@ -97,7 +107,7 @@ else:\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_getHateoas</string> </value>
<value> <string>Instance_getHateoasInformation</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -56,47 +56,47 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.news\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\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
else:\n
\n
import json\n
import json\n
\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
try:\n
d = memcached_dict[context.getReference()]\n
except KeyError:\n
d = {\n
"user": "SlapOS Master",\n
"text": "#error no data found for %s" % context.getReference()\n
}\n
else:\n
d = json.loads(d)\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
try:\n
d = memcached_dict[context.getReference()]\n
except KeyError:\n
d = {\n
"user": "SlapOS Master",\n
"text": "#error no data found for %s" % context.getReference()\n
}\n
else:\n
d = json.loads(d)\n
\n
result_dict = {\n
\'_class\': \'slapos.org.news\',\n
\'news\': [d],\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.news" },\n
"http://slapos.org/reg/instance": { "href": "%s/Instance_getHateoas" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.instance" },\n
},\n
}\n
result_dict = {\n
\'news\': [d],\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Software Instance"\n
},\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......
<?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
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.person\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
response.setStatus(403)\n
return ""\n
else:\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.person\',\n
\'title\': context.getTitle(),\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.person" },\n
\n
"http://slapos.org/reg/request": {\n
"href": "%s/Person_requestHateoasHostingSubscription" % context.absolute_url(),\n
"method": "POST",\n
"type": "application/json; class=slapos.org.hosting_subscription",\n
},\n
\n
"http://slapos.org/reg/computer": {\n
"href": "%s/Person_getHateoasComputerList" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.collection",\n
},\n
\n
"http://slapos.org/reg/hosting_subscription": {\n
"href": "%s/Person_getHateoasHostingSubscriptionList" % context.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.collection",\n
},\n
\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\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>Person_getHateoas</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -56,40 +56,43 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
response.setStatus(403)\n
return ""\n
else:\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.collection\',\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": type },\n
"item": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Computer",\n
default_source_administration_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'item\'].append({\n
\'href\': \'%s/Computer_getHateoas\' % obj.absolute_url(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.computer\',\n
})\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Person"\n
},\n
"content": [],\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Computer",\n
default_source_administration_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getTitle(),\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......
......@@ -56,40 +56,43 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
response.setStatus(403)\n
return ""\n
else:\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.collection\',\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": type },\n
"item": [],\n
},\n
}\n
\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Hosting Subscription",\n
default_destination_section_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'item\'].append({\n
\'href\': \'%s/HostingSubscription_getHateoas\' % obj.absolute_url(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.hosting_subscription\',\n
})\n
import json\n
result_dict = {\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl() },\n
# XXX current type\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Person"\n
},\n
"content": [],\n
},\n
}\n
\n
response.setHeader(\'Content-Type\', type)\n
return json.dumps(result_dict)\n
for sql_obj in context.getPortalObject().portal_catalog(\n
portal_type="Hosting Subscription",\n
default_destination_section_uid=context.getUid(),\n
):\n
obj = sql_obj.getObject()\n
result_dict[\'_links\'][\'content\'].append({\n
\'href\': \'%s/ERP5Document_getHateoas\' % obj.absolute_url(),\n
\'title\': obj.getTitle()\n
})\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
</string> </value>
</item>
<item>
......
......@@ -58,12 +58,12 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/json; class=slapos.org.hosting_subscription\'\n
mime_type = \'application/json\'\n
\n
if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_getRequestHeader(\'Content-Type\'):\n
elif mime_type != context.Base_getRequestHeader(\'Content-Type\'):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() != "Person":\n
......
......@@ -56,12 +56,12 @@ if REQUEST is None:\n
raise Unauthorized\n
\n
response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.software_installation\'\n
mime_type = \'application/hal+json\'\n
\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n
elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
elif context.getPortalType() not in ["Software Installation"]:\n
......@@ -78,19 +78,21 @@ else:\n
\n
import json\n
result_dict = {\n
\'_class\': \'slapos.org.software_installation\',\n
\'title\': context.getTitle(),\n
\'status\': state,\n
\'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.software_installation" },\n
"self": { "href": context.Base_getRequestUrl() },\n
"index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Software Installation"\n
},\n
},\n
}\n
url_string = context.getUrlString(None)\n
if url_string is not None:\n
result_dict["_links"]["software_release"] = { "href": url_string }\n
\n
response.setHeader(\'Content-Type\', type)\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n
</string> </value>
</item>
......@@ -100,7 +102,7 @@ else:\n
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstallation_getHateoas</string> </value>
<value> <string>SoftwareInstallation_getHateoasInformation</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -8,6 +8,15 @@ import httplib
import urlparse
import base64
def hateoasGetLinkFromLinks(links, title):
if type(links) == dict:
if links.get('title') == title:
return links
return
for action in links:
if action.get('title') == title:
return action
class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
def _makeUser(self):
......@@ -31,20 +40,28 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
erp5_person = self._makeUser()
authorization = 'Basic %s' % base64.b64encode(
"%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())
def getNewHttpConnection(api_netloc):
if api_scheme == 'https':
connection = httplib.HTTPSConnection(api_netloc)
else:
connection = httplib.HTTPConnection(api_netloc)
return connection
#####################################################
# Access the master home page hal
#####################################################
content_type = "application/vnd.slapos.org.hal+json; class=slapos.org.master"
connection = httplib.HTTPConnection(api_netloc)
connection = getNewHttpConnection(api_netloc)
connection.request(
method='GET',
url='%s/Base_getHateoasMaster' % \
url='%s/web_site_module/hateoas/Base_getHateoasMaster' % \
self.portal.absolute_url(),
headers={
'Authorization': authorization,
......@@ -53,7 +70,6 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
body="",
)
response = connection.getresponse()
self.assertEquals(response.status, 200)
self.assertEquals(response.getheader('Content-Type'), content_type)
home_page_hal = json.loads(response.read())
......@@ -61,21 +77,20 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Fetch the user hal
#####################################################
content_type = "application/vnd.slapos.org.hal+json; class=slapos.org.person"
user_link_dict = home_page_hal['_links']['http://slapos.org/reg/me']
user_link_dict = home_page_hal['_links']['action_object_jump']
self.assertNotEqual(user_link_dict, None)
connection = httplib.HTTPConnection(api_netloc)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': user_link_dict['type'],
'Accept': content_type,
},
body="",
)
response = connection.getresponse()
self.assertEquals(response.status, 200)
self.assertEquals(response.getheader('Content-Type'), content_type)
user_hal = json.loads(response.read())
......@@ -83,17 +98,19 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Run method to request an hosting subscription
#####################################################
content_type = "application/json; " \
"class=slapos.org.hosting_subscription"
request_link_dict = user_hal['_links']['http://slapos.org/reg/request']
connection = httplib.HTTPConnection(api_netloc)
request_link_dict = hateoasGetLinkFromLinks(
user_hal['_links']['action_object_slap_post'],
'requestHateoasHostingSubscription'
)
self.assertNotEqual(request_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=request_link_dict.get('method', 'GET'),
method=request_link_dict.get('method', 'POST'),
url=request_link_dict['href'],
headers={
'Authorization': authorization,
'Content-Type': request_link_dict['type'],
'Content-Type': 'application/json',
},
body=json.dumps({
'software_release': 'http://example.orgé',
......@@ -114,18 +131,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get user's hosting subscription list
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
user_link_dict = user_hal['_links']\
['http://slapos.org/reg/hosting_subscription']
connection = httplib.HTTPConnection(api_netloc)
user_link_dict = hateoasGetLinkFromLinks(
user_hal['_links']['action_object_slap'],
'getHateoasHostingSubscriptionList'
)
self.assertNotEqual(user_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': user_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -138,18 +155,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get user's hosting subscription
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.hosting_subscription"
subscription_link_dict = subscription_collection_hal['_links']\
['item'][0]
connection = httplib.HTTPConnection(api_netloc)
['content'][0]
self.assertNotEqual(subscription_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=subscription_link_dict.get('method', 'GET'),
url=subscription_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': subscription_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -162,18 +177,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get hosting subscription's instance list
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
user_link_dict = subscription_hal['_links']\
['http://slapos.org/reg/instance']
connection = httplib.HTTPConnection(api_netloc)
user_link_dict = hateoasGetLinkFromLinks(
subscription_hal['_links']['action_object_slap'],
'getHateoasInstanceList'
)
self.assertNotEqual(user_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': user_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -186,18 +201,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get instance
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.instance"
subscription_link_dict = instance_collection_hal['_links']\
['item'][0]
connection = httplib.HTTPConnection(api_netloc)
['content'][0]
self.assertNotEqual(subscription_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=subscription_link_dict.get('method', 'GET'),
url=subscription_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': subscription_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -210,18 +223,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get instance news
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.news"
news_link_dict = instance_hal['_links']\
['http://slapos.org/reg/news']
connection = httplib.HTTPConnection(api_netloc)
news_link_dict = hateoasGetLinkFromLinks(
instance_hal['_links']['action_object_slap'],
'getHateoasNews'
)
self.assertNotEqual(news_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=news_link_dict.get('method', 'GET'),
url=news_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': news_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -249,18 +262,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get user's computer list
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
user_link_dict = user_hal['_links']\
['http://slapos.org/reg/computer']
connection = httplib.HTTPConnection(api_netloc)
user_link_dict = hateoasGetLinkFromLinks(
user_hal['_links']['action_object_slap'],
'getHateoasComputerList'
)
self.assertNotEqual(user_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': user_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -273,18 +286,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get user's computer
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.computer"
computer_link_dict = computer_collection_hal['_links']\
['item'][0]
connection = httplib.HTTPConnection(api_netloc)
['content'][0]
self.assertNotEqual(computer_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=computer_link_dict.get('method', 'GET'),
url=computer_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': computer_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -297,18 +308,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get computer's software list
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
computer_link_dict = computer_hal['_links']\
['http://slapos.org/reg/software']
connection = httplib.HTTPConnection(api_netloc)
computer_link_dict = hateoasGetLinkFromLinks(
computer_hal['_links']['action_object_slap'],
'getHateoasSoftwareInstallationList'
)
self.assertNotEqual(computer_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=computer_link_dict.get('method', 'GET'),
url=computer_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': computer_link_dict['type'],
'Accept': content_type,
},
body="",
)
......@@ -321,18 +332,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
#####################################################
# Get user's software
#####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.software_installation"
software_link_dict = software_collection_hal['_links']\
['item'][0]
connection = httplib.HTTPConnection(api_netloc)
['content'][0]
self.assertNotEqual(software_link_dict, None)
connection = getNewHttpConnection(api_netloc)
connection.request(
method=software_link_dict.get('method', 'GET'),
url=software_link_dict['href'],
headers={
'Authorization': authorization,
'Accept': software_link_dict['type'],
'Accept': content_type,
},
body="",
)
......
......@@ -17,6 +17,20 @@ import sys
import json
import StringIO
def changeSkin(skin_name):
def decorator(func):
def wrapped(self, *args, **kwargs):
default_skin = self.portal.portal_skins.default_skin
self.portal.portal_skins.changeSkin(skin_name)
self.app.REQUEST.set('portal_skin', skin_name)
try:
v = func(self, *args, **kwargs)
finally:
self.portal.portal_skins.changeSkin(default_skin)
self.app.REQUEST.set('portal_skin', default_skin)
return v
return wrapped
return decorator
def simulate(script_id, params_string, code_string):
def upperWrap(f):
......@@ -55,11 +69,16 @@ def do_fake_request(request_method, headers={}):
env.update(headers)
return HTTPRequest(StringIO.StringIO(), env, HTTPResponse())
class TestSlapOSBase_getRequestHeader(testSlapOSMixin):
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class ERP5HALJSONStyleSkinsMixin(ERP5TypeTestCase):
def afterSetUp(self):
self.login()
self.changeSkin('Hal')
def beforeTearDown(self):
transaction.abort()
class TestBase_getRequestHeader(ERP5HALJSONStyleSkinsMixin):
def test_getRequestHeader_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
......@@ -83,11 +102,8 @@ class TestSlapOSBase_getRequestHeader(testSlapOSMixin):
def test_getRequestHeader_matching_key(self):
pass
class TestSlapOSBase_getRequestUrl(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
# XXX to be migrated to erp5_hal_json_style bt
class TestBase_getRequestUrl(ERP5HALJSONStyleSkinsMixin):
def test_getRequestUrl_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
......@@ -98,11 +114,7 @@ class TestSlapOSBase_getRequestUrl(testSlapOSMixin):
def test_getRequestUrl_matching_key(self):
pass
class TestSlapOSBase_getRequestBody(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
class TestBase_getRequestBody(ERP5HALJSONStyleSkinsMixin):
def test_getRequestBody_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
......@@ -113,11 +125,7 @@ class TestSlapOSBase_getRequestBody(testSlapOSMixin):
def test_getRequestBody_matching_key(self):
pass
class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
def beforeTearDown(self):
transaction.abort()
class TestBase_handleAcceptHeader(ERP5HALJSONStyleSkinsMixin):
def test_handleAcceptHeader_REQUEST_disallowed(self):
self.assertRaises(
Unauthorized,
......@@ -126,6 +134,7 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
REQUEST={})
@simulate('Base_getRequestHeader', '*args, **kwargs', 'return "*/*"')
@changeSkin('Hal')
def test_handleAcceptHeader_star_accept(self):
self.assertEquals(
self.portal.Base_handleAcceptHeader(['application/vnd+test',
......@@ -133,8 +142,9 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
'application/vnd+test'
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+2test"')
@changeSkin('Hal')
def test_handleAcceptHeader_matching_type(self):
self.assertEquals(
self.portal.Base_handleAcceptHeader(['application/vnd+test',
......@@ -142,15 +152,23 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
'application/vnd+2test'
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+2test"')
@changeSkin('Hal')
def test_handleAcceptHeader_non_matching_type(self):
self.assertEquals(
self.portal.Base_handleAcceptHeader(['application/vnd+test']),
None
)
class TestSlapOSBase_getHateoasMaster(testSlapOSMixin):
class TestSlapOSHypermediaMixin(testSlapOSMixin):
def afterSetUp(self):
testSlapOSMixin.afterSetUp(self)
self.changeSkin('Hal')
def beforeTearDown(self):
transaction.abort()
def _makePerson(self):
new_id = self.generateNewId()
......@@ -166,212 +184,195 @@ class TestSlapOSBase_getHateoasMaster(testSlapOSMixin):
for assignment in person_user.contentValues(portal_type="Assignment"):
assignment.open()
self.tic()
self.changeSkin('Hal')
return person_user
def beforeTearDown(self):
transaction.abort()
def _makeHostingSubscription(self):
hosting_subscription = self.portal.hosting_subscription_module\
.template_hosting_subscription.Base_createCloneDocument(batch_mode=1)
hosting_subscription.validate()
self.tic()
self.changeSkin('Hal')
return hosting_subscription
def _makeInstance(self):
instance = self.portal.software_instance_module\
.template_software_instance.Base_createCloneDocument(batch_mode=1)
instance.validate()
self.tic()
return instance
def _makeComputer(self):
computer = self.portal.computer_module\
.template_computer.Base_createCloneDocument(batch_mode=1)
computer.validate()
self.tic()
return computer
def _makeSoftwareInstallation(self):
software_installation = self.portal.software_installation_module\
.template_software_installation.Base_createCloneDocument(batch_mode=1)
software_installation.validate()
self.tic()
return software_installation
class TestSlapOSPersonERP5Document_getHateoas(TestSlapOSHypermediaMixin):
# XXX: currently for person, make it generic
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasPerson_wrong_ACCEPT(self):
person_user = self._makePerson()
fake_request = do_fake_request("GET")
result = person_user.ERP5Document_getHateoas(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_getHateoasPerson_bad_method(self):
person_user = self._makePerson()
fake_request = do_fake_request("POST")
result = person_user.ERP5Document_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
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_getHateoasPerson_result(self):
person_user = self._makePerson()
fake_request = do_fake_request("GET")
result = person_user.ERP5Document_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
results = json.loads(result)
action_object_slap = results['_links']['action_object_slap']
self.assertEqual(len(action_object_slap), 3)
for action in [
{
'href': '%s/Person_getHateoasComputerList' % \
person_user.absolute_url(),
'name': 'get_hateoas_computer_list',
'title': 'getHateoasComputerList'
},
{
'href': '%s/Person_getHateoasHostingSubscriptionList' % \
person_user.absolute_url(),
'name': 'get_hateoas_hosting_subscription_list',
'title': 'getHateoasHostingSubscriptionList'
},
{
'href': '%s/Person_getHateoasInformation' % \
person_user.absolute_url(),
'name': 'get_hateoas_information',
'title': 'getHateoasInformation'
},
]:
self.assertTrue(action in action_object_slap)
self.assertEquals(results['_links']['action_object_slap_post'], {
"href": '%s/Person_requestHateoasHostingSubscription' % \
person_user.absolute_url(),
"name": "request_hateoas_hosting_subscription",
"title": "requestHateoasHostingSubscription"
})
class TestSlapOSBase_getHateoasMaster(TestSlapOSHypermediaMixin):
@changeSkin('Hal')
def test_getHateoasMaster_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Base_getHateoasMaster
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasMaster_wrong_ACCEPT(self):
#self.changeSkin('Hal')
fake_request = do_fake_request("GET")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.master"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasMaster_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.master"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasMaster_anonymous_result(self):
self.logout()
self.changeSkin('Hal')
fake_request = do_fake_request("GET")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.master"
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_class': 'slapos.org.master',
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.master"
"href": "http://example.org/bar"
},
},
}))
}, indent=2))
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.master"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasMaster_person_result(self):
person_user = self._makePerson()
self.login(person_user.getReference())
self.changeSkin('Hal')
fake_request = do_fake_request("GET")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.master"
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_class': 'slapos.org.master',
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.master"
"href": "http://example.org/bar"
},
"http://slapos.org/reg/me": {
"href": "%s/Person_getHateoas" % person_user.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.person"
"action_object_jump": {
"href": "%s/ERP5Document_getHateoas" % person_user.absolute_url(),
"title": "Person"
},
},
}))
class TestSlapOSPerson_getHateoas(testSlapOSMixin):
def _makePerson(self):
new_id = self.generateNewId()
person_user = self.portal.person_module.template_member.\
Base_createCloneDocument(batch_mode=1)
person_user.edit(
title="live_test_%s" % new_id,
reference="live_test_%s" % new_id,
default_email_text="live_test_%s@example.org" % new_id,
)
}, indent=2))
person_user.validate()
for assignment in person_user.contentValues(portal_type="Assignment"):
assignment.open()
self.tic()
return person_user
def beforeTearDown(self):
transaction.abort()
def test_getHateoasPerson_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Person_getHateoas
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
def test_getHateoasPerson_wrong_ACCEPT(self):
person_user = self._makePerson()
fake_request = do_fake_request("GET")
result = person_user.Person_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.person"')
def test_getHateoasPerson_bad_method(self):
person_user = self._makePerson()
fake_request = do_fake_request("POST")
result = person_user.Person_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.person"')
def test_getHateoasPerson_not_person_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoas(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/vnd.slapos.org.hal+json; ' \
'class=slapos.org.person"')
def test_getHateoasPerson_result(self):
person_user = self._makePerson()
fake_request = do_fake_request("GET")
result = person_user.Person_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.person"
)
self.assertEquals(result, json.dumps({
'_class': 'slapos.org.person',
'title': person_user.getTitle(),
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.person"
},
"http://slapos.org/reg/request": {
"href": "%s/Person_requestHateoasHostingSubscription" % \
person_user.absolute_url(),
"method": "POST",
"type": "application/json; class=slapos.org.hosting_subscription",
},
"http://slapos.org/reg/computer": {
"href": "%s/Person_getHateoasComputerList" % \
person_user.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection",
},
"http://slapos.org/reg/hosting_subscription": {
"href": "%s/Person_getHateoasHostingSubscriptionList" % \
person_user.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
},
},
}))
class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
def _makePerson(self):
new_id = self.generateNewId()
person_user = self.portal.person_module.template_member.\
Base_createCloneDocument(batch_mode=1)
person_user.edit(
title="live_test_%s" % new_id,
reference="live_test_%s" % new_id,
default_email_text="live_test_%s@example.org" % new_id,
)
person_user.validate()
for assignment in person_user.contentValues(portal_type="Assignment"):
assignment.open()
self.tic()
return person_user
def beforeTearDown(self):
transaction.abort()
class TestSlapOSPerson_requestHateoasHostingSubscription(TestSlapOSHypermediaMixin):
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Person_requestHateoasHostingSubscription
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_wrong_CONTENT(self):
person_user = self._makePerson()
fake_request = do_fake_request("POST")
......@@ -380,9 +381,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \
'class=slapos.org.hosting_subscription"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_bad_method(self):
person_user = self._makePerson()
fake_request = do_fake_request("GET")
......@@ -391,9 +392,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \
'class=slapos.org.hosting_subscription"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_not_person_context(self):
fake_request = do_fake_request("POST")
result = self.portal.Person_requestHateoasHostingSubscription(
......@@ -401,11 +402,11 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestBody', '*args, **kwargs',
@simulate('Base_getRequestBody', '*args, **kwargs',
'return "[}"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \
'class=slapos.org.hosting_subscription"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_no_json(self):
person_user = self._makePerson()
fake_request = do_fake_request("POST")
......@@ -414,12 +415,12 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 400)
self.assertEquals(result, "")
@simulate('Base_getRequestBody', '*args, **kwargs',
@simulate('Base_getRequestBody', '*args, **kwargs',
'return "%s"' % json.dumps({
}))
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \
'class=slapos.org.hosting_subscription"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_missing_parameter(self):
person_user = self._makePerson()
fake_request = do_fake_request("POST")
......@@ -428,7 +429,7 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 400)
self.assertEquals(result, "")
@simulate('Base_getRequestBody', '*args, **kwargs',
@simulate('Base_getRequestBody', '*args, **kwargs',
'return """%s"""' % json.dumps({
'software_release': 'http://example.orgé',
'title': 'a great titleé',
......@@ -438,9 +439,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
'slave': False,
'status': 'started',
}))
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \
'class=slapos.org.hosting_subscription"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_result(self):
person_user = self._makePerson()
fake_request = do_fake_request("POST")
......@@ -450,58 +451,18 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(result, "")
# XXX Test that person.request is called.
class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
def _makePerson(self):
new_id = self.generateNewId()
person_user = self.portal.person_module.template_member.\
Base_createCloneDocument(batch_mode=1)
person_user.edit(
title="live_test_%s" % new_id,
reference="live_test_%s" % new_id,
default_email_text="live_test_%s@example.org" % new_id,
)
person_user.validate()
for assignment in person_user.contentValues(portal_type="Assignment"):
assignment.open()
self.tic()
return person_user
def _makeHostingSubscription(self):
hosting_subscription = self.portal.hosting_subscription_module\
.template_hosting_subscription.Base_createCloneDocument(batch_mode=1)
hosting_subscription.validate()
# hosting_subscription.edit(
# title=self.generateNewSoftwareTitle(),
# reference="TESTHS-%s" % self.generateNewId(),
# )
# self.request_kw = dict(
# software_release=\
# self.generateNewSoftwareReleaseUrl(),
# software_type=self.generateNewSoftwareType(),
# instance_xml=self.generateSafeXml(),
# sla_xml=self.generateSafeXml(),
# shared=False,
# software_title=hosting_subscription.getTitle(),
# state='started'
# )
# hosting_subscription.requestStart(**self.request_kw)
# hosting_subscription.requestInstance(**self.request_kw)
self.tic()
return hosting_subscription
def beforeTearDown(self):
transaction.abort()
class TestSlapOSPerson_getHateoasHostingSubscriptionList(TestSlapOSHypermediaMixin):
@changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Person_getHateoasHostingSubscriptionList
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_wrong_ACCEPT(self):
person_user = self._makePerson()
fake_request = do_fake_request("GET")
......@@ -510,9 +471,9 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json')
@changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.Person_getHateoasHostingSubscriptionList(
......@@ -520,21 +481,20 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
def test_requestHateoasHostingSubscription_not_person_context(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_not_person_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoasHostingSubscriptionList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
def test_getHateoasHostingSubscriptionList_person_result(self):
person_user = self._makePerson()
hosting_subscription = self._makeHostingSubscription()
......@@ -542,204 +502,183 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
self.tic()
self.login(person_user.getReference())
self.changeSkin('Hal')
fake_request = do_fake_request("GET")
result = person_user.Person_getHateoasHostingSubscriptionList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.collection"
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_class': 'slapos.org.collection',
'_links': {
"self": {
"href": "http://example.org/foo",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
},
"item": [{
"href": "%s/HostingSubscription_getHateoas" % \
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(),
"title": "Person"
},
"content": [{
"href": "%s/ERP5Document_getHateoas" % \
hosting_subscription.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.hosting_subscription"
"title": "Template Hosting Subscription"
}],
},
}))
class TestSlapOSHostingSubscription_getHateoas(testSlapOSMixin):
def _makeHostingSubscription(self):
hosting_subscription = self.portal.hosting_subscription_module\
.template_hosting_subscription.Base_createCloneDocument(batch_mode=1)
hosting_subscription.edit(
title=self.generateNewSoftwareTitle(),
reference="TESTHS-%s" % self.generateNewId(),
)
self.tic()
return hosting_subscription
}, indent=2))
def beforeTearDown(self):
transaction.abort()
class TestSlapOSHostingSubscription_getHateoasInstanceList(TestSlapOSHypermediaMixin):
def test_getHateoasHostingSubscription_REQUEST_mandatory(self):
@changeSkin('Hal')
def test_getHateoasInstanceList_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.HostingSubscription_getHateoas
self.portal.HostingSubscription_getHateoasInstanceList
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
def test_getHateoasHostingSubscription_wrong_ACCEPT(self):
hosting_subscription = self._makeHostingSubscription()
@changeSkin('Hal')
def test_getHateoasInstanceList_wrong_ACCEPT(self):
subscription = self._makeHostingSubscription()
fake_request = do_fake_request("GET")
result = hosting_subscription.HostingSubscription_getHateoas(
result = subscription.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.hosting_subscription"')
def test_getHateoasHostingSubscription_bad_method(self):
hosting_subscription = self._makeHostingSubscription()
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasInstanceList_bad_method(self):
fake_request = do_fake_request("POST")
result = hosting_subscription.HostingSubscription_getHateoas(
result = self.portal.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.hosting_subscription"')
def test_getHateoasHostingSubscription_not_hosting_subscription_context(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasInstanceList_not_hosting_subscription_context(self):
fake_request = do_fake_request("GET")
result = self.portal.HostingSubscription_getHateoas(REQUEST=fake_request)
result = self.portal.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.hosting_subscription"')
def test_getHateoasHostingSubscription_result(self):
hosting_subscription = self._makeHostingSubscription()
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasInstanceList_person_result(self):
subscription = self._makeHostingSubscription()
instance= self._makeInstance()
instance.edit(specialise_value=subscription)
self.tic()
fake_request = do_fake_request("GET")
result = hosting_subscription.HostingSubscription_getHateoas(
result = subscription.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.hosting_subscription"
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_class': 'slapos.org.hosting_subscription',
'title': hosting_subscription.getTitle(),
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.hosting_subscription"
"href": "http://example.org/bar"
},
"http://slapos.org/reg/instance": {
"href": "%s/HostingSubscription_getHateoasInstanceList" % \
hosting_subscription.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
"content": [{
"href": "%s/ERP5Document_getHateoas" % \
instance.absolute_url(),
"title": "Template Software Instance"
}],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(),
"title": "Hosting Subscription"
},
},
}))
class TestSlapOSHostingSubscription_getHateoasInstanceList(testSlapOSMixin):
def _makeHostingSubscription(self):
hosting_subscription = self.portal.hosting_subscription_module\
.template_hosting_subscription.Base_createCloneDocument(batch_mode=1)
hosting_subscription.validate()
self.tic()
return hosting_subscription
def _makeInstance(self):
instance = self.portal.software_instance_module\
.template_software_instance.Base_createCloneDocument(batch_mode=1)
instance.validate()
self.tic()
return instance
}, indent=2))
def beforeTearDown(self):
transaction.abort()
class TestSlapOSHostingSubscription_getHateoasRootSoftwareInstance(TestSlapOSHypermediaMixin):
def test_getHateoasInstanceList_REQUEST_mandatory(self):
@changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.HostingSubscription_getHateoasInstanceList
self.portal.HostingSubscription_getHateoasRootSoftwareInstance
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
def test_getHateoasInstanceList_wrong_ACCEPT(self):
@changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_wrong_ACCEPT(self):
subscription = self._makeHostingSubscription()
fake_request = do_fake_request("GET")
result = subscription.HostingSubscription_getHateoasInstanceList(
result = subscription.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
def test_getHateoasInstanceList_bad_method(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.HostingSubscription_getHateoasInstanceList(
result = self.portal.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
def test_requestHateoasHostingSubscription_not_person_context(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_not_hosting_subscription_context(self):
fake_request = do_fake_request("GET")
result = self.portal.HostingSubscription_getHateoasInstanceList(
result = self.portal.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
def test_getHateoasInstanceList_person_result(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_person_result(self):
subscription = self._makeHostingSubscription()
instance= self._makeInstance()
instance.edit(specialise_value=subscription)
instance = self._makeInstance()
instance.edit(specialise_value=subscription, title=subscription.getTitle())
subscription.edit(predecessor_value=instance)
self.tic()
fake_request = do_fake_request("GET")
result = subscription.HostingSubscription_getHateoasInstanceList(
result = subscription.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.collection"
"application/hal+json"
)
self.assertEquals(result, json.dumps({
'_class': 'slapos.org.collection',
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
"href": "http://example.org/bar"
},
"item": [{
"href": "%s/Instance_getHateoas" % \
"content": [{
"href": "%s/ERP5Document_getHateoas" % \
instance.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.instance"
}],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(),
"title": "Hosting Subscription"
},
},
}))
}, indent=2))
class TestSlapOSInstance_getHateoas(testSlapOSMixin):
class TestSlapOSInstance_getHateoasNews(TestSlapOSHypermediaMixin):
def _makeInstance(self):
instance = self.portal.software_instance_module\
......@@ -756,87 +695,78 @@ class TestSlapOSInstance_getHateoas(testSlapOSMixin):
self.tic()
return instance
def beforeTearDown(self):
transaction.abort()
def test_getHateoasInstance_REQUEST_mandatory(self):
@changeSkin('Hal')
def test_getHateoasNewsInstance_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Instance_getHateoas
self.portal.Instance_getHateoasNews
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
def test_getHateoasInstance_wrong_ACCEPT(self):
@changeSkin('Hal')
def test_getHateoasNewsInstance_wrong_ACCEPT(self):
instance = self._makeInstance()
fake_request = do_fake_request("GET")
result = instance.Instance_getHateoas(
result = instance.Instance_getHateoasNews(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.instance"')
def test_getHateoasInstance_bad_method(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasNewsInstance_bad_method(self):
instance = self._makeInstance()
fake_request = do_fake_request("POST")
result = instance.Instance_getHateoas(
result = instance.Instance_getHateoasNews(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.instance"')
def test_getHateoasInstance_not_instance_context(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasNewsInstance_not_instance_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Instance_getHateoas(REQUEST=fake_request)
result = self.portal.Instance_getHateoasNews(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.instance"')
def test_getHateoasInstance_result(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasNewsInstance_result(self):
instance = self._makeInstance()
fake_request = do_fake_request("GET")
result = instance.Instance_getHateoas(
result = instance.Instance_getHateoasNews(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.instance"
"application/hal+json"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.instance',
'title': instance.getTitle(),
'slave': False,
'software_type': instance.getSourceReference(),
'parameter': instance.getInstanceXmlAsDict(),
'sla': instance.getSlaXmlAsDict(),
'connection': instance.getConnectionXmlAsDict(),
'status': 'destroyed',
'news': [{
"user": "SlapOS Master",
"text": "#error no data found for %s" % instance.getReference()
}],
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.instance"
"href": "http://example.org/bar"
},
"http://slapos.org/reg/news": {
"href": "%s/Instance_getHateoasNews" % instance.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.news"
},
"http://slapos.org/reg/release": {
"href": instance.getUrlString(),
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
instance.getRelativeUrl(),
"title": "Software Instance"
},
},
})))
}, indent=2)))
class TestSlapOSInstance_getHateoasNews(testSlapOSMixin):
class TestSlapOSInstance_getHateoasInformation(TestSlapOSHypermediaMixin):
def _makeInstance(self):
instance = self.portal.software_instance_module\
......@@ -853,121 +783,95 @@ class TestSlapOSInstance_getHateoasNews(testSlapOSMixin):
self.tic()
return instance
def beforeTearDown(self):
transaction.abort()
def test_getHateoasNewsInstance_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Instance_getHateoasNews
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
def test_getHateoasNewsInstance_wrong_ACCEPT(self):
instance = self._makeInstance()
@changeSkin('Hal')
def test_getHateoas_wrong_ACCEPT(self):
fake_request = do_fake_request("GET")
result = instance.Instance_getHateoasNews(
REQUEST=fake_request)
result = self.portal.Instance_getHateoasInformation(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.news"')
def test_getHateoasNewsInstance_bad_method(self):
instance = self._makeInstance()
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_bad_method(self):
fake_request = do_fake_request("POST")
result = instance.Instance_getHateoasNews(
result = self.portal.Instance_getHateoasInformation(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.news"')
def test_getHateoasNewsInstance_not_instance_context(self):
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_request_not_correct_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Instance_getHateoasNews(REQUEST=fake_request)
result = self.portal.Instance_getHateoasInformation(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/vnd.slapos.org.hal+json; ' \
'class=slapos.org.news"')
def test_getHateoasNewsInstance_result(self):
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_result(self):
instance = self._makeInstance()
instance.edit(url_string="http://foo.com/software.cfg")
self.portal.portal_workflow._jumpToStateFor(instance,
'start_requested')
fake_request = do_fake_request("GET")
result = instance.Instance_getHateoasNews(
result = instance.Instance_getHateoasInformation(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.news"
"application/hal+json"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.news',
'news': [{
"user": "SlapOS Master",
"text": "#error no data found for %s" % instance.getReference()
}],
'title': instance.getTitle(),
'requested_state': 'started',
'slave': False,
'instance_guid': instance.getId(),
'connection_dict': instance.getConnectionXmlAsDict(),
'parameter_dict': instance.getInstanceXmlAsDict(),
'software_type': instance.getSourceReference(),
'sla_dict': instance.getSlaXmlAsDict(),
'_links': {
"self": {
"href": "http://example.org/bar",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.news"
"href": "http://example.org/foo"
},
"http://slapos.org/reg/instance": {
"href": "%s/Instance_getHateoas" % instance.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.instance"
"software_release": {
"href": "http://foo.com/software.cfg",
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % instance.getRelativeUrl(),
"title": "Software Instance"
},
},
})))
class TestSlapOSPerson_getHateoasComputerList(testSlapOSMixin):
}, indent=2)))
def _makePerson(self):
new_id = self.generateNewId()
person_user = self.portal.person_module.template_member.\
Base_createCloneDocument(batch_mode=1)
person_user.edit(
title="live_test_%s" % new_id,
reference="live_test_%s" % new_id,
default_email_text="live_test_%s@example.org" % new_id,
)
person_user.validate()
for assignment in person_user.contentValues(portal_type="Assignment"):
assignment.open()
self.tic()
return person_user
def _makeComputer(self):
computer = self.portal.computer_module\
.template_computer.Base_createCloneDocument(batch_mode=1)
computer.validate()
return computer
class TestSlapOSPerson_getHateoasComputerList(TestSlapOSHypermediaMixin):
@changeSkin('Hal')
def test_getHateoasComputerList_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Person_getHateoasComputerList
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasComputerList_wrong_ACCEPT(self):
fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoasComputerList(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasComputerList_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.Person_getHateoasComputerList(
......@@ -975,143 +879,62 @@ class TestSlapOSPerson_getHateoasComputerList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasComputerList_request_not_correct_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoasComputerList(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasComputerList_result(self):
person_user = self._makePerson()
computer = self._makeComputer()
computer.edit(source_administration_value=person_user)
self.tic()
fake_request = do_fake_request("GET")
self.changeSkin('Hal')
result = person_user.Person_getHateoasComputerList(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.collection"
"application/hal+json"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.collection',
'_links': {
"self": {
"href": "http://example.org/foo",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
"href": "http://example.org/foo"
},
"item": [{
"href": "%s/Computer_getHateoas" % \
computer.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.computer"
}],
},
})))
class TestSlapOSComputer_getHateoas(testSlapOSMixin):
def _makeComputer(self):
computer = self.portal.computer_module\
.template_computer.Base_createCloneDocument(batch_mode=1)
computer.validate()
self.tic()
return computer
def test_getHateoasComputerList_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Computer_getHateoas
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
def test_getHateoas_wrong_ACCEPT(self):
fake_request = do_fake_request("GET")
result = self.portal.Computer_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.computer"')
def test_getHateoas_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.Computer_getHateoas(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.computer"')
def test_getHateoas_request_not_correct_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Computer_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.computer"')
def test_getHateoas_result(self):
computer = self._makeComputer()
fake_request = do_fake_request("GET")
result = computer.Computer_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.computer"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.computer',
'title': computer.getTitle(),
'_links': {
"self": {
"href": "http://example.org/foo",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.computer"
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
person_user.getRelativeUrl(),
"title": "Person"
},
"http://slapos.org/reg/software": {
"href": "%s/Computer_getHateoasSoftwareInstallationList" % \
"content": [{
"href": "%s/ERP5Document_getHateoas" % \
computer.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
},
"title": computer.getTitle()
}],
},
})))
}, indent=2)))
class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
def _makeComputer(self):
computer = self.portal.computer_module\
.template_computer.Base_createCloneDocument(batch_mode=1)
computer.validate()
return computer
def _makeSoftwareInstallation(self):
software_installation = self.portal.software_installation_module\
.template_software_installation.Base_createCloneDocument(batch_mode=1)
software_installation.validate()
return software_installation
class TestSlapOSComputer_getHateoasSoftwareInstallationList(TestSlapOSHypermediaMixin):
@changeSkin('Hal')
def test_getSoftwareInstallationList_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Computer_getHateoasSoftwareInstallationList
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getSoftwareInstallationList_wrong_ACCEPT(self):
fake_request = do_fake_request("GET")
result = self.portal.Computer_getHateoasSoftwareInstallationList(
......@@ -1119,9 +942,9 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getSoftwareInstallationList_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.Computer_getHateoasSoftwareInstallationList(
......@@ -1129,9 +952,9 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getSoftwareInstallationList_request_not_correct_context(self):
fake_request = do_fake_request("GET")
result = self.portal.Computer_getHateoasSoftwareInstallationList(
......@@ -1139,110 +962,100 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.collection"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getSoftwareInstallationList_result(self):
computer = self._makeComputer()
software_installation = self._makeSoftwareInstallation()
software_installation.edit(aggregate_value=computer)
software_installation.edit(aggregate_value=computer, url_string='foo')
self.tic()
fake_request = do_fake_request("GET")
result = computer.Computer_getHateoasSoftwareInstallationList(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.collection"
"application/hal+json"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.collection',
'_links': {
"self": {
"href": "http://example.org/foo",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
"href": "http://example.org/foo"
},
"item": [{
"href": "%s/SoftwareInstallation_getHateoas" % \
"content": [{
"href": "%s/ERP5Document_getHateoas" % \
software_installation.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.software_installation"
"title": "foo"
}],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % computer.getRelativeUrl(),
"title": "Computer"
},
},
})))
}, indent=2)))
class TestSlapOSSoftwareInstallation_getHateoas(testSlapOSMixin):
class TestSlapOSSoftwareInstallation_getHateoasInformation(TestSlapOSHypermediaMixin):
def _makeSoftwareInstallation(self):
software_installation = self.portal.software_installation_module\
.template_software_installation.Base_createCloneDocument(batch_mode=1)
software_installation.validate()
return software_installation
def test_getHateoas_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.SoftwareInstallation_getHateoas
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoas_wrong_ACCEPT(self):
fake_request = do_fake_request("GET")
result = self.portal.SoftwareInstallation_getHateoas(REQUEST=fake_request)
result = self.portal.SoftwareInstallation_getHateoasInformation(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.software_installation"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_bad_method(self):
fake_request = do_fake_request("POST")
result = self.portal.SoftwareInstallation_getHateoas(
result = self.portal.SoftwareInstallation_getHateoasInformation(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.software_installation"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_request_not_correct_context(self):
fake_request = do_fake_request("GET")
result = self.portal.SoftwareInstallation_getHateoas(REQUEST=fake_request)
result = self.portal.SoftwareInstallation_getHateoasInformation(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs',
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \
'class=slapos.org.software_installation"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_result(self):
software_installation = self._makeSoftwareInstallation()
software_installation.edit(url_string="http://foo.com/software.cfg")
self.portal.portal_workflow._jumpToStateFor(software_installation,
'start_requested')
fake_request = do_fake_request("GET")
result = software_installation.SoftwareInstallation_getHateoas(
result = software_installation.SoftwareInstallation_getHateoasInformation(
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/vnd.slapos.org.hal+json; class=slapos.org.software_installation"
"application/hal+json"
)
self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.software_installation',
'title': software_installation.getTitle(),
'status': 'started',
'_links': {
"self": {
"href": "http://example.org/foo",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.software_installation"
"href": "http://example.org/foo"
},
"software_release": {
"href": "http://foo.com/software.cfg",
},
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % software_installation.getRelativeUrl(),
"title": "Software Installation"
},
},
})))
}, indent=2)))
erp5_hal_json_style
slapos_cloud
slapos_slap_tool
\ No newline at end of file
slapos_slap_tool
4
\ No newline at end of file
5
\ No newline at end of file
Computer | get_hateoas_software_installation_list
Hosting Subscription | get_hateoas_instance_list
Hosting Subscription | get_hateoas_root_instance
Person | get_hateoas_computer_list
Person | get_hateoas_hosting_subscription_list
Person | get_hateoas_information
Person | request_hateoas_hosting_subscription
Software Installation | get_hateoas_information
Software Instance | get_hateoas_information
Software Instance | get_hateoas_news
\ No newline at end of file
action_type/object_slap
action_type/object_slap_post
\ 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