def set_amount(input_amount): """ Validate and set the arguments['amount'] value :param input_amount: input amount value from HTTP request :return: amount value which represented by the float number """ # default amount value is 1 if (input_amount is None) or (not input_amount): return 1.0 else: return core.validate_amount(input_amount)
def test_value(self): self.assertEqual(validate_amount(10), 10.0) self.assertEqual(validate_amount(2.11), 2.11)
def test_instance_of(self): self.assertTrue(isinstance(validate_amount(10), float)) self.assertTrue(isinstance(validate_amount(2.11), float))
def test_empty_string(self): with self.assertRaises(ValueError): validate_amount(" ")
def test_string_value(self): with self.assertRaises(ValueError): validate_amount("22.0qw")
def test_Inf(self): with self.assertRaises(argparse.ArgumentTypeError): validate_amount(float('Inf'))
def test_negative_value(self): with self.assertRaises(argparse.ArgumentTypeError): validate_amount(-34.14)