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