[Zope3-checkins] CVS: Zope3/src/zope/app/utilities/tests - test_schemautilitypersistence.py:1.1.2.1

Sidnei da Silva sidnei at x3ng.com.br
Thu Sep 25 14:21:39 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/utilities/tests
In directory cvs.zope.org:/tmp/cvs-serv1531/src/zope/app/utilities/tests

Added Files:
      Tag: schema_utility_persistence
	test_schemautilitypersistence.py 
Log Message:
Adding a test that shows how schema utility persistence is behaving badly

=== Added File Zope3/src/zope/app/utilities/tests/test_schemautilitypersistence.py ===


import unittest
from persistence.tests.test_persistence import PersistentTest, DM
from zope.app.utilities.schema import SchemaUtility
from zope.schema import Text, getFieldsInOrder
from zope.app.tests import setup

class PSchema(SchemaUtility):

    def __init__(self):
        super(PSchema, self).__init__()
        self.x = 0
        self.setName('PSchema')

    def inc(self):
        self.x += 1

class PersistentSchemaUtilityTest(PersistentTest):
    klass = PSchema

    def setUp(self):
        PersistentTest.setUp(self)
        setup.placefulSetUp(self)

    def testState(self):
        pass

    def testAddField(self):
        f = Text(title=u'alpha')
        p = self.klass()
        p._p_oid = '\0\0\0\0\0\0hi'
        dm = DM()
        p._p_jar = dm
        self.assertEqual(p._p_changed, 0)
        self.assertEqual(dm.called, 0)
        p.addField('alpha', f)
        self.assertEqual(p._p_changed, 1)
        self.assertEqual(dm.called, 1)

    def testRemoveField(self):
        f = Text(title=u'alpha')
        p = self.klass()
        p._p_oid = '\0\0\0\0\0\0hi'
        dm = DM()
        p._p_jar = dm
        self.assertEqual(p._p_changed, 0)
        self.assertEqual(dm.called, 0)
        p.addField('alpha', f)
        self.assertEqual(p._p_changed, 1)
        self.assertEqual(dm.called, 1)
        p._p_changed = 0
        self.assertEqual(p._p_changed, 0)
        self.assertEqual(dm.called, 1)
        p.removeField('alpha')
        self.assertEqual(p._p_changed, 1)
        self.assertEqual(dm.called, 2)

    def tearDown(self):
        PersistentTest.tearDown(self)
        setup.placefulTearDown()

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(PersistentSchemaUtilityTest))
    return suite

if __name__ == '__main__':
    unittest.main()




More information about the Zope3-Checkins mailing list