def test_poll_for_status_error(self, mock_time, mock_message_list): poll_period = 2 some_id = "some_id" global_request_id = "req-someid" action = "some" updated_objects = (base.Resource( None, info={"not_default_field": "creating"}), base.Resource(None, info={"not_default_field": "error"})) poll_fn = mock.MagicMock(side_effect=updated_objects) msg_object = base.Resource(cinderclient.v3.messages.MessageManager, info={"user_message": "ERROR!"}) mock_message_list.return_value = (msg_object, ) self.assertRaises( exceptions.ResourceInErrorState, cinderclient.shell_utils._poll_for_status, poll_fn=poll_fn, obj_id=some_id, global_request_id=global_request_id, messages=cinderclient.v3.messages.MessageManager(api=3.34), info=dict(), action=action, final_ok_states=['available'], status_field="not_default_field", timeout_period=3600) self.assertEqual([mock.call(poll_period)] * 2, mock_time.sleep.call_args_list) self.assertEqual([mock.call(some_id)] * 2, poll_fn.call_args_list)
def test_eq(self): # Two resources of the same type with the same id: equal r1 = base.Resource(None, {'id': 1, 'name': 'hi'}) r2 = base.Resource(None, {'id': 1, 'name': 'hello'}) self.assertEqual(r1, r2) # Two resoruces of different types: never equal r1 = base.Resource(None, {'id': 1}) r2 = volumes.Volume(None, {'id': 1}) self.assertNotEqual(r1, r2) # Two resources with no ID: equal if their info is equal r1 = base.Resource(None, {'name': 'joe', 'age': 12}) r2 = base.Resource(None, {'name': 'joe', 'age': 12}) self.assertEqual(r1, r2)
def test_add_non_ascii_attr_to_resource(self): info = {'gigabytes_тест': -1, 'volumes_тест': -1, 'id': 'admin'} res = base.Resource(None, info) for key, value in info.items(): self.assertEqual(value, getattr(res, key, None))
def test_poll_for_status(self, mock_time): poll_period = 2 some_id = "some-id" global_request_id = "req-someid" action = "some" updated_objects = ( base.Resource(None, info={"not_default_field": "creating"}), base.Resource(None, info={"not_default_field": "available"})) poll_fn = mock.MagicMock(side_effect=updated_objects) cinderclient.shell_utils._poll_for_status( poll_fn = poll_fn, obj_id = some_id, global_request_id = global_request_id, messages = base.Resource(None, {}), info = {}, action = action, status_field = "not_default_field", final_ok_states = ['available'], timeout_period=3600) self.assertEqual([mock.call(poll_period)] * 2, mock_time.sleep.call_args_list) self.assertEqual([mock.call(some_id)] * 2, poll_fn.call_args_list)
def test_api_version(self): version = api_versions.APIVersion('3.1') api = client.Client(api_version=version) manager = test_utils.FakeManagerWithApi(api) r1 = base.Resource(manager, {'id': 1}) self.assertEqual(version, r1.api_version)
def test_resource_object_with_request_ids(self): resp_obj = create_response_obj_with_header() r = base.Resource(None, {"name": "1"}, resp=resp_obj) self.assertEqual([REQUEST_ID], r.request_ids)
def test_to_dict(self): r1 = base.Resource(None, {'id': 1, 'name': 'hi'}) self.assertEqual({'id': 1, 'name': 'hi'}, r1.to_dict())
def test_resource_repr(self): r = base.Resource(None, dict(foo="bar", baz="spam")) self.assertEqual("<Resource baz=spam, foo=bar>", repr(r)) self.assertNotIn("x_openstack_request_ids", repr(r))
def test_resource_repr(self): r = base.Resource(None, dict(foo="bar", baz="spam")) self.assertEqual("<Resource baz=spam, foo=bar>", repr(r))