예제 #1
0
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
예제 #2
0
 def test_empty_string_becomes_None(self):
     assert_equals(validators.int_validator('', {}), None)
예제 #3
0
 def test_zero_prefixed_int_string_converted_as_decimal(self):
     assert_equals(validators.int_validator('0123', {}), 123)
예제 #4
0
 def test_negative_int_string_converted(self):
     assert_equals(validators.int_validator('-2', {}), -2)
예제 #5
0
 def test_decimal_converted(self):
     assert_equals(validators.int_validator(
         decimal.Decimal('19.00'), {}), 19)
예제 #6
0
 def test_float_converted(self):
     assert_equals(validators.int_validator(42.0, None), 42)
예제 #7
0
def test_fraction_converted():
    assert validators.int_validator(fractions.Fraction(2, 1), {}) == 2
예제 #8
0
 def test_string_with_whitespace_converted(self):
     assert_equals(validators.int_validator('\t  98\n', {}), 98)
예제 #9
0
 def test_positive_int_string_converted(self):
     assert_equals(validators.int_validator('+3', {}), 3)
예제 #10
0
 def test_zero_prefixed_int_string_converted_as_decimal(self):
     assert_equals(validators.int_validator('0123', {}), 123)
예제 #11
0
 def test_negative_int_string_converted(self):
     assert_equals(validators.int_validator('-2', {}), -2)
예제 #12
0
 def test_long_int_string_converted(self):
     assert_equals(validators.int_validator('528735648764587235684376', {}),
                   528735648764587235684376)
예제 #13
0
 def test_decimal_converted(self):
     assert_equals(validators.int_validator(decimal.Decimal('19.00'), {}),
                   19)
예제 #14
0
 def test_fraction_converted(self):
     assert_equals(validators.int_validator(fractions.Fraction(2, 1), {}),
                   2)
예제 #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
예제 #17
0
 def test_whitespace_string_becomes_None(self):
     assert_equals(validators.int_validator('\n\n  \t', {}), None)
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #30
0
 def test_whitespace_string_becomes_None(self):
     assert_equals(validators.int_validator('\n\n  \t', {}), None)
예제 #31
0
 def test_float_converted(self):
     assert_equals(validators.int_validator(42.0, None), 42)