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

recipe: Fix Update tests for request and slapconfiguration

parent e7edf99a
......@@ -208,7 +208,7 @@ class RecipejIOTestMixin:
def test_no_return_in_options_logs(self):
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
with httmock.HTTMock(api_handler.request_handler):
with LogCapture() as log:
......@@ -229,7 +229,7 @@ class RecipejIOTestMixin:
if self.called_partition_parameter_kw:
expected_request_body["parameters"] = json.dumps(self.called_partition_parameter_kw)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps(expected_request_body))
api_handler.request_payload_list[0], expected_request_body)
self.assertEqual(api_handler.sequence_list, ["/api/post/"])
self.assertTrue(os.path.exists(self.transaction_file_path))
with open(self.transaction_file_path, 'r') as f:
......@@ -238,7 +238,7 @@ class RecipejIOTestMixin:
def test_return_in_options_logs(self):
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
with httmock.HTTMock(api_handler.request_handler):
......@@ -257,7 +257,7 @@ class RecipejIOTestMixin:
if self.called_partition_parameter_kw:
expected_request_body["parameters"] = json.dumps(self.called_partition_parameter_kw)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps(expected_request_body))
api_handler.request_payload_list[0], expected_request_body)
self.assertEqual(self.options["connection-anything"], "done")
self.assertEqual(api_handler.sequence_list, ["/api/post/"])
self.assertTrue(os.path.exists(self.transaction_file_path))
......@@ -269,7 +269,7 @@ class RecipejIOTestMixin:
def test_return_not_ready(self):
self.instance_data["connection_parameters"] = self.connection_parameter_dict_empty
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
with httmock.HTTMock(api_handler.request_handler):
......@@ -291,7 +291,7 @@ class RecipejIOTestMixin:
if self.called_partition_parameter_kw:
expected_request_body["parameters"] = json.dumps(self.called_partition_parameter_kw)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps(expected_request_body))
api_handler.request_payload_list[0], expected_request_body)
self.assertEqual(self.options["connection-anything"], "")
self.assertEqual(api_handler.sequence_list, ["/api/post/"])
self.assertTrue(os.path.exists(self.transaction_file_path))
......@@ -301,7 +301,7 @@ class RecipejIOTestMixin:
def test_return_ready(self):
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
with httmock.HTTMock(api_handler.request_handler):
......@@ -320,7 +320,7 @@ class RecipejIOTestMixin:
if self.called_partition_parameter_kw:
expected_request_body["parameters"] = json.dumps(self.called_partition_parameter_kw)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps(expected_request_body))
api_handler.request_payload_list[0], expected_request_body)
self.assertEqual(self.options["connection-anything"], "done")
self.assertIsInstance(self.options['connection-anything'], str)
self.assertEqual(api_handler.sequence_list, ["/api/post/"])
......@@ -332,7 +332,7 @@ class RecipejIOTestMixin:
def test_two_requests_return_ready(self):
# Request first instance
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
with httmock.HTTMock(api_handler.request_handler):
......@@ -342,7 +342,7 @@ class RecipejIOTestMixin:
self.options["name"] = self.instance_data["title"] = 'MyInstance2'
self.instance_data["reference"] = "SOFTINST-13"
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
with httmock.HTTMock(api_handler.request_handler):
......@@ -355,7 +355,7 @@ class RecipejIOTestMixin:
def test_requester_stopped_state_propagated(self):
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
self.buildout['slap-connection']['requested'] = 'stopped'
......@@ -375,7 +375,7 @@ class RecipejIOTestMixin:
if self.called_partition_parameter_kw:
expected_request_body["parameters"] = json.dumps(self.called_partition_parameter_kw)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps(expected_request_body))
api_handler.request_payload_list[0], expected_request_body)
self.assertEqual(self.options["connection-anything"], "done")
self.assertIsInstance(self.options['connection-anything'], str)
self.assertEqual(api_handler.sequence_list, ["/api/post/"])
......@@ -386,7 +386,7 @@ class RecipejIOTestMixin:
def test_requester_destroyed_state_not_propagated(self):
api_handler = APIRequestHandler([
("/api/get", json.dumps(self.instance_data)),
("/api/post/", json.dumps(self.instance_data)),
])
self.options['return'] = 'anything'
self.buildout['slap-connection']['requested'] = 'destroyed'
......@@ -406,7 +406,7 @@ class RecipejIOTestMixin:
if self.called_partition_parameter_kw:
expected_request_body["parameters"] = json.dumps(self.called_partition_parameter_kw)
self.assertEqual(
api_handler.request_payload_list[0], json.dumps(expected_request_body))
api_handler.request_payload_list[0], expected_request_body)
self.assertEqual(self.options["connection-anything"], "done")
self.assertIsInstance(self.options['connection-anything'], str)
self.assertEqual(api_handler.sequence_list, ["/api/post/"])
......
# coding: utf-8
import mock
import json
import httmock
import os
import unittest
import tempfile
from collections import defaultdict
from slapos.recipe import slapconfiguration
from slapos import format as slapformat
from slapos.grid.SlapObject import SOFTWARE_INSTANCE_JSON_FILENAME
......@@ -100,14 +98,14 @@ class SlapConfigurationTestMixin(object):
}
if self.use_api:
api_handler = APIRequestHandler([
("/api/get", json.dumps(instance_data)),
("/api/allDocs", json.dumps({"result_list": []}))
("/api/get/", json.dumps(instance_data)),
("/api/allDocs/", json.dumps({"result_list": []}))
])
else:
with open(self.instance_json_location, 'w') as f:
json.dump(instance_data, f, indent=2)
api_handler = APIRequestHandler([
("/api/allDocs", json.dumps({"result_list": []}))
("/api/allDocs/", json.dumps({"result_list": []}))
])
with httmock.HTTMock(api_handler.request_handler):
slapconfiguration.Recipe(self.buildout, "slapconfiguration", options)
......@@ -190,22 +188,22 @@ class SlapConfigurationTestMixin(object):
}
if self.use_api:
api_handler = APIRequestHandler([
("/api/get", json.dumps(instance_data)),
("/api/allDocs", json.dumps({"result_list": [{
("/api/get/", json.dumps(instance_data)),
("/api/allDocs/", json.dumps({"result_list": [{
"portal_type": "Shared Instance",
"reference": shared_instance_data["reference"]
}]})),
("/api/get", json.dumps(shared_instance_data)),
("/api/get/", json.dumps(shared_instance_data)),
])
else:
with open(self.instance_json_location, 'w') as f:
json.dump(instance_data, f, indent=2)
api_handler = APIRequestHandler([
("/api/allDocs", json.dumps({"result_list": [{
("/api/allDocs/", json.dumps({"result_list": [{
"portal_type": "Shared Instance",
"reference": shared_instance_data["reference"]
}]})),
("/api/get", json.dumps(shared_instance_data)),
("/api/get/", json.dumps(shared_instance_data)),
])
with httmock.HTTMock(api_handler.request_handler):
slapconfiguration.Recipe(self.buildout, "slapconfiguration", options)
......@@ -246,7 +244,7 @@ class SlapConfigurationTestMixin(object):
self.assertEqual(dumped_data["slave_instance_list"], options["shared-instance-list"])
class SlapConfigurationWithLocalInstanceFile(SlapConfigurationTestMixin, unittest.TestCase):
use_api = True
use_api = False
class SlapConfigurationWithApi(SlapConfigurationTestMixin, unittest.TestCase):
use_api = False
use_api = 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