def test_to_field(self): doc = DocType() for f in ['question', 'statement']: nameField = doc.to_field(f, AnswerPage._meta.get_field(f)) self.assertIsInstance(nameField, fields.TextField) self.assertEqual(nameField._path, [f]) dateField = doc.to_field('last_edited', AnswerPage._meta.get_field('last_edited')) self.assertIsInstance(dateField, fields.DateField) self.assertEqual(dateField._path, ['last_edited']) for f in ['featured', 'share_and_print']: boolField = doc.to_field(f, AnswerPage._meta.get_field(f)) self.assertIsInstance(boolField, fields.BooleanField) self.assertEqual(boolField._path, [f]) intField = doc.to_field('featured_rank', AnswerPage._meta.get_field('featured_rank')) self.assertIsInstance(intField, fields.IntegerField) self.assertEqual(intField._path, ['featured_rank'])
def test_to_field_with_unknown_field(self): doc = DocType() with self.assertRaises(ModelFieldNotMappedError): doc.to_field('manufacturer', Car._meta.get_field('manufacturer'))
def test_to_field(self): doc = DocType() nameField = doc.to_field('name', Car._meta.get_field('name')) self.assertIsInstance(nameField, fields.TextField) self.assertEqual(nameField._path, ['name'])
def test_to_field_with_unknown_field(self): doc = DocType() with self.assertRaises(ModelFieldNotMappedError): doc.to_field('answer_base', AnswerPage._meta.get_field('answer_base'))