[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_schema.py:1.4
R. David Murray
bitz@bitdance.com
Mon, 27 Jan 2003 21:56:49 -0500
Update of /cvs-repository/Zope3/src/zope/schema/tests
In directory cvs.zope.org:/tmp/cvs-serv8113/zope/schema/tests
Modified Files:
test_schema.py
Log Message:
zope.app.form.utility had a function, fieldNames, that returned a
list of the Fields in a schema in schema order. This is exactly
parallel to getFieldsInOrder from the schema package itself, and
it seems to me that's where it belongs. So I added a getFieldNamesInOrder
function to schema. I also added a getFieldNames in parallel to
getFields, to complete the set. Everything that used fieldNames
is converted to use getFieldNamesInOrder.
The unit tests from form was actually a little stronger than those
in schema: it made sure that all fields were returned when using
a derived schema, which the schema tests didn't. So I added some
subschema tests to the schema test suite in addition to the tests
for the new functions themselves.
=== Zope3/src/zope/schema/tests/test_schema.py 1.3 => 1.4 ===
--- Zope3/src/zope/schema/tests/test_schema.py:1.3 Thu Jan 9 09:13:20 2003
+++ Zope3/src/zope/schema/tests/test_schema.py Mon Jan 27 21:56:46 2003
@@ -20,6 +20,7 @@
from zope.schema import Bytes
from zope.schema.errornames import RequiredMissing
from zope.schema import getFields, getFieldsInOrder
+from zope.schema import getFieldNames, getFieldNamesInOrder
class ISchemaTest(Interface):
title = Bytes(
@@ -40,8 +41,31 @@
default="",
required=True)
+class ISchemaTestSubclass(ISchemaTest):
+ foo = Bytes(
+ title=u'Foo',
+ description=u'Fooness',
+ default="",
+ required=False)
+
+
class SchemaTest(TestCase):
+ def test_getFieldNames(self):
+ names = getFieldNames(ISchemaTest)
+ self.assertEqual(len(names),3)
+ self.assert_('title' in names)
+ self.assert_('description' in names)
+ self.assert_('spam' in names)
+
+ def test_getFieldNamesAll(self):
+ names = getFieldNames(ISchemaTestSubclass)
+ self.assertEqual(len(names),4)
+ self.assert_('title' in names)
+ self.assert_('description' in names)
+ self.assert_('spam' in names)
+ self.assert_('foo' in names)
+
def test_getFields(self):
fields = getFields(ISchemaTest)
@@ -53,12 +77,39 @@
for key, value in fields.iteritems():
self.assertEquals(key, value.getName())
+ def test_getFieldsAll(self):
+ fields = getFields(ISchemaTestSubclass)
+
+ self.assert_(fields.has_key('title'))
+ self.assert_(fields.has_key('description'))
+ self.assert_(fields.has_key('spam'))
+ self.assert_(fields.has_key('foo'))
+
+ # test whether getName() has the right value
+ for key, value in fields.iteritems():
+ self.assertEquals(key, value.getName())
+
def test_getFieldsInOrder(self):
fields = getFieldsInOrder(ISchemaTest)
field_names = [name for name, field in fields]
self.assertEquals(field_names, ['title', 'description', 'spam'])
for key, value in fields:
self.assertEquals(key, value.getName())
+
+ def test_getFieldsInOrderAll(self):
+ fields = getFieldsInOrder(ISchemaTestSubclass)
+ field_names = [name for name, field in fields]
+ self.assertEquals(field_names, ['title', 'description', 'spam', 'foo'])
+ for key, value in fields:
+ self.assertEquals(key, value.getName())
+
+ def test_getFieldsNamesInOrder(self):
+ names = getFieldNamesInOrder(ISchemaTest)
+ self.assertEquals(names, ['title', 'description', 'spam'])
+
+ def test_getFieldsNamesInOrderAll(self):
+ names = getFieldNamesInOrder(ISchemaTestSubclass)
+ self.assertEquals(names, ['title', 'description', 'spam', 'foo'])
def test_suite():
return makeSuite(SchemaTest)