def positive_integer_validator(value, context):
   if value is None:
      return None
   if hasattr(value, 'strip') and not value.strip():
      return None
   value = int_validator(value, context)
   if value < 1:
      raise Invalid(_('Must be a positive integer'))
   return value
Beispiel #2
0
 def test_empty_string_becomes_None(self):
     assert_equals(validators.int_validator('', {}), None)
Beispiel #3
0
 def test_zero_prefixed_int_string_converted_as_decimal(self):
     assert_equals(validators.int_validator('0123', {}), 123)
Beispiel #4
0
 def test_negative_int_string_converted(self):
     assert_equals(validators.int_validator('-2', {}), -2)
Beispiel #5
0
 def test_decimal_converted(self):
     assert_equals(validators.int_validator(
         decimal.Decimal('19.00'), {}), 19)
Beispiel #6
0
 def test_float_converted(self):
     assert_equals(validators.int_validator(42.0, None), 42)
Beispiel #7
0
def test_fraction_converted():
    assert validators.int_validator(fractions.Fraction(2, 1), {}) == 2
Beispiel #8
0
 def test_string_with_whitespace_converted(self):
     assert_equals(validators.int_validator('\t  98\n', {}), 98)
Beispiel #9
0
 def test_positive_int_string_converted(self):
     assert_equals(validators.int_validator('+3', {}), 3)
Beispiel #10
0
 def test_zero_prefixed_int_string_converted_as_decimal(self):
     assert_equals(validators.int_validator('0123', {}), 123)
Beispiel #11
0
 def test_negative_int_string_converted(self):
     assert_equals(validators.int_validator('-2', {}), -2)
Beispiel #12
0
 def test_long_int_string_converted(self):
     assert_equals(validators.int_validator('528735648764587235684376', {}),
                   528735648764587235684376)
Beispiel #13
0
 def test_decimal_converted(self):
     assert_equals(validators.int_validator(decimal.Decimal('19.00'), {}),
                   19)
Beispiel #14
0
 def test_fraction_converted(self):
     assert_equals(validators.int_validator(fractions.Fraction(2, 1), {}),
                   2)
Beispiel #15
0
 def test_empty_string_becomes_None(self):
     assert_equals(validators.int_validator('', {}), None)
def test_whitespace_string_becomes_None():
    assert validators.int_validator("\n\n  \t", {}) is None
Beispiel #17
0
 def test_whitespace_string_becomes_None(self):
     assert_equals(validators.int_validator('\n\n  \t', {}), None)
Beispiel #18
0
def test_float_converted():
    assert validators.int_validator(42.0, None) == 42
def test_long_int_string_converted():
    assert (validators.int_validator("528735648764587235684376",
                                     {}) == 528735648764587235684376)
Beispiel #20
0
def test_decimal_converted():
    assert validators.int_validator(decimal.Decimal("19.00"), {}) == 19
def test_negative_int_string_converted():
    assert validators.int_validator("-2", {}) == -2
Beispiel #22
0
 def test_fraction_converted(self):
     assert_equals(validators.int_validator(
         fractions.Fraction(2, 1), {}), 2)
def test_positive_int_string_converted():
    assert validators.int_validator("+3", {}) == 3
Beispiel #24
0
 def test_long_int_string_converted(self):
     assert_equals(validators.int_validator(
         '528735648764587235684376', {}), 528735648764587235684376)
def test_zero_prefixed_int_string_converted_as_decimal():
    assert validators.int_validator("0123", {}) == 123
Beispiel #26
0
 def test_positive_int_string_converted(self):
     assert_equals(validators.int_validator('+3', {}), 3)
def test_string_with_whitespace_converted():
    assert validators.int_validator("\t  98\n", {}) == 98
Beispiel #28
0
 def test_string_with_whitespace_converted(self):
     assert_equals(validators.int_validator('\t  98\n', {}), 98)
def test_empty_string_becomes_None():
    assert validators.int_validator("", {}) is None
Beispiel #30
0
 def test_whitespace_string_becomes_None(self):
     assert_equals(validators.int_validator('\n\n  \t', {}), None)
Beispiel #31
0
 def test_float_converted(self):
     assert_equals(validators.int_validator(42.0, None), 42)