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_to_python_convert(self): field = StringListField('testing') self.assertEqual(field.to_python(''), []) self.assertEqual(field.to_python('"A","B","C"'), ['A', 'B', 'C'])