Пример #1
0
 def test_coerce_with_max(self):
     """
     L{Parameter.coerce} raises an error if the given value is greater than
     the upper bound.
     """
     parameter = Parameter("Test", max=3)
     parameter.measure = lambda value: len(value)
     parameter.greater_than_max_template = "%s should be enough for anybody"
     error = self.assertRaises(APIError, parameter.coerce, "longish")
     self.assertEqual(400, error.status)
     self.assertEqual("InvalidParameterValue", error.code)
     self.assertEqual("Value (longish) for parameter Test is invalid.  "
                      "3 should be enough for anybody", error.message)
Пример #2
0
 def test_coerce_with_max(self):
     """
     L{Parameter.coerce} raises an error if the given value is greater than
     the upper bound.
     """
     parameter = Parameter("Test", max=3)
     parameter.measure = lambda value: len(value)
     parameter.greater_than_max_template = "%s should be enough for anybody"
     error = self.assertRaises(APIError, parameter.coerce, "longish")
     self.assertEqual(400, error.status)
     self.assertEqual("InvalidParameterValue", error.code)
     self.assertEqual("Value (longish) for parameter Test is invalid.  "
                      "3 should be enough for anybody", error.message)
Пример #3
0
 def test_coerce_with_min(self):
     """
     L{Parameter.coerce} raises an error if the given value is lower than
     the lower bound.
     """
     parameter = Parameter("Test", min=50)
     parameter.measure = lambda value: int(value)
     parameter.lower_than_min_template = "Please give me at least %s"
     error = self.assertRaises(APIError, parameter.coerce, "4")
     self.assertEqual(400, error.status)
     self.assertEqual("InvalidParameterValue", error.code)
     self.assertEqual("Value (4) for parameter Test is invalid.  "
                      "Please give me at least 50", error.message)
Пример #4
0
 def test_coerce_with_min(self):
     """
     L{Parameter.coerce} raises an error if the given value is lower than
     the lower bound.
     """
     parameter = Parameter("Test", min=50)
     parameter.measure = lambda value: int(value)
     parameter.lower_than_min_template = "Please give me at least %s"
     error = self.assertRaises(APIError, parameter.coerce, "4")
     self.assertEqual(400, error.status)
     self.assertEqual("InvalidParameterValue", error.code)
     self.assertEqual("Value (4) for parameter Test is invalid.  "
                      "Please give me at least 50", error.message)