[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 ...@@ -56,23 +56,21 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.master\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
else:\n \n
import json\n import json\n
result_dict = {\n result_dict = {\n
\'_class\': \'slapos.org.master\',\n
# \'title\': \'Vifib SlapOS Master\',\n # \'title\': \'Vifib SlapOS Master\',\n
# \'description\': \'Reference implementation of the SlapOS Master specifications.\',\n # \'description\': \'Reference implementation of the SlapOS Master specifications.\',\n
\'_links\': {\n \'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n "self": { "href": context.Base_getRequestUrl() },\n
"type": type },\n
# "http://slapos.org/reg/edit": {\n # "http://slapos.org/reg/edit": {\n
# "href": "/edit",\n # "href": "/edit",\n
# "method": "PUT",\n # "method": "PUT",\n
...@@ -83,21 +81,21 @@ else:\n ...@@ -83,21 +81,21 @@ else:\n
# "method": "POST",\n # "method": "POST",\n
# "type": "application/json; class=slapos.org.person",\n # "type": "application/json; class=slapos.org.person",\n
# },\n # },\n
},\n },\n
}\n }\n
\n \n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
# XXX Handle also other kind of users: instance, computer, master\n # XXX Handle also other kind of users: instance, computer, master\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\n if person is not None:\n
result_dict[\'_links\'][\'http://slapos.org/reg/me\'] = {\n result_dict[\'_links\'][\'action_object_jump\'] = {\n
\'href\': \'%s/Person_getHateoas\' % person.absolute_url(),\n \'href\': \'%s/ERP5Document_getHateoas\' % person.absolute_url(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.person"\n \'title\': \'Person\'\n
}\n }\n
\n \n
response.setHeader(\'Content-Type\', type)\n response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n return json.dumps(result_dict, indent=2)\n
</string> </value> </string> </value>
</item> </item>
<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 ...@@ -56,41 +56,43 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Computer":\n elif context.getPortalType() != "Computer":\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\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 \n
for sql_obj in context.getPortalObject().portal_catalog(\n import json\n
portal_type=\'Software Installation\',\n result_dict = {\n
default_aggregate_uid=context.getUid(),\n \'_links\': {\n
validation_state=\'validated\',\n "self": { "href": context.Base_getRequestUrl() },\n
):\n "index": {\n
obj = sql_obj.getObject()\n "href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
result_dict[\'_links\'][\'item\'].append({\n "title": "Computer"\n
\'href\': \'%s/SoftwareInstallation_getHateoas\' % obj.absolute_url(),\n },\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.software_installation\',\n "content": [],\n
})\n },\n
}\n
\n \n
response.setHeader(\'Content-Type\', type)\n for sql_obj in context.getPortalObject().portal_catalog(\n
return json.dumps(result_dict)\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> </string> </value>
</item> </item>
<item> <item>
......
...@@ -56,40 +56,42 @@ if REQUEST is None:\n ...@@ -56,40 +56,42 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Hosting Subscription":\n elif context.getPortalType() != "Hosting Subscription":\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\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 \n
for sql_obj in context.getPortalObject().portal_catalog(\n import json\n
portal_type=[\'Software Instance\', \'Slave Instance\'],\n result_dict = {\n
default_specialise_uid=context.getUid(),\n \'_links\': {\n
):\n "self": { "href": context.Base_getRequestUrl() },\n
obj = sql_obj.getObject()\n "content": [],\n
result_dict[\'_links\'][\'item\'].append({\n "index": {\n
\'href\': \'%s/Instance_getHateoas\' % obj.absolute_url(),\n "href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.instance\',\n "title": "Hosting Subscription"\n
})\n },\n
},\n
}\n
\n \n
response.setHeader(\'Content-Type\', type)\n for sql_obj in context.getPortalObject().portal_catalog(\n
return json.dumps(result_dict)\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> </string> </value>
</item> </item>
<item> <item>
......
...@@ -56,39 +56,42 @@ if REQUEST is None:\n ...@@ -56,39 +56,42 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\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 \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Hosting Subscription":\n elif context.getPortalType() != "Hosting Subscription":\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\n return ""\n
else:\n
\n
# XXX Set more properties on the document\n
\n \n
import json\n instance_list = context.getPredecessorValueList()\n
result_dict = {\n for instance in instance_list:\n
\'_class\': \'slapos.org.hosting_subscription\',\n if instance.getTitle() == context.getTitle():\n
\'title\': context.getTitle(),\n root_instance = instance\n
\'_links\': {\n break\n
"self": { "href": context.Base_getRequestUrl(),\n else:\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.hosting_subscription" },\n raise Exception(\'Root instance not found.\')\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
\n \n
},\n import json\n
}\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 \n
response.setHeader(\'Content-Type\', type)\n response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n return json.dumps(result_dict, indent=2)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -97,7 +100,7 @@ else:\n ...@@ -97,7 +100,7 @@ else:\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>HostingSubscription_getHateoas</string> </value> <value> <string>HostingSubscription_getHateoasRootSoftwareInstance</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </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 ...@@ -56,39 +56,49 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.computer\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Computer":\n elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\n return ""\n
else:\n
\n
# XXX Set more properties on the document\n
\n \n
import json\n if context.getSlapState() == "stop_requested":\n
result_dict = {\n state = \'stopped\'\n
\'_class\': \'slapos.org.computer\',\n elif context.getSlapState() == "start_requested":\n
\'title\': context.getTitle(),\n state = \'started\'\n
\'_links\': {\n else:\n
"self": { "href": context.Base_getRequestUrl(),\n state = \'destroyed\'\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
\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
\n \n
response.setHeader(\'Content-Type\', type)\n response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n return json.dumps(result_dict, indent=2)\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -97,7 +107,7 @@ else:\n ...@@ -97,7 +107,7 @@ else:\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Computer_getHateoas</string> </value> <value> <string>Instance_getHateoasInformation</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -56,47 +56,47 @@ if REQUEST is None:\n ...@@ -56,47 +56,47 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.news\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n elif context.getPortalType() not in ["Software Instance", "Slave Instance"]:\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\n return ""\n
else:\n
\n \n
import json\n import json\n
\n \n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n plugin_path=\'portal_memcached/default_memcached_plugin\')\n
try:\n try:\n
d = memcached_dict[context.getReference()]\n d = memcached_dict[context.getReference()]\n
except KeyError:\n except KeyError:\n
d = {\n d = {\n
"user": "SlapOS Master",\n "user": "SlapOS Master",\n
"text": "#error no data found for %s" % context.getReference()\n "text": "#error no data found for %s" % context.getReference()\n
}\n }\n
else:\n else:\n
d = json.loads(d)\n d = json.loads(d)\n
\n \n
result_dict = {\n result_dict = {\n
\'_class\': \'slapos.org.news\',\n \'news\': [d],\n
\'news\': [d],\n \'_links\': {\n
\'_links\': {\n "self": { "href": context.Base_getRequestUrl() },\n
"self": { "href": context.Base_getRequestUrl(),\n # XXX current type\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.news" },\n "index": {\n
"http://slapos.org/reg/instance": { "href": "%s/Instance_getHateoas" % context.absolute_url(),\n "href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.instance" },\n "title": "Software Instance"\n
},\n },\n
}\n },\n
}\n
\n \n
response.setHeader(\'Content-Type\', type)\n response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n return json.dumps(result_dict, indent=2)\n
</string> </value> </string> </value>
</item> </item>
<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 ...@@ -56,40 +56,43 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Person":\n elif context.getPortalType() != "Person":\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\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 \n
for sql_obj in context.getPortalObject().portal_catalog(\n import json\n
portal_type="Computer",\n result_dict = {\n
default_source_administration_uid=context.getUid(),\n \'_links\': {\n
):\n "self": { "href": context.Base_getRequestUrl() },\n
obj = sql_obj.getObject()\n # XXX current type\n
result_dict[\'_links\'][\'item\'].append({\n "index": {\n
\'href\': \'%s/Computer_getHateoas\' % obj.absolute_url(),\n "href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.computer\',\n "title": "Person"\n
})\n },\n
"content": [],\n
},\n
}\n
\n \n
response.setHeader(\'Content-Type\', type)\n for sql_obj in context.getPortalObject().portal_catalog(\n
return json.dumps(result_dict)\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> </string> </value>
</item> </item>
<item> <item>
......
...@@ -56,40 +56,43 @@ if REQUEST is None:\n ...@@ -56,40 +56,43 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/vnd.slapos.org.hal+json; class=slapos.org.collection\'\n mime_type = \'application/hal+json\'\n
\n \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Person":\n elif context.getPortalType() != "Person":\n
response.setStatus(403)\n response.setStatus(403)\n
return ""\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 \n
for sql_obj in context.getPortalObject().portal_catalog(\n import json\n
portal_type="Hosting Subscription",\n result_dict = {\n
default_destination_section_uid=context.getUid(),\n \'_links\': {\n
):\n "self": { "href": context.Base_getRequestUrl() },\n
obj = sql_obj.getObject()\n # XXX current type\n
result_dict[\'_links\'][\'item\'].append({\n "index": {\n
\'href\': \'%s/HostingSubscription_getHateoas\' % obj.absolute_url(),\n "href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
\'type\': \'application/vnd.slapos.org.hal+json; class=slapos.org.hosting_subscription\',\n "title": "Person"\n
})\n },\n
"content": [],\n
},\n
}\n
\n \n
response.setHeader(\'Content-Type\', type)\n for sql_obj in context.getPortalObject().portal_catalog(\n
return json.dumps(result_dict)\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> </string> </value>
</item> </item>
<item> <item>
......
...@@ -58,12 +58,12 @@ if REQUEST is None:\n ...@@ -58,12 +58,12 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\n response = REQUEST.RESPONSE\n
type = \'application/json; class=slapos.org.hosting_subscription\'\n mime_type = \'application/json\'\n
\n \n
if REQUEST.other[\'method\'] != "POST":\n if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_getRequestHeader(\'Content-Type\'):\n elif mime_type != context.Base_getRequestHeader(\'Content-Type\'):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() != "Person":\n elif context.getPortalType() != "Person":\n
......
...@@ -56,12 +56,12 @@ if REQUEST is None:\n ...@@ -56,12 +56,12 @@ if REQUEST is None:\n
raise Unauthorized\n raise Unauthorized\n
\n \n
response = REQUEST.RESPONSE\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 \n
if REQUEST.other[\'method\'] != "GET":\n if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n response.setStatus(405)\n
return ""\n return ""\n
elif type != context.Base_handleAcceptHeader([type]):\n elif mime_type != context.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n response.setStatus(406)\n
return ""\n return ""\n
elif context.getPortalType() not in ["Software Installation"]:\n elif context.getPortalType() not in ["Software Installation"]:\n
...@@ -78,19 +78,21 @@ else:\n ...@@ -78,19 +78,21 @@ else:\n
\n \n
import json\n import json\n
result_dict = {\n result_dict = {\n
\'_class\': \'slapos.org.software_installation\',\n
\'title\': context.getTitle(),\n \'title\': context.getTitle(),\n
\'status\': state,\n \'status\': state,\n
\'_links\': {\n \'_links\': {\n
"self": { "href": context.Base_getRequestUrl(),\n "self": { "href": context.Base_getRequestUrl() },\n
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.software_installation" },\n "index": {\n
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % context.getRelativeUrl(),\n
"title": "Software Installation"\n
},\n
},\n },\n
}\n }\n
url_string = context.getUrlString(None)\n url_string = context.getUrlString(None)\n
if url_string is not None:\n if url_string is not None:\n
result_dict["_links"]["software_release"] = { "href": url_string }\n result_dict["_links"]["software_release"] = { "href": url_string }\n
\n \n
response.setHeader(\'Content-Type\', type)\n response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict)\n return json.dumps(result_dict)\n
</string> </value> </string> </value>
</item> </item>
...@@ -100,7 +102,7 @@ else:\n ...@@ -100,7 +102,7 @@ else:\n
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>SoftwareInstallation_getHateoas</string> </value> <value> <string>SoftwareInstallation_getHateoasInformation</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -8,6 +8,15 @@ import httplib ...@@ -8,6 +8,15 @@ import httplib
import urlparse import urlparse
import base64 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): class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
def _makeUser(self): def _makeUser(self):
...@@ -31,20 +40,28 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -31,20 +40,28 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
erp5_person = self._makeUser() erp5_person = self._makeUser()
authorization = 'Basic %s' % base64.b64encode( authorization = 'Basic %s' % base64.b64encode(
"%s:%s" % (erp5_person.getReference(), erp5_person.getReference())) "%s:%s" % (erp5_person.getReference(), erp5_person.getReference()))
content_type = "application/hal+json"
# XXX Default home url. 'Hardcoded' in client. # XXX Default home url. 'Hardcoded' in client.
api_scheme, api_netloc, api_path, api_query, \ api_scheme, api_netloc, api_path, api_query, \
api_fragment = urlparse.urlsplit('%s/Base_getHateoasMaster' % \ api_fragment = urlparse.urlsplit('%s/Base_getHateoasMaster' % \
self.portal.absolute_url()) 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 # 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( connection.request(
method='GET', method='GET',
url='%s/Base_getHateoasMaster' % \ url='%s/web_site_module/hateoas/Base_getHateoasMaster' % \
self.portal.absolute_url(), self.portal.absolute_url(),
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
...@@ -53,7 +70,6 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -53,7 +70,6 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
body="", body="",
) )
response = connection.getresponse() response = connection.getresponse()
self.assertEquals(response.status, 200) self.assertEquals(response.status, 200)
self.assertEquals(response.getheader('Content-Type'), content_type) self.assertEquals(response.getheader('Content-Type'), content_type)
home_page_hal = json.loads(response.read()) home_page_hal = json.loads(response.read())
...@@ -61,21 +77,20 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -61,21 +77,20 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Fetch the user hal # Fetch the user hal
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; class=slapos.org.person" user_link_dict = home_page_hal['_links']['action_object_jump']
user_link_dict = home_page_hal['_links']['http://slapos.org/reg/me'] self.assertNotEqual(user_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'], url=user_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': user_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
response = connection.getresponse() response = connection.getresponse()
self.assertEquals(response.status, 200) self.assertEquals(response.status, 200)
self.assertEquals(response.getheader('Content-Type'), content_type) self.assertEquals(response.getheader('Content-Type'), content_type)
user_hal = json.loads(response.read()) user_hal = json.loads(response.read())
...@@ -83,17 +98,19 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -83,17 +98,19 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Run method to request an hosting subscription # 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( connection.request(
method=request_link_dict.get('method', 'GET'), method=request_link_dict.get('method', 'POST'),
url=request_link_dict['href'], url=request_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Content-Type': request_link_dict['type'], 'Content-Type': 'application/json',
}, },
body=json.dumps({ body=json.dumps({
'software_release': 'http://example.orgé', 'software_release': 'http://example.orgé',
...@@ -114,18 +131,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -114,18 +131,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get user's hosting subscription list # Get user's hosting subscription list
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \ user_link_dict = hateoasGetLinkFromLinks(
"class=slapos.org.collection" user_hal['_links']['action_object_slap'],
user_link_dict = user_hal['_links']\ 'getHateoasHostingSubscriptionList'
['http://slapos.org/reg/hosting_subscription'] )
self.assertNotEqual(user_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'], url=user_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': user_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -138,18 +155,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -138,18 +155,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get user's hosting subscription # 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']\ subscription_link_dict = subscription_collection_hal['_links']\
['item'][0] ['content'][0]
self.assertNotEqual(subscription_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=subscription_link_dict.get('method', 'GET'), method=subscription_link_dict.get('method', 'GET'),
url=subscription_link_dict['href'], url=subscription_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': subscription_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -162,18 +177,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -162,18 +177,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get hosting subscription's instance list # Get hosting subscription's instance list
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \ user_link_dict = hateoasGetLinkFromLinks(
"class=slapos.org.collection" subscription_hal['_links']['action_object_slap'],
user_link_dict = subscription_hal['_links']\ 'getHateoasInstanceList'
['http://slapos.org/reg/instance'] )
self.assertNotEqual(user_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'], url=user_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': user_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -186,18 +201,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -186,18 +201,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get instance # Get instance
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.instance"
subscription_link_dict = instance_collection_hal['_links']\ subscription_link_dict = instance_collection_hal['_links']\
['item'][0] ['content'][0]
self.assertNotEqual(subscription_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=subscription_link_dict.get('method', 'GET'), method=subscription_link_dict.get('method', 'GET'),
url=subscription_link_dict['href'], url=subscription_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': subscription_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -210,18 +223,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -210,18 +223,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get instance news # Get instance news
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \ news_link_dict = hateoasGetLinkFromLinks(
"class=slapos.org.news" instance_hal['_links']['action_object_slap'],
news_link_dict = instance_hal['_links']\ 'getHateoasNews'
['http://slapos.org/reg/news'] )
self.assertNotEqual(news_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=news_link_dict.get('method', 'GET'), method=news_link_dict.get('method', 'GET'),
url=news_link_dict['href'], url=news_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': news_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -249,18 +262,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -249,18 +262,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get user's computer list # Get user's computer list
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \ user_link_dict = hateoasGetLinkFromLinks(
"class=slapos.org.collection" user_hal['_links']['action_object_slap'],
user_link_dict = user_hal['_links']\ 'getHateoasComputerList'
['http://slapos.org/reg/computer'] )
self.assertNotEqual(user_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=user_link_dict.get('method', 'GET'), method=user_link_dict.get('method', 'GET'),
url=user_link_dict['href'], url=user_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': user_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -273,18 +286,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -273,18 +286,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get user's computer # Get user's computer
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.computer"
computer_link_dict = computer_collection_hal['_links']\ computer_link_dict = computer_collection_hal['_links']\
['item'][0] ['content'][0]
self.assertNotEqual(computer_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=computer_link_dict.get('method', 'GET'), method=computer_link_dict.get('method', 'GET'),
url=computer_link_dict['href'], url=computer_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': computer_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -297,18 +308,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -297,18 +308,18 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get computer's software list # Get computer's software list
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \ computer_link_dict = hateoasGetLinkFromLinks(
"class=slapos.org.collection" computer_hal['_links']['action_object_slap'],
computer_link_dict = computer_hal['_links']\ 'getHateoasSoftwareInstallationList'
['http://slapos.org/reg/software'] )
self.assertNotEqual(computer_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=computer_link_dict.get('method', 'GET'), method=computer_link_dict.get('method', 'GET'),
url=computer_link_dict['href'], url=computer_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': computer_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
...@@ -321,18 +332,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin): ...@@ -321,18 +332,16 @@ class TestSlapOSHypermediaPersonScenario(testSlapOSMixin):
##################################################### #####################################################
# Get user's software # Get user's software
##################################################### #####################################################
content_type = "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.software_installation"
software_link_dict = software_collection_hal['_links']\ software_link_dict = software_collection_hal['_links']\
['item'][0] ['content'][0]
self.assertNotEqual(software_link_dict, None)
connection = httplib.HTTPConnection(api_netloc) connection = getNewHttpConnection(api_netloc)
connection.request( connection.request(
method=software_link_dict.get('method', 'GET'), method=software_link_dict.get('method', 'GET'),
url=software_link_dict['href'], url=software_link_dict['href'],
headers={ headers={
'Authorization': authorization, 'Authorization': authorization,
'Accept': software_link_dict['type'], 'Accept': content_type,
}, },
body="", body="",
) )
......
...@@ -17,6 +17,20 @@ import sys ...@@ -17,6 +17,20 @@ import sys
import json import json
import StringIO 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 simulate(script_id, params_string, code_string):
def upperWrap(f): def upperWrap(f):
...@@ -55,11 +69,16 @@ def do_fake_request(request_method, headers={}): ...@@ -55,11 +69,16 @@ def do_fake_request(request_method, headers={}):
env.update(headers) env.update(headers)
return HTTPRequest(StringIO.StringIO(), env, HTTPResponse()) 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): def beforeTearDown(self):
transaction.abort() transaction.abort()
class TestBase_getRequestHeader(ERP5HALJSONStyleSkinsMixin):
def test_getRequestHeader_REQUEST_disallowed(self): def test_getRequestHeader_REQUEST_disallowed(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
...@@ -83,11 +102,8 @@ class TestSlapOSBase_getRequestHeader(testSlapOSMixin): ...@@ -83,11 +102,8 @@ class TestSlapOSBase_getRequestHeader(testSlapOSMixin):
def test_getRequestHeader_matching_key(self): def test_getRequestHeader_matching_key(self):
pass pass
class TestSlapOSBase_getRequestUrl(testSlapOSMixin): # XXX to be migrated to erp5_hal_json_style bt
class TestBase_getRequestUrl(ERP5HALJSONStyleSkinsMixin):
def beforeTearDown(self):
transaction.abort()
def test_getRequestUrl_REQUEST_disallowed(self): def test_getRequestUrl_REQUEST_disallowed(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
...@@ -98,11 +114,7 @@ class TestSlapOSBase_getRequestUrl(testSlapOSMixin): ...@@ -98,11 +114,7 @@ class TestSlapOSBase_getRequestUrl(testSlapOSMixin):
def test_getRequestUrl_matching_key(self): def test_getRequestUrl_matching_key(self):
pass pass
class TestSlapOSBase_getRequestBody(testSlapOSMixin): class TestBase_getRequestBody(ERP5HALJSONStyleSkinsMixin):
def beforeTearDown(self):
transaction.abort()
def test_getRequestBody_REQUEST_disallowed(self): def test_getRequestBody_REQUEST_disallowed(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
...@@ -113,11 +125,7 @@ class TestSlapOSBase_getRequestBody(testSlapOSMixin): ...@@ -113,11 +125,7 @@ class TestSlapOSBase_getRequestBody(testSlapOSMixin):
def test_getRequestBody_matching_key(self): def test_getRequestBody_matching_key(self):
pass pass
class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin): class TestBase_handleAcceptHeader(ERP5HALJSONStyleSkinsMixin):
def beforeTearDown(self):
transaction.abort()
def test_handleAcceptHeader_REQUEST_disallowed(self): def test_handleAcceptHeader_REQUEST_disallowed(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
...@@ -126,6 +134,7 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin): ...@@ -126,6 +134,7 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
REQUEST={}) REQUEST={})
@simulate('Base_getRequestHeader', '*args, **kwargs', 'return "*/*"') @simulate('Base_getRequestHeader', '*args, **kwargs', 'return "*/*"')
@changeSkin('Hal')
def test_handleAcceptHeader_star_accept(self): def test_handleAcceptHeader_star_accept(self):
self.assertEquals( self.assertEquals(
self.portal.Base_handleAcceptHeader(['application/vnd+test', self.portal.Base_handleAcceptHeader(['application/vnd+test',
...@@ -133,8 +142,9 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin): ...@@ -133,8 +142,9 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
'application/vnd+test' 'application/vnd+test'
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+2test"') 'return "application/vnd+2test"')
@changeSkin('Hal')
def test_handleAcceptHeader_matching_type(self): def test_handleAcceptHeader_matching_type(self):
self.assertEquals( self.assertEquals(
self.portal.Base_handleAcceptHeader(['application/vnd+test', self.portal.Base_handleAcceptHeader(['application/vnd+test',
...@@ -142,15 +152,23 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin): ...@@ -142,15 +152,23 @@ class TestSlapOSBase_handleAcceptHeader(testSlapOSMixin):
'application/vnd+2test' 'application/vnd+2test'
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+2test"') 'return "application/vnd+2test"')
@changeSkin('Hal')
def test_handleAcceptHeader_non_matching_type(self): def test_handleAcceptHeader_non_matching_type(self):
self.assertEquals( self.assertEquals(
self.portal.Base_handleAcceptHeader(['application/vnd+test']), self.portal.Base_handleAcceptHeader(['application/vnd+test']),
None 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): def _makePerson(self):
new_id = self.generateNewId() new_id = self.generateNewId()
...@@ -166,212 +184,195 @@ class TestSlapOSBase_getHateoasMaster(testSlapOSMixin): ...@@ -166,212 +184,195 @@ class TestSlapOSBase_getHateoasMaster(testSlapOSMixin):
for assignment in person_user.contentValues(portal_type="Assignment"): for assignment in person_user.contentValues(portal_type="Assignment"):
assignment.open() assignment.open()
self.tic() self.tic()
self.changeSkin('Hal')
return person_user return person_user
def beforeTearDown(self): def _makeHostingSubscription(self):
transaction.abort() 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): def test_getHateoasMaster_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.Base_getHateoasMaster self.portal.Base_getHateoasMaster
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasMaster_wrong_ACCEPT(self): def test_getHateoasMaster_wrong_ACCEPT(self):
#self.changeSkin('Hal')
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request) result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.master"') @changeSkin('Hal')
def test_getHateoasMaster_bad_method(self): def test_getHateoasMaster_bad_method(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request) result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.master"') @changeSkin('Hal')
def test_getHateoasMaster_anonymous_result(self): def test_getHateoasMaster_anonymous_result(self):
self.logout() self.logout()
self.changeSkin('Hal')
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request) result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(result, json.dumps({
'_class': 'slapos.org.master',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/bar", "href": "http://example.org/bar"
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.master"
}, },
}, },
})) }, indent=2))
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.master"') @changeSkin('Hal')
def test_getHateoasMaster_person_result(self): def test_getHateoasMaster_person_result(self):
person_user = self._makePerson() person_user = self._makePerson()
self.login(person_user.getReference()) self.login(person_user.getReference())
self.changeSkin('Hal')
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Base_getHateoasMaster(REQUEST=fake_request) result = self.portal.Base_getHateoasMaster(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(result, json.dumps({
'_class': 'slapos.org.master',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/bar", "href": "http://example.org/bar"
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.master"
}, },
"http://slapos.org/reg/me": { "action_object_jump": {
"href": "%s/Person_getHateoas" % person_user.absolute_url(), "href": "%s/ERP5Document_getHateoas" % person_user.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; class=slapos.org.person" "title": "Person"
}, },
}, },
})) }, indent=2))
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,
)
person_user.validate() class TestSlapOSPerson_requestHateoasHostingSubscription(TestSlapOSHypermediaMixin):
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()
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_REQUEST_mandatory(self): def test_requestHateoasHostingSubscription_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.Person_requestHateoasHostingSubscription self.portal.Person_requestHateoasHostingSubscription
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
@changeSkin('Hal')
def test_requestHateoasHostingSubscription_wrong_CONTENT(self): def test_requestHateoasHostingSubscription_wrong_CONTENT(self):
person_user = self._makePerson() person_user = self._makePerson()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
...@@ -380,9 +381,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -380,9 +381,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \ 'return "application/json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_bad_method(self): def test_requestHateoasHostingSubscription_bad_method(self):
person_user = self._makePerson() person_user = self._makePerson()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
...@@ -391,9 +392,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -391,9 +392,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \ 'return "application/json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_not_person_context(self): def test_requestHateoasHostingSubscription_not_person_context(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.Person_requestHateoasHostingSubscription( result = self.portal.Person_requestHateoasHostingSubscription(
...@@ -401,11 +402,11 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -401,11 +402,11 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 403) self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestBody', '*args, **kwargs', @simulate('Base_getRequestBody', '*args, **kwargs',
'return "[}"') 'return "[}"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \ 'return "application/json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_no_json(self): def test_requestHateoasHostingSubscription_no_json(self):
person_user = self._makePerson() person_user = self._makePerson()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
...@@ -414,12 +415,12 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -414,12 +415,12 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 400) self.assertEquals(fake_request.RESPONSE.status, 400)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestBody', '*args, **kwargs', @simulate('Base_getRequestBody', '*args, **kwargs',
'return "%s"' % json.dumps({ 'return "%s"' % json.dumps({
})) }))
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \ 'return "application/json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_missing_parameter(self): def test_requestHateoasHostingSubscription_missing_parameter(self):
person_user = self._makePerson() person_user = self._makePerson()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
...@@ -428,7 +429,7 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -428,7 +429,7 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 400) self.assertEquals(fake_request.RESPONSE.status, 400)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestBody', '*args, **kwargs', @simulate('Base_getRequestBody', '*args, **kwargs',
'return """%s"""' % json.dumps({ 'return """%s"""' % json.dumps({
'software_release': 'http://example.orgé', 'software_release': 'http://example.orgé',
'title': 'a great titleé', 'title': 'a great titleé',
...@@ -438,9 +439,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -438,9 +439,9 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
'slave': False, 'slave': False,
'status': 'started', 'status': 'started',
})) }))
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/json; ' \ 'return "application/json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_result(self): def test_requestHateoasHostingSubscription_result(self):
person_user = self._makePerson() person_user = self._makePerson()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
...@@ -450,58 +451,18 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin): ...@@ -450,58 +451,18 @@ class TestSlapOSPerson_requestHateoasHostingSubscription(testSlapOSMixin):
self.assertEquals(result, "") self.assertEquals(result, "")
# XXX Test that person.request is called. # XXX Test that person.request is called.
class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin): class TestSlapOSPerson_getHateoasHostingSubscriptionList(TestSlapOSHypermediaMixin):
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()
@changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_REQUEST_mandatory(self): def test_getHateoasHostingSubscriptionList_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.Person_getHateoasHostingSubscriptionList self.portal.Person_getHateoasHostingSubscriptionList
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_wrong_ACCEPT(self): def test_getHateoasHostingSubscriptionList_wrong_ACCEPT(self):
person_user = self._makePerson() person_user = self._makePerson()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
...@@ -510,9 +471,9 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin): ...@@ -510,9 +471,9 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getHateoasHostingSubscriptionList_bad_method(self): def test_getHateoasHostingSubscriptionList_bad_method(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.Person_getHateoasHostingSubscriptionList( result = self.portal.Person_getHateoasHostingSubscriptionList(
...@@ -520,21 +481,20 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin): ...@@ -520,21 +481,20 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_not_person_context(self): def test_getHateoasHostingSubscriptionList_not_person_context(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoasHostingSubscriptionList( result = self.portal.Person_getHateoasHostingSubscriptionList(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403) self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"') 'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"')
def test_getHateoasHostingSubscriptionList_person_result(self): def test_getHateoasHostingSubscriptionList_person_result(self):
person_user = self._makePerson() person_user = self._makePerson()
hosting_subscription = self._makeHostingSubscription() hosting_subscription = self._makeHostingSubscription()
...@@ -542,204 +502,183 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin): ...@@ -542,204 +502,183 @@ class TestSlapOSPerson_getHateoasHostingSubscriptionList(testSlapOSMixin):
self.tic() self.tic()
self.login(person_user.getReference()) self.login(person_user.getReference())
self.changeSkin('Hal')
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = person_user.Person_getHateoasHostingSubscriptionList( result = person_user.Person_getHateoasHostingSubscriptionList(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(result, json.dumps({
'_class': 'slapos.org.collection',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/foo", "href": "http://example.org/foo",
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
}, },
"item": [{ "index": {
"href": "%s/HostingSubscription_getHateoas" % \ "href": "urn:jio:get:%s/ERP5Document_getHateoas" % person_user.getRelativeUrl(),
"title": "Person"
},
"content": [{
"href": "%s/ERP5Document_getHateoas" % \
hosting_subscription.absolute_url(), hosting_subscription.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \ "title": "Template Hosting Subscription"
"class=slapos.org.hosting_subscription"
}], }],
}, },
})) }, indent=2))
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
def beforeTearDown(self): class TestSlapOSHostingSubscription_getHateoasInstanceList(TestSlapOSHypermediaMixin):
transaction.abort()
def test_getHateoasHostingSubscription_REQUEST_mandatory(self): @changeSkin('Hal')
def test_getHateoasInstanceList_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.HostingSubscription_getHateoas self.portal.HostingSubscription_getHateoasInstanceList
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
def test_getHateoasHostingSubscription_wrong_ACCEPT(self): @changeSkin('Hal')
hosting_subscription = self._makeHostingSubscription() def test_getHateoasInstanceList_wrong_ACCEPT(self):
subscription = self._makeHostingSubscription()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = hosting_subscription.HostingSubscription_getHateoas( result = subscription.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_getHateoasHostingSubscription_bad_method(self): def test_getHateoasInstanceList_bad_method(self):
hosting_subscription = self._makeHostingSubscription()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = hosting_subscription.HostingSubscription_getHateoas( result = self.portal.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_getHateoasHostingSubscription_not_hosting_subscription_context(self): def test_getHateoasInstanceList_not_hosting_subscription_context(self):
fake_request = do_fake_request("GET") 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(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.hosting_subscription"') @changeSkin('Hal')
def test_getHateoasHostingSubscription_result(self): def test_getHateoasInstanceList_person_result(self):
hosting_subscription = self._makeHostingSubscription() subscription = self._makeHostingSubscription()
instance= self._makeInstance()
instance.edit(specialise_value=subscription)
self.tic()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = hosting_subscription.HostingSubscription_getHateoas( result = subscription.HostingSubscription_getHateoasInstanceList(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(result, json.dumps({
'_class': 'slapos.org.hosting_subscription',
'title': hosting_subscription.getTitle(),
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/bar", "href": "http://example.org/bar"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.hosting_subscription"
}, },
"http://slapos.org/reg/instance": { "content": [{
"href": "%s/HostingSubscription_getHateoasInstanceList" % \ "href": "%s/ERP5Document_getHateoas" % \
hosting_subscription.absolute_url(), instance.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \ "title": "Template Software Instance"
"class=slapos.org.collection" }],
"index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % subscription.getRelativeUrl(),
"title": "Hosting Subscription"
}, },
}, },
})) }, indent=2))
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
def beforeTearDown(self): class TestSlapOSHostingSubscription_getHateoasRootSoftwareInstance(TestSlapOSHypermediaMixin):
transaction.abort()
def test_getHateoasInstanceList_REQUEST_mandatory(self): @changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.HostingSubscription_getHateoasInstanceList self.portal.HostingSubscription_getHateoasRootSoftwareInstance
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
def test_getHateoasInstanceList_wrong_ACCEPT(self): @changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_wrong_ACCEPT(self):
subscription = self._makeHostingSubscription() subscription = self._makeHostingSubscription()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = subscription.HostingSubscription_getHateoasInstanceList( result = subscription.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getHateoasInstanceList_bad_method(self): def test_getHateoasRootSoftwareInstance_bad_method(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.HostingSubscription_getHateoasInstanceList( result = self.portal.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_requestHateoasHostingSubscription_not_person_context(self): def test_getHateoasRootSoftwareInstance_not_hosting_subscription_context(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.HostingSubscription_getHateoasInstanceList( result = self.portal.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403) self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ @simulate('Base_getRequestHeader', '*args, **kwargs',
'class=slapos.org.collection"') 'return "application/hal+json"')
def test_getHateoasInstanceList_person_result(self): @changeSkin('Hal')
def test_getHateoasRootSoftwareInstance_person_result(self):
subscription = self._makeHostingSubscription() subscription = self._makeHostingSubscription()
instance= self._makeInstance() instance = self._makeInstance()
instance.edit(specialise_value=subscription) instance.edit(specialise_value=subscription, title=subscription.getTitle())
subscription.edit(predecessor_value=instance)
self.tic() self.tic()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = subscription.HostingSubscription_getHateoasInstanceList( result = subscription.HostingSubscription_getHateoasRootSoftwareInstance(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(result, json.dumps({
'_class': 'slapos.org.collection',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/bar", "href": "http://example.org/bar"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
}, },
"item": [{ "content": [{
"href": "%s/Instance_getHateoas" % \ "href": "%s/ERP5Document_getHateoas" % \
instance.absolute_url(), 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): def _makeInstance(self):
instance = self.portal.software_instance_module\ instance = self.portal.software_instance_module\
...@@ -756,87 +695,78 @@ class TestSlapOSInstance_getHateoas(testSlapOSMixin): ...@@ -756,87 +695,78 @@ class TestSlapOSInstance_getHateoas(testSlapOSMixin):
self.tic() self.tic()
return instance return instance
def beforeTearDown(self): @changeSkin('Hal')
transaction.abort() def test_getHateoasNewsInstance_REQUEST_mandatory(self):
def test_getHateoasInstance_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.Instance_getHateoas self.portal.Instance_getHateoasNews
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
def test_getHateoasInstance_wrong_ACCEPT(self): @changeSkin('Hal')
def test_getHateoasNewsInstance_wrong_ACCEPT(self):
instance = self._makeInstance() instance = self._makeInstance()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = instance.Instance_getHateoas( result = instance.Instance_getHateoasNews(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.instance"') @changeSkin('Hal')
def test_getHateoasInstance_bad_method(self): def test_getHateoasNewsInstance_bad_method(self):
instance = self._makeInstance() instance = self._makeInstance()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = instance.Instance_getHateoas( result = instance.Instance_getHateoasNews(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.instance"') @changeSkin('Hal')
def test_getHateoasInstance_not_instance_context(self): def test_getHateoasNewsInstance_not_instance_context(self):
fake_request = do_fake_request("GET") 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(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.instance"') @changeSkin('Hal')
def test_getHateoasInstance_result(self): def test_getHateoasNewsInstance_result(self):
instance = self._makeInstance() instance = self._makeInstance()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = instance.Instance_getHateoas( result = instance.Instance_getHateoasNews(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.instance', 'news': [{
'title': instance.getTitle(), "user": "SlapOS Master",
'slave': False, "text": "#error no data found for %s" % instance.getReference()
'software_type': instance.getSourceReference(), }],
'parameter': instance.getInstanceXmlAsDict(),
'sla': instance.getSlaXmlAsDict(),
'connection': instance.getConnectionXmlAsDict(),
'status': 'destroyed',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/bar", "href": "http://example.org/bar"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.instance"
}, },
"http://slapos.org/reg/news": { "index": {
"href": "%s/Instance_getHateoasNews" % instance.absolute_url(), "href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
"type": "application/vnd.slapos.org.hal+json; " \ instance.getRelativeUrl(),
"class=slapos.org.news" "title": "Software Instance"
},
"http://slapos.org/reg/release": {
"href": instance.getUrlString(),
}, },
}, },
}))) }, indent=2)))
class TestSlapOSInstance_getHateoasNews(testSlapOSMixin): class TestSlapOSInstance_getHateoasInformation(TestSlapOSHypermediaMixin):
def _makeInstance(self): def _makeInstance(self):
instance = self.portal.software_instance_module\ instance = self.portal.software_instance_module\
...@@ -853,121 +783,95 @@ class TestSlapOSInstance_getHateoasNews(testSlapOSMixin): ...@@ -853,121 +783,95 @@ class TestSlapOSInstance_getHateoasNews(testSlapOSMixin):
self.tic() self.tic()
return instance return instance
def beforeTearDown(self): @simulate('Base_getRequestHeader', '*args, **kwargs',
transaction.abort()
def test_getHateoasNewsInstance_REQUEST_mandatory(self):
self.assertRaises(
Unauthorized,
self.portal.Instance_getHateoasNews
)
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
def test_getHateoasNewsInstance_wrong_ACCEPT(self): @changeSkin('Hal')
instance = self._makeInstance() def test_getHateoas_wrong_ACCEPT(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = instance.Instance_getHateoasNews( result = self.portal.Instance_getHateoasInformation(REQUEST=fake_request)
REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.news"') @changeSkin('Hal')
def test_getHateoasNewsInstance_bad_method(self): def test_getHateoas_bad_method(self):
instance = self._makeInstance()
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = instance.Instance_getHateoasNews( result = self.portal.Instance_getHateoasInformation(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.news"') @changeSkin('Hal')
def test_getHateoasNewsInstance_not_instance_context(self): def test_getHateoas_request_not_correct_context(self):
fake_request = do_fake_request("GET") 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(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.news"') @changeSkin('Hal')
def test_getHateoasNewsInstance_result(self): def test_getHateoas_result(self):
instance = self._makeInstance() 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") fake_request = do_fake_request("GET")
result = instance.Instance_getHateoasNews( result = instance.Instance_getHateoasInformation(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.news', 'title': instance.getTitle(),
'news': [{ 'requested_state': 'started',
"user": "SlapOS Master", 'slave': False,
"text": "#error no data found for %s" % instance.getReference() 'instance_guid': instance.getId(),
}], 'connection_dict': instance.getConnectionXmlAsDict(),
'parameter_dict': instance.getInstanceXmlAsDict(),
'software_type': instance.getSourceReference(),
'sla_dict': instance.getSlaXmlAsDict(),
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/bar", "href": "http://example.org/foo"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.news"
}, },
"http://slapos.org/reg/instance": { "software_release": {
"href": "%s/Instance_getHateoas" % instance.absolute_url(), "href": "http://foo.com/software.cfg",
"type": "application/vnd.slapos.org.hal+json; " \ },
"class=slapos.org.instance" "index": {
"href": "urn:jio:get:%s/ERP5Document_getHateoas" % instance.getRelativeUrl(),
"title": "Software Instance"
}, },
}, },
}))) }, indent=2)))
class TestSlapOSPerson_getHateoasComputerList(testSlapOSMixin):
def _makePerson(self): class TestSlapOSPerson_getHateoasComputerList(TestSlapOSHypermediaMixin):
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
@changeSkin('Hal')
def test_getHateoasComputerList_REQUEST_mandatory(self): def test_getHateoasComputerList_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.Person_getHateoasComputerList self.portal.Person_getHateoasComputerList
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoasComputerList_wrong_ACCEPT(self): def test_getHateoasComputerList_wrong_ACCEPT(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoasComputerList(REQUEST=fake_request) result = self.portal.Person_getHateoasComputerList(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getHateoasComputerList_bad_method(self): def test_getHateoasComputerList_bad_method(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.Person_getHateoasComputerList( result = self.portal.Person_getHateoasComputerList(
...@@ -975,143 +879,62 @@ class TestSlapOSPerson_getHateoasComputerList(testSlapOSMixin): ...@@ -975,143 +879,62 @@ class TestSlapOSPerson_getHateoasComputerList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getHateoasComputerList_request_not_correct_context(self): def test_getHateoasComputerList_request_not_correct_context(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Person_getHateoasComputerList(REQUEST=fake_request) result = self.portal.Person_getHateoasComputerList(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 403) self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"') 'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getHateoasComputerList_result(self): def test_getHateoasComputerList_result(self):
person_user = self._makePerson() person_user = self._makePerson()
computer = self._makeComputer() computer = self._makeComputer()
computer.edit(source_administration_value=person_user) computer.edit(source_administration_value=person_user)
self.tic() self.tic()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
self.changeSkin('Hal')
result = person_user.Person_getHateoasComputerList(REQUEST=fake_request) result = person_user.Person_getHateoasComputerList(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.collection',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/foo", "href": "http://example.org/foo"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
}, },
"item": [{ "index": {
"href": "%s/Computer_getHateoas" % \ "href": "urn:jio:get:%s/ERP5Document_getHateoas" % \
computer.absolute_url(), person_user.getRelativeUrl(),
"type": "application/vnd.slapos.org.hal+json; " \ "title": "Person"
"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"
}, },
"http://slapos.org/reg/software": { "content": [{
"href": "%s/Computer_getHateoasSoftwareInstallationList" % \ "href": "%s/ERP5Document_getHateoas" % \
computer.absolute_url(), computer.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \ "title": computer.getTitle()
"class=slapos.org.collection" }],
},
}, },
}))) }, indent=2)))
class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin): class TestSlapOSComputer_getHateoasSoftwareInstallationList(TestSlapOSHypermediaMixin):
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
@changeSkin('Hal')
def test_getSoftwareInstallationList_REQUEST_mandatory(self): def test_getSoftwareInstallationList_REQUEST_mandatory(self):
self.assertRaises( self.assertRaises(
Unauthorized, Unauthorized,
self.portal.Computer_getHateoasSoftwareInstallationList self.portal.Computer_getHateoasSoftwareInstallationList
) )
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getSoftwareInstallationList_wrong_ACCEPT(self): def test_getSoftwareInstallationList_wrong_ACCEPT(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Computer_getHateoasSoftwareInstallationList( result = self.portal.Computer_getHateoasSoftwareInstallationList(
...@@ -1119,9 +942,9 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin): ...@@ -1119,9 +942,9 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 406) self.assertEquals(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getSoftwareInstallationList_bad_method(self): def test_getSoftwareInstallationList_bad_method(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.Computer_getHateoasSoftwareInstallationList( result = self.portal.Computer_getHateoasSoftwareInstallationList(
...@@ -1129,9 +952,9 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin): ...@@ -1129,9 +952,9 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getSoftwareInstallationList_request_not_correct_context(self): def test_getSoftwareInstallationList_request_not_correct_context(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.Computer_getHateoasSoftwareInstallationList( result = self.portal.Computer_getHateoasSoftwareInstallationList(
...@@ -1139,110 +962,100 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin): ...@@ -1139,110 +962,100 @@ class TestSlapOSComputer_getHateoasSoftwareInstallationList(testSlapOSMixin):
self.assertEquals(fake_request.RESPONSE.status, 403) self.assertEquals(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"') 'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.collection"') @changeSkin('Hal')
def test_getSoftwareInstallationList_result(self): def test_getSoftwareInstallationList_result(self):
computer = self._makeComputer() computer = self._makeComputer()
software_installation = self._makeSoftwareInstallation() software_installation = self._makeSoftwareInstallation()
software_installation.edit(aggregate_value=computer) software_installation.edit(aggregate_value=computer, url_string='foo')
self.tic() self.tic()
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = computer.Computer_getHateoasSoftwareInstallationList( result = computer.Computer_getHateoasSoftwareInstallationList(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.collection',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/foo", "href": "http://example.org/foo"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.collection"
}, },
"item": [{ "content": [{
"href": "%s/SoftwareInstallation_getHateoas" % \ "href": "%s/ERP5Document_getHateoas" % \
software_installation.absolute_url(), software_installation.absolute_url(),
"type": "application/vnd.slapos.org.hal+json; " \ "title": "foo"
"class=slapos.org.software_installation"
}], }],
"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): @simulate('Base_getRequestHeader', '*args, **kwargs',
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',
'return "application/vnd+bar"') 'return "application/vnd+bar"')
@changeSkin('Hal')
def test_getHateoas_wrong_ACCEPT(self): def test_getHateoas_wrong_ACCEPT(self):
fake_request = do_fake_request("GET") 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(fake_request.RESPONSE.status, 406)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.software_installation"') @changeSkin('Hal')
def test_getHateoas_bad_method(self): def test_getHateoas_bad_method(self):
fake_request = do_fake_request("POST") fake_request = do_fake_request("POST")
result = self.portal.SoftwareInstallation_getHateoas( result = self.portal.SoftwareInstallation_getHateoasInformation(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 405) self.assertEquals(fake_request.RESPONSE.status, 405)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.software_installation"') @changeSkin('Hal')
def test_getHateoas_request_not_correct_context(self): def test_getHateoas_request_not_correct_context(self):
fake_request = do_fake_request("GET") 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(fake_request.RESPONSE.status, 403)
self.assertEquals(result, "") self.assertEquals(result, "")
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/foo"') 'return "http://example.org/foo"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/vnd.slapos.org.hal+json; ' \ 'return "application/hal+json"')
'class=slapos.org.software_installation"') @changeSkin('Hal')
def test_getHateoas_result(self): def test_getHateoas_result(self):
software_installation = self._makeSoftwareInstallation() software_installation = self._makeSoftwareInstallation()
software_installation.edit(url_string="http://foo.com/software.cfg") software_installation.edit(url_string="http://foo.com/software.cfg")
self.portal.portal_workflow._jumpToStateFor(software_installation, self.portal.portal_workflow._jumpToStateFor(software_installation,
'start_requested') 'start_requested')
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = software_installation.SoftwareInstallation_getHateoas( result = software_installation.SoftwareInstallation_getHateoasInformation(
REQUEST=fake_request) REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), 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({ self.assertEquals(json.loads(result), json.loads(json.dumps({
'_class': 'slapos.org.software_installation',
'title': software_installation.getTitle(), 'title': software_installation.getTitle(),
'status': 'started', 'status': 'started',
'_links': { '_links': {
"self": { "self": {
"href": "http://example.org/foo", "href": "http://example.org/foo"
"type": "application/vnd.slapos.org.hal+json; " \
"class=slapos.org.software_installation"
}, },
"software_release": { "software_release": {
"href": "http://foo.com/software.cfg", "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_cloud
slapos_slap_tool slapos_slap_tool
\ No newline at end of file
4 5
\ No newline at end of file \ 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