def test__get_validated_image_not_found(self, mock_transform): clients = mock.MagicMock() clients.glance().images.get().to_dict.side_effect = ( glance_exc.HTTPNotFound("")) result = validation._get_validated_image({"args": {"a": "test"}}, clients, "a") self.assertFalse(result[0].is_valid, result[0].msg)
def test__get_validated_image(self, mock_transform): mock_transform.return_value = "image_id" clients = mock.MagicMock() clients.glance().images.get.return_value = "image" result = validation._get_validated_image({"args": {"a": "test"}}, clients, "a") self.assertTrue(result[0].is_valid, result[0].msg) self.assertEqual(result[1], "image") mock_transform.assert_called_once_with(clients=clients, resource_config="test") clients.glance().images.get.assert_called_once_with(image="image_id")
def test__get_validated_image(self, mock_image_resource_type_transform): clients = mock.MagicMock() clients.glance().images.get().to_dict.return_value = { "image": "image_id"} result = validation._get_validated_image({"args": {"a": "test"}, "context": { "image_name": "foo"}}, clients, "a") self.assertTrue(result[0].is_valid, result[0].msg) self.assertEqual(result[1], {"image": "image_id"}) mock_image_resource_type_transform.assert_called_once_with( clients=clients, resource_config="test") clients.glance().images.get.assert_called_with(image="image_id")
def test__get_validated_image_from_context(self): clients = mock.MagicMock() image = { "size": 0, "min_ram": 0, "min_disk": 0 } result = validation._get_validated_image({"args": { "image": {"name": "foo"}}, "context": { "images": { "image_name": "foo"} }}, clients, "image") self.assertTrue(result[0].is_valid, result[0].msg) self.assertEqual(result[1], image) result = validation._get_validated_image({"args": { "image": {"regex": r"^foo$"}}, "context": { "images": { "image_name": "foo"} }}, clients, "image") self.assertTrue(result[0].is_valid, result[0].msg) self.assertEqual(result[1], image)
def test__get_validated_image_transform_error( self, mock_image_resource_type_transform): result = validation._get_validated_image({"args": {"a": "test"}}, None, "a") self.assertFalse(result[0].is_valid, result[0].msg)
def test__get_validated_image_no_value_in_config(self): result = validation._get_validated_image({}, None, "non_existing") self.assertFalse(result[0].is_valid, result[0].msg)
def test__get_validated_image_transform_error(self, mock_transform): mock_transform.side_effect = exceptions.InvalidScenarioArgument result = validation._get_validated_image({"args": {"a": "test"}}, None, "a") self.assertFalse(result[0].is_valid, result[0].msg)