Commit 2967180b authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

request: Add first test

parent 6d772baa
...@@ -166,6 +166,8 @@ class Recipe(object): ...@@ -166,6 +166,8 @@ class Recipe(object):
"software_type": software_type, "software_type": software_type,
"software_release_uri": software_url, "software_release_uri": software_url,
"portal_type": "Software Instance", "portal_type": "Software Instance",
"compute_node_id": options['computer-id'],
"compute_partition_id": options['partition-id'],
} }
if partition_parameter_kw: if partition_parameter_kw:
request_dict["parameters"] = json.dumps(partition_parameter_kw) request_dict["parameters"] = json.dumps(partition_parameter_kw)
...@@ -206,8 +208,8 @@ class Recipe(object): ...@@ -206,8 +208,8 @@ class Recipe(object):
options['instance-guid'] = partition_dict["reference"] options['instance-guid'] = partition_dict["reference"]
# XXX: deprecated, to be removed # XXX: deprecated, to be removed
options['instance_guid'] = options['instance-guid'] options['instance_guid'] = options['instance-guid']
options['instance-state'] = options['state'] options['instance-state'] = partition_dict['state']
options['instance-status'] = options.get('access_status_message') options['instance-status'] = partition_dict.get('access_status_message')
else: else:
# Try to do the request and fetch parameter dict... # Try to do the request and fetch parameter dict...
...@@ -275,7 +277,7 @@ class Recipe(object): ...@@ -275,7 +277,7 @@ class Recipe(object):
def _getFilteredParameterDict(self, partition_dict, return_parameter_list): def _getFilteredParameterDict(self, partition_dict, return_parameter_list):
result = {} result = {}
parameters = json_loads_byteified(partition.get("parameters", "{}")) parameters = json_loads_byteified(partition_dict.get("parameters", "{}"))
for key in return_parameter_list: for key in return_parameter_list:
if key in parameters: if key in parameters:
result[key] = parameters["key"] result[key] = parameters["key"]
......
import httmock
import json
import mock import mock
import unittest import unittest
from collections import defaultdict from collections import defaultdict
...@@ -153,4 +155,80 @@ class RequestOptionalJSONEncodedTest(RecipeTestMixin, unittest.TestCase): ...@@ -153,4 +155,80 @@ class RequestOptionalJSONEncodedTest(RecipeTestMixin, unittest.TestCase):
called_partition_parameter_kw = {'_': '{}'} called_partition_parameter_kw = {'_': '{}'}
class RecipejIOTestMixin: class RecipejIOTestMixin:
pass
\ No newline at end of file def setUp(self):
self.buildout = {
"buildout": {
},
"slap-connection": {
}
}
self.parameter_dict = {"foo": "bar", "hello": "bye"}
self.instance_data = {
"reference": "SOFTINST-12",
"state": "started",
"software_type": "Couscous",
"compute_partition_id": "slappartx12",
"compute_node_id": "COMP-321",
"software_release_uri": "foo.cfg",
"processing_timestamp": 1223231231,
"title": "MyInstance",
"root_instance_title": "MyInstanceRoot",
"ip_list": [
[
"slaptap9",
"fe80::1ff:fe23:4567:890a"
],
[
"slaptap9",
"10.0.246.114"
]
],
"parameters": json.dumps(self.parameter_dict),
"connection_parameters": self.connection_parameter_dict,
}
self.options = {
"server-url": "http://127.0.0.1:80",
"name": self.instance_data["title"],
"software-instance-reference": "SOFTINST-12",
"computer-id": self.instance_data["compute_node_id"],
"partition-id": self.instance_data["compute_partition_id"],
"software-url": self.instance_data["software_release_uri"],
}
def test_no_return_in_options_logs(self):
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
])
with httmock.HTTMock(api_handler.request_handler):
with LogCapture() as log:
#import pdb; pdb.set_trace()
self.recipe(self.buildout, "request", self.options)
log.check(
('request', 'DEBUG',
'No parameter to return to main instance.Be careful about that...'),
)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps({
"software_release_uri": "foo.cfg",
"title": "MyInstance",
"portal_type": "Software Instance",
"compute_partition_id": "slappartx12",
"state": "started",
"compute_node_id": "COMP-321",
"software_type": "RootSoftwareInstance"
}))
def test_return_in_options_logs(self):
pass
def test_return_not_ready(self):
pass
def test_return_ready(self):
pass
class RequestjIOTest(RecipejIOTestMixin, unittest.TestCase):
recipe = request.Recipe
connection_parameter_dict_empty = {}
connection_parameter_dict = {"foo": "bar"}
...@@ -15,8 +15,10 @@ class APIRequestHandler(object): ...@@ -15,8 +15,10 @@ class APIRequestHandler(object):
def __init__(self, response_list): def __init__(self, response_list):
self.response_list = response_list self.response_list = response_list
self.request_payload_list = [] self.request_payload_list = []
self.sequence_list = []
def request_handler(self, url, req): def request_handler(self, url, req):
self.sequence_list.append(url.path)
if url.path == "/getHateoasUrl": if url.path == "/getHateoasUrl":
return "" return ""
elif url.path == "/getJIOAPIUrl": elif url.path == "/getJIOAPIUrl":
...@@ -25,6 +27,7 @@ class APIRequestHandler(object): ...@@ -25,6 +27,7 @@ class APIRequestHandler(object):
if not self.response_list and self.response_list[0][0] != url.path: if not self.response_list and self.response_list[0][0] != url.path:
raise ValueError("Unexcpected call: %s %s" % (url.path, req.body)) raise ValueError("Unexcpected call: %s %s" % (url.path, req.body))
self.request_payload_list.append(req.body)
return self.response_list.pop(0)[1] return self.response_list.pop(0)[1]
......
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