Ejemplo n.º 1
0
 def _format_checker(self, format, value, error_message):
     format_checker = validators.FormatChecker()
     exc = self.assertRaises(jsonschema_exc.FormatError,
                             format_checker.check, value, format)
     self.assertIsInstance(exc.cause, exception.InvalidName)
     self.assertEqual(error_message,
                      exc.cause.format_message())
 def test_format_checker_failed(self):
     format_checker = validators.FormatChecker()
     exc = self.assertRaises(jsonschema_exc.FormatError,
                             format_checker.check, "   ", "name")
     self.assertIsInstance(exc.cause, exception.InvalidName)
     self.assertEqual("An invalid 'name' value was provided. The name must "
                      "be: printable characters. "
                      "Can not start or end with whitespace.",
                      exc.cause.format_message())
    def test_format_checker_failed_with_non_string(self):
        checks = ["name", "name_with_leading_trailing_spaces",
                  "cell_name", "cell_name_with_leading_trailing_spaces"]
        format_checker = validators.FormatChecker()

        for check in checks:
            exc = self.assertRaises(jsonschema_exc.FormatError,
                                    format_checker.check, None, "name")
            self.assertIsInstance(exc.cause, exception.InvalidName)
            self.assertEqual("An invalid 'name' value was provided. The name "
                             "must be: printable characters. "
                             "Can not start or end with whitespace.",
                             exc.cause.format_message())