def test_to_python_already_done(self): field = StringSetField('testing') self.assertEqual(field.to_python([]), set()) self.assertEqual(field.to_python(set(["A","B","C"])), set(['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 = StringSetField('testing') # This that are legitimate to store in the DB self.assertEqual(field.to_python('[]'), set()) self.assertEqual(field.to_python('["A","B","C"]'), set(['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 = StringSetField('testing') # This that are legitimate to store in the DB self.assertEqual(field.to_python(''), set()) self.assertEqual(field.to_python('"A","B","C"'), set(['A', 'B', 'C']))