def test_get_prep_value_convert(self):
        field = StringListField('testing')

        self.assertEqual(field.get_prep_value(["A", "B", "C"]), '["A", "B", "C"]')

        with self.assertRaises(ValueError):
            field.get_prep_value(5)
Exemple #2
0
    def test_to_python_already_done(self):
        field = StringListField('testing')
        self.assertEqual(field.to_python([]), [])
        self.assertEqual(field.to_python(["A", "B", "C"]), ['A', 'B', 'C'])

        with self.assertRaises(ValueError):
            field.to_python(4)

        with self.assertRaises(ValueError):
            field.to_python([1, 2, 3])

        with self.assertRaises(ValueError):
            field.to_python(None)
Exemple #3
0
    def test_to_python_already_done(self):
        field = StringListField('testing')
        self.assertEqual(field.to_python([]), [])
        self.assertEqual(field.to_python(["A", "B", "C"]), ['A', 'B', 'C'])

        with self.assertRaises(ValueError):
            field.to_python(4)

        with self.assertRaises(ValueError):
            field.to_python([1, 2, 3])

        with self.assertRaises(ValueError):
            field.to_python(None)
    def test_to_python_convert(self):
        field = StringListField('testing')

        # This that are legitimate to store in the DB
        self.assertEqual(field.to_python('[]'), [])
        self.assertEqual(field.to_python('["A","B","C"]'), ['A', 'B', 'C'])

        # Erroneous values that should never end up in the database
        with self.assertRaises(ValueError):
            field.to_python('[1,2,3]')

        with self.assertRaises(ValueError):
            field.to_python('"hello"')

        with self.assertRaises(ValueError):
            field.to_python('{"hi": "foo"}')
    def test_is_string_list(self):
        field = StringListField('testing')

        self.assertTrue(field.is_string_list([]))
        self.assertTrue(field.is_string_list(["hello", "goodbye"]))

        self.assertFalse(field.is_string_list("boo"))
        self.assertFalse(field.is_string_list(3))
        self.assertFalse(field.is_string_list('"A","B"'))
    def test_get_prep_value_convert(self):
        field = StringListField('testing')

        self.assertEqual(field.get_prep_value(["A", "B", "C"]), 'A,B,C')
        self.assertEqual(field.get_prep_value(["A", "B,C", "D"]), 'A,"B,C",D')

        with self.assertRaises(ValueError):
            field.get_prep_value(5)
 def test_to_python_convert(self):
     field = StringListField('testing')
     self.assertEqual(field.to_python(''), [])
     self.assertEqual(field.to_python('"A","B","C"'), ['A', 'B', 'C'])