예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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))
예제 #4
0
    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)
예제 #5
0
    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)