Ejemplo n.º 1
0
 def test_validators_fail_base_max_length(self):
     field = SimpleSetField(forms.CharField(max_length=5))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('longer,yes')
     assert (excinfo.value.messages[0] ==
             'Item "longer" in the set did not validate: '
             'Ensure this value has at most 5 characters (it has 6).')
Ejemplo n.º 2
0
 def test_to_python_duplicates_not_allowed(self):
     field = SimpleSetField(forms.IntegerField())
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('1,1')
     assert (
         excinfo.value.messages[0] ==
         "Duplicates are not supported. '1' appears twice or more."
     )
Ejemplo n.º 3
0
 def test_to_python_base_field_does_not_validate(self):
     field = SimpleSetField(forms.IntegerField())
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,b,9')
     assert (
         excinfo.value.messages[0] ==
         'Item 1 in the set did not validate: Enter a whole number.'
     )
Ejemplo n.º 4
0
 def test_to_python_no_double_commas(self):
     field = SimpleSetField(forms.IntegerField())
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('1,,2')
     assert (
         excinfo.value.messages[0] ==
         'No leading, trailing, or double commas.'
     )
Ejemplo n.º 5
0
 def test_validators_fail(self):
     field = SimpleSetField(forms.RegexField('[a-e]{2}'))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,bc,de')
     assert (
         excinfo.value.messages[0] ==
         'Item "a" in the set did not validate: Enter a valid value.'
     )
Ejemplo n.º 6
0
 def test_min_length(self):
     field = SimpleSetField(forms.CharField(), min_length=4)
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,b,c')
     assert (
         excinfo.value.messages[0] ==
         'Set contains 3 items, it should contain no fewer than 4.'
     )
Ejemplo n.º 7
0
 def test_max_length(self):
     field = SimpleSetField(forms.CharField(), max_length=2)
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean("a,b,c")
     assert (
         excinfo.value.messages[0]
         == "Set contains 3 items, it should contain no more than 2."
     )
Ejemplo n.º 8
0
 def test_min_length(self):
     field = SimpleSetField(forms.CharField(), min_length=4)
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,b,c')
     assert (
         excinfo.value.messages[0] ==
         'Set contains 3 items, it should contain no fewer than 4.'
     )
Ejemplo n.º 9
0
 def test_to_python_base_field_does_not_validate(self):
     field = SimpleSetField(forms.IntegerField())
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('a,b,9')
     self.assertEqual(
         cm.exception.messages[0],
         'Item 1 in the set did not validate: Enter a whole number.'
     )
Ejemplo n.º 10
0
 def test_to_python_two_duplicates_not_allowed(self):
     field = SimpleSetField(forms.IntegerField())
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('1,2,1,2')
     assert (excinfo.value.messages[0] ==
             "Duplicates are not supported. '1' appears twice or more.")
     assert (excinfo.value.messages[1] ==
             "Duplicates are not supported. '2' appears twice or more.")
Ejemplo n.º 11
0
 def test_validators_fail(self):
     field = SimpleSetField(forms.RegexField('[a-e]{2}'))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,bc,de')
     assert (
         excinfo.value.messages[0] ==
         'Item "a" in the set did not validate: Enter a valid value.'
     )
Ejemplo n.º 12
0
 def test_min_length(self):
     field = SimpleSetField(forms.CharField(), min_length=4)
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('a,b,c')
     self.assertEqual(
         cm.exception.messages[0],
         'Set contains 3 items, it should contain no fewer than 4.'
     )
Ejemplo n.º 13
0
 def test_to_python_no_double_commas(self):
     field = SimpleSetField(forms.IntegerField())
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('1,,2')
     assert (
         excinfo.value.messages[0] ==
         'No leading, trailing, or double commas.'
     )
Ejemplo n.º 14
0
 def test_to_python_base_field_does_not_validate(self):
     field = SimpleSetField(forms.IntegerField())
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,b,9')
     assert (
         excinfo.value.messages[0] ==
         'Item 1 in the set did not validate: Enter a whole number.'
     )
Ejemplo n.º 15
0
 def test_to_python_duplicates_not_allowed(self):
     field = SimpleSetField(forms.IntegerField())
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('1,1')
     self.assertEqual(
         cm.exception.messages[0],
         "Duplicates are not supported. '1' appears twice or more."
     )
Ejemplo n.º 16
0
 def test_validators_fail(self):
     field = SimpleSetField(forms.RegexField('[a-e]{2}'))
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('a,bc,de')
     self.assertEqual(
         cm.exception.messages[0],
         'Item "a" in the set did not validate: Enter a valid value.'
     )
Ejemplo n.º 17
0
 def test_to_python_no_double_commas(self):
     field = SimpleSetField(forms.IntegerField())
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('1,,2')
     self.assertEqual(
         cm.exception.messages[0],
         'No leading, trailing, or double commas.'
     )
