Example #1
0
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)
Example #2
0
 def test_value(self):
     self.assertEqual(validate_amount(10), 10.0)
     self.assertEqual(validate_amount(2.11), 2.11)
Example #3
0
 def test_instance_of(self):
     self.assertTrue(isinstance(validate_amount(10), float))
     self.assertTrue(isinstance(validate_amount(2.11), float))
Example #4
0
 def test_empty_string(self):
     with self.assertRaises(ValueError):
         validate_amount(" ")
Example #5
0
 def test_string_value(self):
     with self.assertRaises(ValueError):
         validate_amount("22.0qw")
Example #6
0
 def test_Inf(self):
     with self.assertRaises(argparse.ArgumentTypeError):
         validate_amount(float('Inf'))
Example #7
0
 def test_negative_value(self):
     with self.assertRaises(argparse.ArgumentTypeError):
         validate_amount(-34.14)