Commit 9e05b13d authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

slapos_jio_api_style: tests Raise Error with JSON content when http response...

slapos_jio_api_style: tests Raise Error with JSON content when http response status is not corresponding
parent 5835ef41
...@@ -155,7 +155,8 @@ class TestSlapOSJIOAPIMixin(SlapOSTestCaseMixin): ...@@ -155,7 +155,8 @@ class TestSlapOSJIOAPIMixin(SlapOSTestCaseMixin):
start_date = DateTime().HTML4() start_date = DateTime().HTML4()
response_dict = self.putToApi(data_dict) response_dict = self.putToApi(data_dict)
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(response_dict["compute_node_id"], data_dict["compute_node_id"]) self.assertEqual(response_dict["compute_node_id"], data_dict["compute_node_id"])
...@@ -169,7 +170,8 @@ class TestSlapOSJIOAPIMixin(SlapOSTestCaseMixin): ...@@ -169,7 +170,8 @@ class TestSlapOSJIOAPIMixin(SlapOSTestCaseMixin):
start_date = DateTime().HTML4() start_date = DateTime().HTML4()
response_dict = self.putToApi(data_dict) response_dict = self.putToApi(data_dict)
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertTrue(response_dict.pop("$schema").endswith("SoftwareInstance_updateFromJSON/getOutputJSONSchema")) self.assertTrue(response_dict.pop("$schema").endswith("SoftwareInstance_updateFromJSON/getOutputJSONSchema"))
...@@ -200,7 +202,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin): ...@@ -200,7 +202,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
"portal_type": "Software Instance", "portal_type": "Software Instance",
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_list_response)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
...@@ -237,7 +240,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin): ...@@ -237,7 +240,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
self.login(self.compute_node_user_id) self.login(self.compute_node_user_id)
instance_dict = self.getToApi(instance_resut_dict["get_parameters"]) instance_dict = self.getToApi(instance_resut_dict["get_parameters"])
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
# Check Data is correct # Check Data is correct
...@@ -315,7 +319,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin): ...@@ -315,7 +319,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
"compute_node_id": self.compute_node_id, "compute_node_id": self.compute_node_id,
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % software_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
...@@ -347,7 +352,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin): ...@@ -347,7 +352,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
} }
) )
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(400, response.getStatus()) if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual('404', response_dict["status"]) self.assertEqual('404', response_dict["status"])
...@@ -379,6 +385,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin): ...@@ -379,6 +385,8 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJIOAPIMixin):
} }
) )
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual(400, response.getStatus()) self.assertEqual(400, response.getStatus())
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
...@@ -527,7 +535,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -527,7 +535,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"reference": self.start_requested_software_instance.getReference(), "reference": self.start_requested_software_instance.getReference(),
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % certificate_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertTrue( self.assertTrue(
...@@ -550,7 +559,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -550,7 +559,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"portal_type": "Software Instance", "portal_type": "Software Instance",
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_list_response)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
...@@ -580,7 +590,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -580,7 +590,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
self.login(instance.getUserId()) self.login(instance.getUserId())
instance_dict = self.getToApi(instance_resut_dict["get_parameters"]) instance_dict = self.getToApi(instance_resut_dict["get_parameters"])
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
# Check Data is correct # Check Data is correct
...@@ -629,7 +640,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -629,7 +640,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"portal_type": "Shared Instance", "portal_type": "Shared Instance",
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % shared_instance_list_response)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
...@@ -656,12 +668,14 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -656,12 +668,14 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
instance_dict = self.getToApi(shared_instance_list_response["result_list"][0]["get_parameters"]) instance_dict = self.getToApi(shared_instance_list_response["result_list"][0]["get_parameters"])
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
# Check Data is correct # Check Data is correct
self.login() self.login()
partition = instance.getAggregateValue(portal_type="Compute Partition") partition = instance.getAggregateValue(portal_type="Compute Partition")
self.maxDiff = None
self.assertEqual({ self.assertEqual({
"$schema": instance.getJSONSchemaUrl(), "$schema": instance.getJSONSchemaUrl(),
"title": shared_instance.getTitle(), "title": shared_instance.getTitle(),
...@@ -761,7 +775,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -761,7 +775,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"reference": instance.getReference(), "reference": instance.getReference(),
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual( self.assertEqual(
...@@ -786,7 +801,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -786,7 +801,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"reference": instance.getReference(), "reference": instance.getReference(),
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual( self.assertEqual(
...@@ -845,7 +861,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -845,7 +861,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"reference": instance.getReference(), "reference": instance.getReference(),
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual( self.assertEqual(
...@@ -920,7 +937,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -920,7 +937,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"compute_partition_id": partition_id, "compute_partition_id": partition_id,
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(400, response.getStatus()) if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
...@@ -964,7 +982,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -964,7 +982,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"compute_partition_id": partition_id, "compute_partition_id": partition_id,
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(400, response.getStatus()) if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
...@@ -1009,7 +1028,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin): ...@@ -1009,7 +1028,8 @@ class TestSlapOSSlapToolInstanceAccess(TestSlapOSJIOAPIMixin):
"compute_partition_id": partition_id, "compute_partition_id": partition_id,
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(400, response.getStatus()) if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
...@@ -1230,7 +1250,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin): ...@@ -1230,7 +1250,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin):
"reference": instance.getReference() "reference": instance.getReference()
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
# Check Data is correct # Check Data is correct
...@@ -1299,7 +1320,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin): ...@@ -1299,7 +1320,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin):
"reference": instance.getReference(), "reference": instance.getReference(),
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(200, response.getStatus()) if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual( self.assertEqual(
...@@ -1355,7 +1377,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin): ...@@ -1355,7 +1377,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin):
"shared": True, "shared": True,
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(400, response.getStatus()) if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
...@@ -1393,7 +1416,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin): ...@@ -1393,7 +1416,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin):
"title": "req_reference", "title": "req_reference",
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(400, response.getStatus()) if 400 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_instance_request, { self.assertEqual(self.called_instance_request, {
...@@ -1434,7 +1458,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin): ...@@ -1434,7 +1458,8 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin):
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(201, response.getStatus()) if 201 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
# Check Data is correct # Check Data is correct
...@@ -1478,13 +1503,14 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin): ...@@ -1478,13 +1503,14 @@ class TestSlapOSSlapToolPersonAccess(TestSlapOSJIOAPIMixin):
requestSoftwareRelease = self.compute_node.__class__.requestSoftwareRelease requestSoftwareRelease = self.compute_node.__class__.requestSoftwareRelease
self.compute_node.__class__.requestSoftwareRelease = calledSoftwareSupply self.compute_node.__class__.requestSoftwareRelease = calledSoftwareSupply
software_url = 'live_test_url_%s' % self.generateNewId() software_url = 'live_test_url_%s' % self.generateNewId()
self.postToApi({ response_dict = self.postToApi({
"portal_type": "Software Installation", "portal_type": "Software Installation",
"compute_node_id": self.compute_node.getReference(), "compute_node_id": self.compute_node.getReference(),
"software_release_uri": urllib.quote(software_url) "software_release_uri": urllib.quote(software_url)
}) })
response = self.portal.REQUEST.RESPONSE response = self.portal.REQUEST.RESPONSE
self.assertEqual(201, response.getStatus()) if 201 != response.getStatus():
raise ValueError("Unexpected Result %s" % response_dict)
self.assertEqual('application/json', self.assertEqual('application/json',
response.headers.get('content-type')) response.headers.get('content-type'))
self.assertEqual(self.called_software_supply, { self.assertEqual(self.called_software_supply, {
......
...@@ -6,12 +6,6 @@ ...@@ -6,12 +6,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testSlapOSJIOAPI</string> </value> <value> <string>testSlapOSJIOAPI</string> </value>
...@@ -61,28 +55,13 @@ ...@@ -61,28 +55,13 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -95,7 +74,7 @@ ...@@ -95,7 +74,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -104,7 +83,7 @@ ...@@ -104,7 +83,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
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