Python oslo_serialization.jsonutils.dump_as_bytes() Examples
The following are 30
code examples of oslo_serialization.jsonutils.dump_as_bytes().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
oslo_serialization.jsonutils
, or try the search function
.
Example #1
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_non_existing_instantiation_level( self, mock_instantiate, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_vnf_instance_get_by_id): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "simple", "instantiationLevelId": "non-existing"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.BAD_REQUEST, resp.status_code) self.assertEqual("No instantiation level with id 'non-existing'.", resp.json['badRequest']['message'])
Example #2
Source File: test_notifications.py From masakari with Apache License 2.0 | 6 votes |
def test_create_success_with_201_response_code( self, mock_client, mock_create): body = { "notification": { "hostname": "fake_host", "payload": { "instance_uuid": uuidsentinel.instance_uuid, "vir_domain_event": "STOPPED_FAILED", "event": "LIFECYCLE" }, "type": "VM", "generated_time": NOW } } fake_req = self.req fake_req.headers['Content-Type'] = 'application/json' fake_req.method = 'POST' fake_req.body = jsonutils.dump_as_bytes(body) resp = fake_req.get_response(self.app) self.assertEqual(http.ACCEPTED, resp.status_code)
Example #3
Source File: test_driver_listener.py From octavia with Apache License 2.0 | 6 votes |
def test_GetRequestHandler_handle(self, mock_recv, mock_process_get): TEST_OBJECT = {"test": "msg"} mock_recv.return_value = 'bogus' mock_process_get.return_value = TEST_OBJECT mock_request = mock.MagicMock() mock_send = mock.MagicMock() mock_sendall = mock.MagicMock() mock_request.send = mock_send mock_request.sendall = mock_sendall GetRequestHandler = driver_listener.GetRequestHandler( mock_request, 'bogus', 'bogus') GetRequestHandler.handle() mock_recv.assert_called_with(mock_request) mock_process_get.assert_called_with('bogus') mock_send.assert_called_with(b'15\n') mock_sendall.assert_called_with(jsonutils.dump_as_bytes(TEST_OBJECT))
Example #4
Source File: http_error.py From magnum with Apache License 2.0 | 6 votes |
def __call__(self, environ, start_response): for err_str in self.app_iter: err = {} try: err = jsonutils.loads(err_str.decode('utf-8')) except ValueError: pass links = {'rel': 'help', 'href': 'http://docs.openstack.org' '/api-guide/compute/microversions.html'} err['max_version'] = self.max_version err['min_version'] = self.min_version err['code'] = "magnum.microversion-unsupported" err['links'] = [links] err['title'] = "Requested microversion is unsupported" self.app_iter = [jsonutils.dump_as_bytes(err)] self.headers['Content-Length'] = str(len(self.app_iter[0])) return super(HTTPNotAcceptableAPIVersion, self).__call__( environ, start_response)
Example #5
Source File: test_alarm_receiver.py From tacker with Apache License 2.0 | 6 votes |
def test_process_request_with_body(self, mock_create_token): req = Request.blank(self.ordered_url) req.method = 'POST' old_body = {'fake_key': 'fake_value'} req.body = jsonutils.dump_as_bytes(old_body) self.alarmrc.process_request(req) body_dict = jsonutils.loads(req.body) self.assertDictEqual(old_body, body_dict['trigger']['params']['data']) self.assertEqual(self.alarm_url['05_key'], body_dict['trigger']['params']['credential']) self.assertEqual(self.alarm_url['03_monitoring_policy_name'], body_dict['trigger']['policy_name']) self.assertEqual(self.alarm_url['04_action_name'], body_dict['trigger']['action_name'])
Example #6
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_upload_vnf_package_content(self, mock_vnf_pack_save, mock_vnf_by_id, mock_upload_vnf_package_content, mock_glance_store): updates = {'onboarding_state': 'CREATED', 'operational_state': 'DISABLED'} vnf_package_dict = fakes.fake_vnf_package(updates) vnf_package_obj = objects.VnfPackage(**vnf_package_dict) mock_vnf_by_id.return_value = vnf_package_obj mock_vnf_pack_save.return_value = vnf_package_obj mock_glance_store.return_value = 'location', 0, 'checksum',\ 'multihash', 'loc_meta' req = fake_request.HTTPRequest.blank( '/vnf_packages/%s/package_content' % constants.UUID) req.headers['Content-Type'] = 'application/zip' req.method = 'PUT' req.body = jsonutils.dump_as_bytes(mock.mock_open()) resp = req.get_response(self.app) mock_glance_store.assert_called() self.assertEqual(http_client.ACCEPTED, resp.status_code)
Example #7
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_upload_vnf_package_from_uri(self, mock_vnf_pack_save, mock_vnf_by_id, mock_upload_vnf_package_from_uri, mock_url_open): body = {"addressInformation": "http://localhost/test_data.zip"} updates = {'onboarding_state': 'CREATED', 'operational_state': 'DISABLED'} vnf_package_dict = fakes.fake_vnf_package(updates) vnf_package_obj = objects.VnfPackage(**vnf_package_dict) mock_vnf_by_id.return_value = vnf_package_obj mock_vnf_pack_save.return_value = vnf_package_obj req = fake_request.HTTPRequest.blank( '/vnf_packages/%s/package_content/upload_from_uri' % constants.UUID) req.headers['Content-Type'] = 'application/json' req.method = 'POST' req.body = jsonutils.dump_as_bytes(body) resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code)
Example #8
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_patch(self, mock_save, mock_vnf_by_id): vnf_package_updates = {'operational_state': 'DISABLED'} mock_vnf_by_id.return_value = \ fakes.return_vnfpkg_obj(vnf_package_updates=vnf_package_updates) req_body = {"operationalState": "ENABLED", "userDefinedData": {"testKey1": "val01", "testKey2": "val02", "testkey3": "val03"}} req = fake_request.HTTPRequest.blank( '/vnf_packages/%s' % constants.UUID) req.headers['Content-Type'] = 'application/json' req.method = 'PATCH' req.body = jsonutils.dump_as_bytes(req_body) resp = req.get_response(self.app) self.assertEqual(http_client.OK, resp.status_code) self.assertEqual(req_body, jsonutils.loads(resp.body))
Example #9
Source File: test_monitor.py From tacker with Apache License 2.0 | 6 votes |
def test_to_hosting_vnf(self): test_vnf_dict = { 'id': MOCK_VNF_ID, 'mgmt_ip_address': '{"vdu1": "a.b.c.d"}', 'attributes': { 'monitoring_policy': jsonutils.dump_as_bytes( MOCK_VNF['monitoring_policy']) } } action_cb = mock.MagicMock() expected_output = { 'id': MOCK_VNF_ID, 'action_cb': action_cb, 'mgmt_ip_addresses': { 'vdu1': 'a.b.c.d' }, 'vnf': test_vnf_dict, 'monitoring_policy': MOCK_VNF['monitoring_policy'] } output_dict = monitor.VNFMonitor.to_hosting_vnf(test_vnf_dict, action_cb) self.assertEqual(expected_output, output_dict)
Example #10
Source File: test_monitor.py From tacker with Apache License 2.0 | 6 votes |
def test_add_hosting_vnf(self, mock_monitor_run): test_vnf_dict = { 'id': MOCK_VNF_ID, 'mgmt_ip_address': '{"vdu1": "a.b.c.d"}', 'attributes': { 'monitoring_policy': jsonutils.dump_as_bytes( MOCK_VNF['monitoring_policy']) }, 'status': 'ACTIVE' } action_cb = mock.MagicMock() test_boot_wait = 30 test_vnfmonitor = monitor.VNFMonitor(test_boot_wait) new_dict = test_vnfmonitor.to_hosting_vnf(test_vnf_dict, action_cb) test_vnfmonitor.add_hosting_vnf(new_dict) test_vnf_id = list(test_vnfmonitor._hosting_vnfs.keys())[0] self.assertEqual(MOCK_VNF_ID, test_vnf_id) self._cos_db_plugin.create_event.assert_called_with( mock.ANY, res_id=mock.ANY, res_type=constants.RES_TYPE_VNF, res_state=mock.ANY, evt_type=constants.RES_EVT_MONITOR, tstamp=mock.ANY, details=mock.ANY)
Example #11
Source File: test_monitor.py From tacker with Apache License 2.0 | 6 votes |
def test_vdu_autoheal_action(self, mock_monitor_call, mock_monitor_run): test_hosting_vnf = MOCK_VNF_DEVICE_FOR_VDU_AUTOHEAL test_boot_wait = 30 test_device_dict = { 'status': 'ACTIVE', 'id': MOCK_VNF_ID, 'mgmt_ip_address': '{"vdu1": "a.b.c.d"}', 'attributes': { 'monitoring_policy': jsonutils.dump_as_bytes( MOCK_VNF_DEVICE_FOR_VDU_AUTOHEAL['monitoring_policy']) } } test_hosting_vnf['vnf'] = test_device_dict mock_monitor_call.return_value = 'failure' test_vnfmonitor = monitor.VNFMonitor(test_boot_wait) test_vnfmonitor._monitor_manager = self.mock_monitor_manager test_vnfmonitor.run_monitor(test_hosting_vnf) test_hosting_vnf['action_cb'].assert_called_once_with( 'vdu_autoheal', vdu_name='vdu1')
Example #12
Source File: test_monitor.py From tacker with Apache License 2.0 | 6 votes |
def test_update_hosting_vnf(self, mock_monitor_run): test_boot_wait = 30 test_vnfmonitor = monitor.VNFMonitor(test_boot_wait) vnf_dict = { 'id': MOCK_VNF_ID, 'mgmt_ip_address': '{"vdu1": "a.b.c.d"}', 'mgmt_ip_addresses': 'a.b.c.d', 'vnf': { 'id': MOCK_VNF_ID, 'mgmt_ip_address': '{"vdu1": "a.b.c.d"}', 'attributes': { 'monitoring_policy': jsonutils.dump_as_bytes( MOCK_VNF['monitoring_policy']) }, 'status': 'ACTIVE', } } test_vnfmonitor.add_hosting_vnf(vnf_dict) vnf_dict['status'] = 'PENDING_HEAL' test_vnfmonitor.update_hosting_vnf(vnf_dict) test_device_status = test_vnfmonitor._hosting_vnfs[MOCK_VNF_ID][ 'vnf']['status'] self.assertEqual('PENDING_HEAL', test_device_status)
Example #13
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_deployment_flavour( self, mock_instantiate, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_save, mock_vnf_instance_get_by_id, mock_get_vim): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "simple"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_instantiate.assert_called_once()
Example #14
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_non_existing_deployment_flavour( self, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_vnf_instance_get_by_id): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "invalid"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.BAD_REQUEST, resp.status_code) self.assertEqual("No flavour with id 'invalid'.", resp.json['badRequest']['message'])
Example #15
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_instantiation_level( self, mock_instantiate, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_save, mock_vnf_instance_get_by_id, mock_get_vim): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() body = {"flavourId": "simple", "instantiationLevelId": "instantiation_level_1"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_instantiate.assert_called_once()
Example #16
Source File: test_k8s_client.py From kuryr-kubernetes with Apache License 2.0 | 6 votes |
def test_watch(self, m_get): path = '/test' data = [{'obj': 'obj%s' % i} for i in range(3)] lines = [jsonutils.dump_as_bytes(i) for i in data] m_resp = mock.MagicMock() m_resp.ok = True m_resp.iter_lines.return_value = lines m_get.return_value = m_resp cycles = 3 self.assertEqual( data * cycles, list(itertools.islice(self.client.watch(path), len(data) * cycles))) self.assertEqual(cycles, m_get.call_count) self.assertEqual(cycles, m_resp.close.call_count) m_get.assert_called_with(self.base_url + path, headers={}, stream=True, params={'watch': 'true'}, cert=(None, None), verify=False, timeout=(30, 60))
Example #17
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_default_vim_not_configured( self, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id, mock_vnf_instance_get_by_id, mock_get_vim): mock_vnf_instance_get_by_id.return_value =\ fakes.return_vnf_instance_model() mock_vnf_package_vnfd_get_by_id.return_value = \ fakes.return_vnf_package_vnfd() mock_vnf_package_get_by_id.return_value = \ fakes.return_vnf_package_with_deployment_flavour() mock_get_vim.side_effect = nfvo.VimDefaultNotDefined body = {"flavourId": "simple"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.BAD_REQUEST, resp.status_code) self.assertEqual("Default VIM is not defined.", resp.json['badRequest']['message'])
Example #18
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_incorrect_task_state(self, mock_vnf_by_id): vnf_instance = fakes.return_vnf_instance_model( task_state=fields.VnfInstanceTaskState.INSTANTIATING) mock_vnf_by_id.return_value = vnf_instance body = {"flavourId": "simple"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.CONFLICT, resp.status_code) expected_msg = ("Vnf instance %s in task_state INSTANTIATING. Cannot " "instantiate while the vnf instance is in this state.") self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id, resp.json['conflictingRequest']['message'])
Example #19
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_invalid_request_parameter(self): body = {"flavourId": "simple"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) # Pass invalid request parameter body = {"flavourId": "simple"} body.update({'additional_property': 'test_value'}) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.BAD_REQUEST, resp.status_code) self.assertEqual("Additional properties are not allowed " "('additional_property' was unexpected)", resp.json['badRequest']['message'])
Example #20
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_instantiate_with_non_existing_vnf_instance( self, mock_vnf_by_id): mock_vnf_by_id.side_effect = exceptions.VnfInstanceNotFound body = {"flavourId": "simple"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' # Call Instantiate API resp = req.get_response(self.app) self.assertEqual(http_client.NOT_FOUND, resp.status_code) self.assertEqual("Can not find requested vnf instance: %s" % uuidsentinel.vnf_instance_id, resp.json['itemNotFound']['message'])
Example #21
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_terminate_with_invalid_request_body( self, attribute, value, expected_type): req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/terminate' % uuidsentinel.vnf_instance_id) body = {'terminationType': 'GRACEFUL', 'gracefulTerminationTimeout': 10} body.update({attribute: value}) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' expected_message = ("Invalid input for field/attribute {attribute}. " "Value: {value}.".format(value=value, attribute=attribute)) exception = self.assertRaises(exceptions.ValidationError, self.controller.terminate, req, constants.UUID, body=body) self.assertIn(expected_message, exception.msg)
Example #22
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_terminate_non_existing_vnf_instance(self, mock_vnf_by_id): body = {'terminationType': 'GRACEFUL', 'gracefulTerminationTimeout': 10} mock_vnf_by_id.side_effect = exceptions.VnfInstanceNotFound req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/terminate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.NOT_FOUND, resp.status_code) self.assertEqual("Can not find requested vnf instance: %s" % uuidsentinel.vnf_instance_id, resp.json['itemNotFound']['message'])
Example #23
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_terminate_incorrect_instantiation_state(self, mock_vnf_by_id): mock_vnf_by_id.return_value = fakes.return_vnf_instance() body = {"terminationType": "FORCEFUL"} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/terminate' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.CONFLICT, resp.status_code) expected_msg = ("Vnf instance %s in instantiation_state " "NOT_INSTANTIATED. Cannot terminate while the vnf " "instance is in this state.") self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id, resp.json['conflictingRequest']['message'])
Example #24
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_heal(self, body, mock_rpc_heal, mock_save, mock_vnf_by_id): vnf_instance_obj = fakes.return_vnf_instance( fields.VnfInstanceState.INSTANTIATED) mock_vnf_by_id.return_value = vnf_instance_obj req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.ACCEPTED, resp.status_code) mock_rpc_heal.assert_called_once()
Example #25
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_heal_incorrect_instantiated_state(self, mock_vnf_by_id): vnf_instance_obj = fakes.return_vnf_instance( fields.VnfInstanceState.NOT_INSTANTIATED) mock_vnf_by_id.return_value = vnf_instance_obj body = {} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.CONFLICT, resp.status_code) expected_msg = ("Vnf instance %s in instantiation_state " "NOT_INSTANTIATED. Cannot heal while the vnf instance " "is in this state.") self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id, resp.json['conflictingRequest']['message'])
Example #26
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_heal_incorrect_task_state(self, mock_vnf_by_id): vnf_instance_obj = fakes.return_vnf_instance( fields.VnfInstanceState.INSTANTIATED, task_state=fields.VnfInstanceTaskState.HEALING) mock_vnf_by_id.return_value = vnf_instance_obj body = {} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.CONFLICT, resp.status_code) expected_msg = ("Vnf instance %s in task_state " "HEALING. Cannot heal while the vnf instance " "is in this state.") self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id, resp.json['conflictingRequest']['message'])
Example #27
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_heal_with_invalid_vnfc_id(self, mock_vnf_by_id): vnf_instance_obj = fakes.return_vnf_instance( fields.VnfInstanceState.INSTANTIATED) mock_vnf_by_id.return_value = vnf_instance_obj body = {'vnfcInstanceId': [uuidsentinel.vnfc_instance_id]} req = fake_request.HTTPRequest.blank( '/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' resp = req.get_response(self.app) self.assertEqual(http_client.BAD_REQUEST, resp.status_code) expected_msg = "Vnfc id %s not present in vnf instance %s" self.assertEqual(expected_msg % (uuidsentinel.vnfc_instance_id, uuidsentinel.vnf_instance_id), resp.json['badRequest']['message'])
Example #28
Source File: test_controller.py From tacker with Apache License 2.0 | 6 votes |
def test_heal_with_invalid_request_body( self, attribute, value, expected_type): body = {} req = fake_request.HTTPRequest.blank( '/vnf_instances/29c770a3-02bc-4dfc-b4be-eb173ac00567/heal') body.update({attribute: value}) req.body = jsonutils.dump_as_bytes(body) req.headers['Content-Type'] = 'application/json' req.method = 'POST' exception = self.assertRaises( exceptions.ValidationError, self.controller.heal, req, body=body) expected_message = \ ("Invalid input for field/attribute {attribute}. Value: {value}. " "{value} is not of type '{expected_type}'". format(value=value, attribute=attribute, expected_type=expected_type)) self.assertEqual(expected_message, exception.msg)
Example #29
Source File: test_placement_helper.py From watcher with Apache License 2.0 | 6 votes |
def test_get_resource_providers_OK(self, kss_req): rp_name = 'compute' rp_uuid = uuidutils.generate_uuid() parent_uuid = uuidutils.generate_uuid() fake_rp = [{'uuid': rp_uuid, 'name': rp_name, 'generation': 0, 'parent_provider_uuid': parent_uuid}] mock_json_data = { 'resource_providers': fake_rp } kss_req.return_value = fake_requests.FakeResponse( 200, content=jsonutils.dump_as_bytes(mock_json_data)) result = self.client.get_resource_providers(rp_name) expected_url = '/resource_providers?name=compute' self._assert_keystone_called_once(kss_req, expected_url, 'GET') self.assertEqual(fake_rp, result)
Example #30
Source File: test_placement_helper.py From watcher with Apache License 2.0 | 6 votes |
def test_get_resource_providers_no_rp_OK(self, kss_req): rp_name = None rp_uuid = uuidutils.generate_uuid() parent_uuid = uuidutils.generate_uuid() fake_rp = [{'uuid': rp_uuid, 'name': 'compute', 'generation': 0, 'parent_provider_uuid': parent_uuid}] mock_json_data = { 'resource_providers': fake_rp } kss_req.return_value = fake_requests.FakeResponse( 200, content=jsonutils.dump_as_bytes(mock_json_data)) result = self.client.get_resource_providers(rp_name) expected_url = '/resource_providers' self._assert_keystone_called_once(kss_req, expected_url, 'GET') self.assertEqual(fake_rp, result)