def setUp(self): super(TestLaunchpadRadioWidgetWithDescription, self).setUp() self.request = LaunchpadTestRequest() field = Choice(__name__='test_field', vocabulary=self.TestEnum) self.field = field.bind(object()) self.widget = LaunchpadRadioWidgetWithDescription( self.field, self.TestEnum, self.request)
def test_create_vocabulary(self): vocabulary.setVocabularyRegistry(DummyRegistry()) field = Choice(vocabulary="vocab") o = object() bound = field.bind(o) self.assertEqual([term.value for term in bound.vocabulary], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
def test_create_vocabulary(self): vocabulary.setVocabularyRegistry(DummyRegistry()) field = Choice(vocabulary="vocab") o = object() bound = field.bind(o) self.assertEqual([term.value for term in bound.vocabulary], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
def setUp(self): super(TestLaunchpadRadioWidgetWithDescription, self).setUp() self.request = LaunchpadTestRequest() field = Choice(__name__='test_field', vocabulary=self.TestEnum) self.field = field.bind(object()) self.widget = LaunchpadRadioWidgetWithDescription( self.field, self.TestEnum, self.request)
def make_target_git_repository_widget(context): """Given a Git repository or reference, return a widget for selecting where to land it.""" choice = Choice(__name__='test_field', vocabulary='GitRepository') choice = choice.bind(context) request = LaunchpadTestRequest() return TargetGitRepositoryWidget(choice, None, request)
def setUp(self): super(ItemWidgetTestCase, self).setUp() self.request = LaunchpadTestRequest() self.vocabulary = SimpleVocabulary([self.SAFE_TERM, self.UNSAFE_TERM]) field = Choice(__name__='test_field', vocabulary=self.vocabulary) self.field = field.bind(object()) self.widget = self.WIDGET_CLASS(self.field, self.vocabulary, self.request)
def setUp(self): super(ItemWidgetTestCase, self).setUp() self.request = LaunchpadTestRequest() self.vocabulary = SimpleVocabulary([self.SAFE_TERM, self.UNSAFE_TERM]) field = Choice(__name__='test_field', vocabulary=self.vocabulary) self.field = field.bind(object()) self.widget = self.WIDGET_CLASS( self.field, self.vocabulary, self.request)
def test_ChoiceInputWidget(self): ztapi.provideMultiView((IChoice, IIterableVocabulary), IBrowserRequest, IInputWidget, '', DropdownWidget) field = Choice(values=[1, 2, 3]) bound = field.bind(object()) widget = ChoiceInputWidget(bound, TestRequest()) self.assert_(isinstance(widget, DropdownWidget)) self.assertEqual(widget.context, bound) self.assertEqual(widget.vocabulary, bound.vocabulary)
def test_ChoiceInputWidget(self): ztapi.provideMultiView((IChoice, IIterableVocabulary), IBrowserRequest, IInputWidget, '', DropdownWidget) field = Choice(values=[1, 2, 3]) bound = field.bind(object()) widget = ChoiceInputWidget(bound, TestRequest()) self.assert_(isinstance(widget, DropdownWidget)) self.assertEqual(widget.context, bound) self.assertEqual(widget.vocabulary, bound.vocabulary)
def test_ChoiceDisplayWidget(self): provideAdapter(ItemDisplayWidget, (IChoice, IIterableVocabulary, IBrowserRequest), IDisplayWidget) field = Choice(values=[1, 2, 3]) bound = field.bind(object()) widget = ChoiceDisplayWidget(bound, TestRequest()) self.assert_(isinstance(widget, ItemDisplayWidget)) self.assertEqual(widget.context, bound) self.assertEqual(widget.vocabulary, bound.vocabulary)
def test_get_widgets_for_schema_fields(self): salutation = Choice(title=u'Salutation', values=("Mr.", "Mrs.", "Captain", "Don")) contactname = TextLine(title=u'Name') request = FakeRequest() salutation = salutation.bind(request) contactname = contactname.bind(request) view1 = getViewProviding(contactname, IInputWidget, request) self.assertEquals(view1.__class__, zope.app.form.browser.textwidgets.TextWidget) view2 = getViewProviding(salutation, IInputWidget, request) self.assertEquals(view2.__class__, zope.app.form.browser.itemswidgets.DropdownWidget)
def test_ChoiceDisplayWidget(self): provideAdapter(ItemDisplayWidget, (IChoice, IIterableVocabulary, IBrowserRequest), IDisplayWidget) field = Choice(values=[1, 2, 3]) bound = field.bind(object()) widget = ChoiceDisplayWidget(bound, TestRequest()) self.assert_(isinstance(widget, ItemDisplayWidget)) self.assertEqual(widget.context, bound) self.assertEqual(widget.vocabulary, bound.vocabulary)
def test_get_widgets_for_schema_fields(self): salutation = Choice(title=u'Salutation', values=("Mr.", "Mrs.", "Captain", "Don")) contactname = TextLine(title=u'Name') request = FakeRequest() salutation = salutation.bind(request) contactname = contactname.bind(request) view1 = getViewProviding(contactname, IInputWidget, request) self.assertEquals(view1.__class__, zope.app.form.browser.textwidgets.TextWidget) view2 = getViewProviding(salutation, IInputWidget, request) self.assertEquals(view2.__class__, zope.app.form.browser.itemswidgets.DropdownWidget)
def test_validate_source(self): s = SampleContextSourceBinder() choice = Choice(source=s) # raises not iterable with unbound field self.assertRaises(TypeError, choice.validate, 1) o = object() clone = choice.bind(o) clone.validate(1) clone.validate(3) self.assertRaises(ConstraintNotSatisfied, clone.validate, 42)
def setUp(self): super(TestSuggestionWidget, self).setUp() request = LaunchpadTestRequest() vocabulary = SimpleHugeVocabulary([self.SAFE_TERM, self.UNSAFE_TERM]) provideUtility(vocabulary, provides=IVocabularyFactory, name='SimpleHugeVocabulary') field = Choice(__name__='test_field', vocabulary="SimpleHugeVocabulary") field = field.bind(object()) self.widget = self.ExampleSuggestionWidget(field, vocabulary, request)
def setUp(self): super(TestSuggestionWidget, self).setUp() request = LaunchpadTestRequest() vocabulary = SimpleHugeVocabulary( [self.SAFE_TERM, self.UNSAFE_TERM]) provideUtility( vocabulary, provides=IVocabularyFactory, name='SimpleHugeVocabulary') field = Choice( __name__='test_field', vocabulary="SimpleHugeVocabulary") field = field.bind(object()) self.widget = self.ExampleSuggestionWidget( field, vocabulary, request)