Back to index

plone3  3.1.7
test_schemata_manipulation.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 """
00026 """
00027 
00028 from Testing import ZopeTestCase
00029 
00030 from Products.Archetypes.tests.attestcase import ATTestCase
00031 
00032 from Products.Archetypes.atapi import *
00033 from Products.Archetypes.Schema import ManagedSchema
00034 
00035 class SchemataManipulationTest( ATTestCase ):
00036 
00037     def afterSetUp(self):
00038         self.schema = ManagedSchema(
00039                (StringField('a', schemata='waldi'),
00040                 StringField('d', schemata='nasbaer'),
00041                 StringField('x', schemata='edgar'),
00042                 StringField('b', schemata='waldi'),
00043                 StringField('e', schemata='nasbaer'),
00044                 StringField('y', schemata='edgar'),
00045                 StringField('c', schemata='waldi'),
00046                 StringField('f', schemata='nasbaer'),
00047                 StringField('z', schemata='edgar')
00048             ))
00049 
00050     def fields2names(self, fields):
00051         return [f.getName() for f in fields]
00052 
00053     def testBasic(self):
00054         self.assertEqual(self.fields2names(self.schema.fields()),
00055                         ['a','d','x', 'b','e','y','c','f','z'])
00056         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar'])
00057         self.schema.addField(StringField('p', schemata='waldi'))
00058         self.schema.addField(StringField('hello_world', schemata='helloworld'))
00059         self.schema.addField(StringField('hello_world1', schemata='helloworld1'))
00060         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar', 'helloworld', 'helloworld1'])
00061 
00062     def testSchemataFields(self):
00063         self.assertEqual(self.fields2names(self.schema.getSchemataFields('waldi')),
00064                         ['a', 'b', 'c'])
00065         self.assertEqual(self.fields2names(self.schema.getSchemataFields('nasbaer')),
00066                         ['d', 'e', 'f'])
00067         self.assertEqual(self.fields2names(self.schema.getSchemataFields('edgar')),
00068                         ['x', 'y', 'z'])
00069     def testDelField(self):
00070         self.schema.delField('x')
00071         self.schema.delField('b')
00072         self.schema.delField('z')
00073         self.assertEqual(self.fields2names(self.schema.fields()),
00074                         ['a','d','e','y','c','f'])
00075         self.schema.addField(StringField('z'))
00076         self.schema.addField(StringField('b'))
00077         self.schema.addField(StringField('x'))
00078         self.assertEqual(self.fields2names(self.schema.fields()),
00079                         ['a','d','e','y','c','f','z','b','x'])
00080         self.schema.delField('b')
00081         self.schema.delField('z')
00082         self.schema.delField('x')
00083         self.assertEqual(self.fields2names(self.schema.fields()),
00084                         ['a','d','e','y','c','f'])
00085 
00086     def testDelSchemata(self):
00087         self.schema.delSchemata('nasbaer')
00088         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'edgar'])
00089         self.schema.addField(StringField('hello_world', schemata='helloworld'))
00090         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'edgar', 'helloworld'])
00091 
00092     def testAddSchemata(self):
00093         self.schema.addSchemata('otto')
00094         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar', 'otto'])
00095         self.assertEqual(len(self.schema.getSchemataFields('otto')), 1)
00096 
00097     def testFieldChangeSchemata(self):
00098         self.schema.changeSchemataForField('z','otto')
00099         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar', 'otto'])
00100         self.assertEqual(self.fields2names(self.schema.getSchemataFields('otto')), ['z'])
00101         self.schema.changeSchemataForField('z','waldi')
00102         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar'])
00103 
00104     def testMoveSchemata1(self):
00105         self.schema.moveSchemata('waldi', -1)
00106         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar'])
00107         self.schema.moveSchemata('waldi', 1)
00108         self.assertEqual(self.schema.getSchemataNames(), ['nasbaer', 'waldi', 'edgar'])
00109         self.schema.moveSchemata('waldi', 1)
00110         self.assertEqual(self.schema.getSchemataNames(), ['nasbaer', 'edgar', 'waldi'])
00111         self.schema.moveSchemata('waldi', 1)
00112         self.assertEqual(self.schema.getSchemataNames(), ['nasbaer', 'edgar', 'waldi'])
00113 
00114     def testMoveSchemata2(self):
00115         self.schema.moveSchemata('edgar', 1)
00116         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'nasbaer', 'edgar'])
00117         self.schema.moveSchemata('edgar', -1)
00118         self.assertEqual(self.schema.getSchemataNames(), ['waldi', 'edgar', 'nasbaer'])
00119         self.schema.moveSchemata('edgar', -1)
00120         self.assertEqual(self.schema.getSchemataNames(), ['edgar', 'waldi', 'nasbaer'])
00121         self.schema.moveSchemata('edgar', -1)
00122         self.assertEqual(self.schema.getSchemataNames(), ['edgar', 'waldi', 'nasbaer'])
00123 
00124     def testMoveField(self):
00125         self.assertEqual(self.fields2names(self.schema.getSchemataFields('waldi')), ['a','b','c'])
00126         self.schema.moveField('a', -1)
00127         self.assertEqual(self.fields2names(self.schema.getSchemataFields('waldi')), ['a','b','c'])
00128         self.schema.moveField('a', 1)
00129         self.assertEqual(self.fields2names(self.schema.getSchemataFields('waldi')), ['b','a','c'])
00130         self.schema.moveField('a', 1)
00131         self.assertEqual(self.fields2names(self.schema.getSchemataFields('waldi')), ['b','c','a'])
00132 
00133     def testReplaceField(self):
00134         f1 = StringField('f1')
00135         f2 = StringField('f2')
00136         f3 = StringField('f3')
00137         self.schema.replaceField('a', f1)
00138         self.schema.replaceField('e', f2)
00139         self.schema.replaceField('z', f3)
00140         self.assertEqual(self.fields2names(self.schema.fields()),
00141                         ['f1','d','x', 'b','f2','y','c','f','f3'])
00142 
00143 
00144 def test_suite():
00145     from unittest import TestSuite, makeSuite
00146     suite = TestSuite()
00147     suite.addTest(makeSuite(SchemataManipulationTest))
00148     return suite