Back to index

plone3  3.1.7
test_varschema.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 from Products.Archetypes.tests.attestcase import ATTestCase
00027 from Products.Archetypes.atapi import *
00028 from Products.Archetypes.config import PKG_NAME
00029 from Products.Archetypes.VariableSchemaSupport import VariableSchemaSupport
00030 
00031 schema = BaseSchema
00032 schema1= BaseSchema + Schema((StringField('additionalField'),))
00033 
00034 class Dummy(VariableSchemaSupport,BaseContent):
00035     schema = schema
00036 
00037 
00038 class VarSchemataTest( ATTestCase ):
00039 
00040     def afterSetUp(self):
00041         registerType(Dummy, 'Archetypes')
00042         content_types, constructors, ftis = process_types(listTypes(), PKG_NAME)
00043 
00044     def test_variableschema(self):        
00045         self.folder.dummy = Dummy(oid='dummy')
00046         dummy = self.folder.dummy
00047         dummy.setTitle('dummy1')
00048         self.assertEqual(dummy.Title(),'dummy1')
00049 
00050         #change the schema
00051         dummy.schema=schema1
00052         #try to read an old value using the new schema
00053         self.assertEqual(dummy.Title(),'dummy1')
00054         dummy.setAdditionalField('flurb')
00055         #check if we can read the new field using the new schema
00056         self.assertEqual(dummy.getAdditionalField(),'flurb')
00057 
00058 
00059 def test_suite():
00060     from unittest import TestSuite, makeSuite
00061     suite = TestSuite()
00062     suite.addTest(makeSuite(VarSchemataTest))
00063     return suite