def test_setting_valid_uniqueId_returns_content_object(self): context = mock.Mock() context.__name__ = 'foo' source = [self.repository['testcontent']] widget = ObjectSequenceWidget(context, source, request=mock.Mock()) self.assertEqual( (self.repository['testcontent'], ), widget._toFieldValue(['http://xml.zeit.de/testcontent']))
def test_to_form_value_ignores_non_cms_content(self): import zeit.cms.interfaces import zope.interface context = mock.Mock() context.__name__ = 'name' widget = ObjectSequenceWidget(context, mock.Mock(), mock.Mock()) content = mock.Mock() zope.interface.alsoProvides(content, zeit.cms.interfaces.ICMSContent) result = widget._toFormValue([mock.sentinel.foo, content]) self.assertEqual([{'uniqueId': content.uniqueId}], result)
def test_to_form_value_copes_with_none(self): context = mock.Mock() context.__name__ = 'name' widget = ObjectSequenceWidget(context, mock.Mock(), mock.Mock()) self.assertEqual([], widget._toFormValue(None))
def test_invalid_unique_id_fails_validation(self): context = mock.Mock() context.__name__ = 'name' widget = ObjectSequenceWidget(context, mock.Mock(), mock.Mock()) with self.assertRaises(zope.formlib.interfaces.ConversionError): widget._toFieldValue([mock.sentinel.foo, mock.sentinel.bar])