Ejemplo n.º 18
0
 def test_validators_fail_base_max_length(self):
     field = SimpleSetField(forms.CharField(max_length=5))
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('longer,yes')
     self.assertEqual(
         cm.exception.messages[0],
         'Item "longer" in the set did not validate: '
         'Ensure this value has at most 5 characters (it has 6).'
     )
Ejemplo n.º 19
0
 def test_validators_fail_base_max_length(self):
     field = SimpleSetField(forms.CharField(max_length=5))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('longer,yes')
     assert (
         excinfo.value.messages[0] ==
         'Item "longer" in the set did not validate: '
         'Ensure this value has at most 5 characters (it has 6).'
     )
Ejemplo n.º 20
0
 def test_validate_fail(self):
     field = SimpleSetField(
         forms.ChoiceField(choices=(('a', 'The letter A'),
                                    ('b', 'The letter B'))))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,c')
     assert (
         excinfo.value.messages[0] ==
         'Item "c" in the set did not validate: '
         'Select a valid choice. c is not one of the available choices.')
Ejemplo n.º 21
0
 def test_validate_fail(self):
     field = SimpleSetField(
         forms.ChoiceField(choices=[("a",
                                     "The letter A"), ("b",
                                                       "The letter B")]))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean("a,c")
     assert excinfo.value.messages[0] == (
         'Item "c" in the set did not validate: ' +
         "Select a valid choice. c is not one of the available " +
         "choices.")
Ejemplo n.º 22
0
 def test_validators_fail_base_min_max_length(self):
     # there's just no satisfying some people...
     field = SimpleSetField(forms.CharField(min_length=10, max_length=8))
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('undefined')
     assert (excinfo.value.messages[0] ==
             'Item "undefined" in the set did not validate: '
             'Ensure this value has at least 10 characters (it has 9).')
     assert (excinfo.value.messages[1] ==
             'Item "undefined" in the set did not validate: '
             'Ensure this value has at most 8 characters (it has 9).')
Ejemplo n.º 23
0
 def test_validate_fail(self):
     field = SimpleSetField(
         forms.ChoiceField(choices=(('a', 'The letter A'),
                                    ('b', 'The letter B')))
     )
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('a,c')
     self.assertEqual(
         cm.exception.messages[0],
         'Item "c" in the set did not validate: '
         'Select a valid choice. c is not one of the available choices.'
     )
Ejemplo n.º 24
0
 def test_validate_fail(self):
     field = SimpleSetField(
         forms.ChoiceField(choices=(('a', 'The letter A'),
                                    ('b', 'The letter B')))
     )
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('a,c')
     assert (
         excinfo.value.messages[0] ==
         'Item "c" in the set did not validate: '
         'Select a valid choice. c is not one of the available choices.'
     )
Ejemplo n.º 25
0
 def test_validators_fail_base_min_max_length(self):
     # there's just no satisfying some people...
     field = SimpleSetField(forms.CharField(min_length=10, max_length=8))
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('undefined')
     self.assertEqual(
         cm.exception.messages[0],
         'Item "undefined" in the set did not validate: '
         'Ensure this value has at least 10 characters (it has 9).'
     )
     self.assertEqual(
         cm.exception.messages[1],
         'Item "undefined" in the set did not validate: '
         'Ensure this value has at most 8 characters (it has 9).'
     )
Ejemplo n.º 26
0
 def test_required(self):
     field = SimpleSetField(forms.CharField(), required=True)
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('')
     assert excinfo.value.messages[0] == 'This field is required.'
Ejemplo n.º 27
0
 def test_valid(self):
     field = SimpleSetField(forms.CharField())
     value = field.clean("a,b,c")
     assert value == {"a", "b", "c"}
Ejemplo n.º 28
0
 def test_valid(self):
     field = SimpleSetField(forms.CharField())
     value = field.clean('a,b,c')
     assert value == {'a', 'b', 'c'}
Ejemplo n.º 29
0
 def test_valid(self):
     field = SimpleSetField(forms.CharField())
     value = field.clean('a,b,c')
     self.assertEqual(value, {'a', 'b', 'c'})
Ejemplo n.º 30
0
 def test_required(self):
     field = SimpleSetField(forms.CharField(), required=True)
     with pytest.raises(exceptions.ValidationError) as excinfo:
         field.clean('')
     assert excinfo.value.messages[0] == 'This field is required.'
Ejemplo n.º 31
0
 def test_required(self):
     field = SimpleSetField(forms.CharField(), required=True)
     with self.assertRaises(exceptions.ValidationError) as cm:
         field.clean('')
     self.assertEqual(cm.exception.messages[0], 'This field is required.')
Ejemplo n.º 32
0
 def test_valid(self):
     field = SimpleSetField(forms.CharField())
     value = field.clean('a,b,c')
     assert value == {'a', 'b', 'c'}