def test_to_python_string(self):
     item = SelectMultipleField()
     for i, v in enumerate(self.choices_list):
         subset = self.choices_list[0: i]
         encoded = encode_list_to_csv(subset)
         self.assertIsInstance(item.to_python(encoded), list)
         self.assertEqual(item.to_python(encoded), sorted(subset))
 def test_field_to_python_value_is_encoded_string(self):
     """Widget may return encoded string as value for key in POST"""
     ff = SelectMultipleFormField()
     for i, v in enumerate(self.choices_list):
         subset = self.choices_list[0: i]
         encoded = encode_list_to_csv(subset)
         self.assertEqual(ff.to_python(encoded), sorted(subset))
Exemplo n.º 3
0
 def test_max_length_many(self):
     for n in range(2, len(self.choices_list)):
         many_choices = self.choices_list[0:n]
         encoded_choices_len = len(encode_list_to_csv(many_choices))
         item = SelectMultipleField(choices=self.choices,
                                    max_length=encoded_choices_len)
         self.assertEqual(item.max_length, encoded_choices_len)
         self.assertIsInstance(item.validators[0], MaxLengthValidator)
         self.assertIs(item.run_validators(value=many_choices), None)
 def test_max_length_many(self):
     for n in range(2, len(self.choices_list)):
         many_choices = self.choices_list[0:n]
         encoded_choices_len = len(encode_list_to_csv(many_choices))
         item = SelectMultipleField(
             choices=self.choices, max_length=encoded_choices_len)
         self.assertEqual(item.max_length, encoded_choices_len)
         self.assertIsInstance(item.validators[0], MaxLengthValidator)
         self.assertIs(item.run_validators(value=many_choices), None)
Exemplo n.º 5
0
    def test_max_length_validationerror_many(self):
        for n in range(2, len(self.choices_list)):
            test_max_length = 2 * n - 2  # One less than encoded list len
            item = SelectMultipleField(choices=self.choices,
                                       max_length=test_max_length)
            self.assertEqual(item.max_length, test_max_length)
            self.assertIsInstance(item.validators[0], MaxLengthValidator)
            many_choices = self.choices_list[0:n]
            many_choices_len = len(encode_list_to_csv(many_choices))
            self.assertTrue(many_choices_len > test_max_length)
            with self.assertRaises(ValidationError) as cm:
                item.run_validators(value=many_choices)

            self.assertEqual(
                cm.exception.messages[0], MaxLengthValidator.message % {
                    'limit_value': item.max_length,
                    'show_value': many_choices_len
                })
    def test_max_length_validationerror_many(self):
        for n in range(2, len(self.choices_list)):
            test_max_length = 2 * n - 2  # One less than encoded list len
            item = SelectMultipleField(
                choices=self.choices, max_length=test_max_length)
            self.assertEqual(item.max_length, test_max_length)
            self.assertIsInstance(item.validators[0], MaxLengthValidator)
            many_choices = self.choices_list[0:n]
            many_choices_len = len(encode_list_to_csv(many_choices))
            self.assertTrue(many_choices_len > test_max_length)
            with self.assertRaises(ValidationError) as cm:
                item.run_validators(value=many_choices)

            self.assertEqual(
                cm.exception.messages[0],
                MaxLengthValidator.message % {
                    'limit_value': item.max_length,
                    'show_value': many_choices_len}
            )
 def test_encoder_delimiter(self):
     with self.settings(SELECTMULTIPLEFIELD_DELIMITER=self.wild_delimiter):
         encoded = encode_list_to_csv(self.test_list)
         self.assertEqual(encoded, self.test_encoded_alt)
 def test_encoder_deduplicates(self):
     encoded = encode_list_to_csv(self.test_list * 3)
     self.assertEqual(encoded, self.test_encoded)
 def test_encoder_on_empty_list(self):
     encoded = encode_list_to_csv([])
     self.assertEqual(encoded, '')
 def test_encoder(self):
     encoded = encode_list_to_csv(self.test_list)
     self.assertEqual(encoded, self.test_encoded)
     encoded = encode_list_to_csv(self.test_list[0:1])
     self.assertEqual(encoded, self.test_encoded[0:1])
Exemplo n.º 11
0
 def test_encoder_delimiter(self):
     with self.settings(SELECTMULTIPLEFIELD_DELIMITER=self.wild_delimiter):
         encoded = encode_list_to_csv(self.test_list)
         self.assertEqual(encoded, self.test_encoded_alt)
Exemplo n.º 12
0
 def test_encoder_deduplicates(self):
     encoded = encode_list_to_csv(self.test_list * 3)
     self.assertEqual(encoded, self.test_encoded)
Exemplo n.º 13
0
 def test_encoder_on_empty_list(self):
     encoded = encode_list_to_csv([])
     self.assertEqual(encoded, '')
Exemplo n.º 14
0
 def test_encoder(self):
     encoded = encode_list_to_csv(self.test_list)
     self.assertEqual(encoded, self.test_encoded)
     encoded = encode_list_to_csv(self.test_list[0:1])
     self.assertEqual(encoded, self.test_encoded[0:1])