Commit 281f5093 authored by Romain Courteaud's avatar Romain Courteaud 🐙

slapos_json_rpc_api: one more test

parent 0bf35983
...@@ -23,9 +23,11 @@ if portal_type == "Software Instance": ...@@ -23,9 +23,11 @@ if portal_type == "Software Instance":
search_kw = { search_kw = {
"portal_type": "Software Instance", "portal_type": "Software Instance",
"validation_state": "validated", "validation_state": "validated",
"jio_api_revision.web_section": web_section, #"jio_api_revision.web_section": web_section,
"select_list": ("title", "reference", "portal_type", "slap_state", "aggregate_reference", "url_string", "jio_api_revision.revision"), "select_list": ("title", "reference", "portal_type", "slap_state", "aggregate_reference", "url_string"),#, "jio_api_revision.revision"),
"sort_on": ("jio_api_revision.revision", "ASC"), #"sort_on": ("jio_api_revision.revision", "ASC"),
# XXX Sorting is slow
"sort_on": [("reference", "ASC")],
"limit": limit "limit": limit
} }
...@@ -48,7 +50,7 @@ if portal_type == "Software Instance": ...@@ -48,7 +50,7 @@ if portal_type == "Software Instance":
"state": slap_state_dict.get(x.slap_state, ""), "state": slap_state_dict.get(x.slap_state, ""),
"compute_partition_id": x.aggregate_reference, "compute_partition_id": x.aggregate_reference,
"software_release_uri": x.url_string, "software_release_uri": x.url_string,
"api_revision": x.revision, #"api_revision": x.revision,
"get_parameters": { "get_parameters": {
"portal_type": x.portal_type, "portal_type": x.portal_type,
"reference": x.reference, "reference": x.reference,
...@@ -90,7 +92,7 @@ elif portal_type == "Shared Instance": ...@@ -90,7 +92,7 @@ elif portal_type == "Shared Instance":
"portal_type": "Software Instance", "portal_type": "Software Instance",
"state": slap_state_dict.get(x.slap_state, ""), "state": slap_state_dict.get(x.slap_state, ""),
"compute_partition_id": x.aggregate_reference, "compute_partition_id": x.aggregate_reference,
"api_revision": x.revision, #"api_revision": x.revision,
"get_parameters": { "get_parameters": {
"portal_type": "Software Instance", "portal_type": "Software Instance",
"reference": x.reference, "reference": x.reference,
...@@ -105,8 +107,8 @@ else: ...@@ -105,8 +107,8 @@ else:
error_message="You Reached code that was not recheable", error_message="You Reached code that was not recheable",
) )
if result_list: #if result_list:
data_dict["from_api_revision"] = result_list[-1]["api_revision"] # data_dict["from_api_revision"] = result_list[-1]["api_revision"]
return { return {
# "$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema", # "$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema",
......
...@@ -170,37 +170,17 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJsonRpcMixin): ...@@ -170,37 +170,17 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJsonRpcMixin):
instance_1 = self.compute_node.partition1.getAggregateRelatedValue(portal_type='Software Instance') instance_1 = self.compute_node.partition1.getAggregateRelatedValue(portal_type='Software Instance')
instance_2 = self.compute_node.partition2.getAggregateRelatedValue(portal_type='Software Instance') instance_2 = self.compute_node.partition2.getAggregateRelatedValue(portal_type='Software Instance')
instance_3 = self.compute_node.partition3.getAggregateRelatedValue(portal_type='Software Instance') instance_3 = self.compute_node.partition3.getAggregateRelatedValue(portal_type='Software Instance')
instance_4 = self.compute_node.partition4.getAggregateRelatedValue(portal_type='Software Instance')
response = self.callJsonRpcWebService('slapos.allDocs.slapos_jio_api_search_instance', {
"compute_node_id": self.compute_node_id,
"portal_type": "Software Instance",
}, self.compute_node_user_id)
self.assertEqual('application/json', response.headers.get('content-type'))
self.assertEqual(
byteify(json.loads(response.getBody())),
{
'current_page_full': False,
'next_page_request': {'compute_node_id': self.compute_node.getReference(),
'portal_type': 'Software Instance'},
'result_list': []
})
self.assertEqual(response.getStatus(), 200)
instance_list_response = json.loads(response.getBody())
# self.assertTrue(instance_list_response["$schema"].endswith("jIOWebSection_searchInstanceFromJSON/getOutputJSONSchema"))
result_list = instance_list_response["result_list"]
self.assertEqual(3, len(result_list))
# This is the expected instance list, it is sorted by api_revision # This is the expected instance list, it is sorted by api_revision
instance_list = [instance_1, instance_2, instance_3] instance_list = [instance_1, instance_2, instance_3, instance_4]
instance_list.sort(key=lambda x: x.getJIOAPIRevision(self.connector.getRelativeUrl())) # instance_list.sort(key=lambda x: x.getJIOAPIRevision(self.connector.getRelativeUrl()))
# Check result_list match instance_list= # Check result_list match instance_list=
expected_instance_list = [] expected_instance_list = []
for instance in instance_list: for instance in instance_list:
expected_instance_list.append({ expected_instance_list.append({
"api_revision": instance.getJIOAPIRevision(self.connector.getRelativeUrl()), # "api_revision": instance.getJIOAPIRevision(self.connector.getRelativeUrl()),
"compute_partition_id": instance.getAggregateReference(), "compute_partition_id": instance.getAggregateReference(),
"get_parameters": { "get_parameters": {
"portal_type": "Software Instance", "portal_type": "Software Instance",
...@@ -212,23 +192,41 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJsonRpcMixin): ...@@ -212,23 +192,41 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJsonRpcMixin):
"state": self.getAPIStateFromSlapState(instance.getSlapState()), "state": self.getAPIStateFromSlapState(instance.getSlapState()),
"title": instance.getTitle(), "title": instance.getTitle(),
}) })
self.assertEqual(expected_instance_list, instance_list_response["result_list"])
response = self.callJsonRpcWebService('slapos.allDocs.slapos_jio_api_search_instance', {
"compute_node_id": self.compute_node_id,
"portal_type": "Software Instance",
}, self.compute_node_user_id)
self.assertEqual('application/json', response.headers.get('content-type'))
instance_list_response = byteify(json.loads(response.getBody()))
# self.assertTrue(instance_list_response["$schema"].endswith("jIOWebSection_searchInstanceFromJSON/getOutputJSONSchema"))
self.assertEqual(
instance_list_response,
{
'current_page_full': False,
'next_page_request': {'compute_node_id': self.compute_node.getReference(),
'portal_type': 'Software Instance'},
'result_list': expected_instance_list
})
self.assertEqual(response.getStatus(), 200)
for i in range(len(expected_instance_list)): for i in range(len(expected_instance_list)):
instance_resut_dict = expected_instance_list[i] instance_resut_dict = expected_instance_list[i]
instance = instance_list[i] instance = instance_list[i]
# Get instance as "user" # Get instance as "user"
self.login(self.compute_node_user_id)
response = self.callJsonRpcWebService("slapos.get.slapos_jio_api_get_software_instance", instance_resut_dict["get_parameters"])
instance_dict = json.loads(response.getBody())
if 200 != response.getStatus():
raise ValueError("Unexpected Result %s" % instance_dict)
self.assertEqual('application/json',
response.headers.get('content-type'))
# Check Data is correct # Check Data is correct
partition = instance.getAggregateValue(portal_type="Compute Partition") partition = instance.getAggregateValue(portal_type="Compute Partition")
self.assertEqual({ response = self.callJsonRpcWebService(
"$schema": instance.getJSONSchemaUrl(), 'slapos.get.slapos_jio_api_get_software_instance',
instance_resut_dict["get_parameters"],
self.compute_node_user_id
)
self.assertEqual('application/json', response.headers.get('content-type'))
self.assertEqual(
byteify(json.loads(response.getBody())),
{
#"$schema": instance.getJSONSchemaUrl(),
"title": instance.getTitle(), "title": instance.getTitle(),
"reference": instance.getReference(), "reference": instance.getReference(),
"software_release_uri": instance.getUrlString(), "software_release_uri": instance.getUrlString(),
...@@ -251,9 +249,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJsonRpcMixin): ...@@ -251,9 +249,10 @@ class TestSlapOSSlapToolComputeNodeAccess(TestSlapOSJsonRpcMixin):
"compute_partition_id": partition.getReference(), "compute_partition_id": partition.getReference(),
"processing_timestamp": instance.getSlapTimestamp(), "processing_timestamp": instance.getSlapTimestamp(),
"access_status_message": instance.getTextAccessStatus(), "access_status_message": instance.getTextAccessStatus(),
"api_revision": instance.getJIOAPIRevision(self.connector.getRelativeUrl()), #"api_revision": instance.getJIOAPIRevision(self.connector.getRelativeUrl()),
"portal_type": instance.getPortalType(), "portal_type": instance.getPortalType(),
}, instance_dict) })
self.assertEqual(response.getStatus(), 200)
def test_ComputeNodeAccess_01_bis_getFullComputerInformationSoftwareList(self): def test_ComputeNodeAccess_01_bis_getFullComputerInformationSoftwareList(self):
self._makeComplexComputeNode(self.project, with_slave=True) self._makeComplexComputeNode(self.project, with_slave=True)
......
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