[Checkins] SVN: grok/trunk/src/grok/tests/form/schemainherit.py Add a (passing) test for schema inheritance.

Martijn Faassen faassen at infrae.com
Thu Dec 14 16:06:08 EST 2006


Log message for revision 71551:
  Add a (passing) test for schema inheritance.
  

Changed:
  A   grok/trunk/src/grok/tests/form/schemainherit.py

-=-
Added: grok/trunk/src/grok/tests/form/schemainherit.py
===================================================================
--- grok/trunk/src/grok/tests/form/schemainherit.py	2006-12-14 19:48:27 UTC (rev 71550)
+++ grok/trunk/src/grok/tests/form/schemainherit.py	2006-12-14 21:06:07 UTC (rev 71551)
@@ -0,0 +1,30 @@
+"""
+A grok.Model may implement a schema that inherits from another one:
+
+  >>> grok.grok(__name__)
+  >>> manfred = Mammoth()
+
+  >>> from zope import component
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> view = component.getMultiAdapter((manfred, request), name='edit')
+  >>> len(view.form.form_fields)
+  3
+  >>> [w.__name__ for w in view.form.form_fields]
+  ['name', 'size', 'speciality']
+"""
+import grok
+from zope import interface, schema
+
+class IMammoth(interface.Interface):
+    name = schema.TextLine(title=u"Name")
+    size = schema.TextLine(title=u"Size", default=u"Quite normal")
+
+class ISpecialMammoth(IMammoth):
+    speciality = schema.TextLine(title=u"Speciality")
+
+class Mammoth(grok.Model):
+    interface.implements(ISpecialMammoth)
+
+class Edit(grok.EditForm):
+    grok.context(Mammoth)



More information about the Checkins mailing list