def setUp(self):
     super(RequiredServicesValidatorTestCase, self).setUp()
     self.validator = validators.RequiredServicesValidator([
         consts.Service.KEYSTONE,
         consts.Service.NOVA])
     self.config = config
     self.context = context
    def test_validator_wrong_service(self):

        self.config["context"]["api_versions@openstack"].get = mock.Mock(
            return_value={consts.Service.KEYSTONE: "service_type",
                          consts.Service.NOVA: "service_name"})

        clients = self.context["admin"].get("credential").clients()
        clients.services().values.return_value = [
            consts.Service.KEYSTONE, consts.Service.NOVA]

        validator = validators.RequiredServicesValidator([
            consts.Service.KEYSTONE,
            consts.Service.NOVA, "lol"])

        e = self.assertRaises(
            validators.validation.ValidationError,
            validator.validate, self.context, {}, None, None)
        expected_msg = ("'{0}' service is not available. Hint: If '{0}'"
                        " service has non-default service_type, try to setup"
                        " it via 'api_versions' context.").format("lol")
        self.assertEqual(expected_msg, e.message)