Example #1
0
    def test_validator(self, param_name, nullable, err_msg, ex=False):
        validator = validators.ImageExistsValidator(param_name, nullable)

        clients = self.context["users"][0].clients.return_value

        clients.glance().images.get = mock.Mock()
        if ex:
            clients.glance().images.get.side_effect = ex

        if err_msg:
            e = self.assertRaises(validators.validation.ValidationError,
                                  validator.validate, self.context,
                                  self.config, None, None)
            self.assertEqual(err_msg, e.message)
        else:
            result = validator.validate(self.config, self.context, None, None)
            self.assertIsNone(result)
Example #2
0
 def setUp(self):
     super(ImageExistsValidatorTestCase, self).setUp()
     self.validator = validators.ImageExistsValidator("image", True)
     self.config = copy.deepcopy(config)
     self.context = copy.deepcopy(context)