def test_voc_factory(self): from ptah.form.fields import VocabularyField voc = object() def factory(context): return voc field = VocabularyField('test', voc_factory=factory) clone = field.bind('p.', None, None) self.assertIs(clone.vocabulary, voc)
def test_voc_factory(self): from ptah.form.fields import VocabularyField voc = object() def factory(context): return voc field = VocabularyField('test', voc_factory=factory) clone = field.bind(self.request, 'p.', None, None) self.assertIs(clone.vocabulary, voc)
def test_ctor_convert_vocabulary(self): from ptah.form.fields import VocabularyField field = VocabularyField('test', vocabulary=('one', 'two')) self.assertIsInstance(field.vocabulary, ptah.form.Vocabulary) self.assertIs(field.vocabulary, field.cls.vocabulary) self.assertEqual(2, len(field.vocabulary))
def test_voc_factory_context(self): from ptah.form.fields import VocabularyField voc = object() data = [] def factory(context): data.append(context) return voc field = VocabularyField('test', voc_factory=factory) clone = field.bind('p.', None, None) self.assertIsNone(data[-1]) context = object() clone = field.bind('p.', None, None, context) self.assertIs(data[-1], context)
def test_voc_factory_context(self): from ptah.form.fields import VocabularyField voc = object() data = [] def factory(c): data.append(c) return voc field = VocabularyField('test', voc_factory=factory) field.bind(self.request, 'p.', None, None) self.assertIsNone(data[-1]) context = object() field.bind(self.request, 'p.', None, None, context) self.assertIs(data[-1], context)