Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Attributes
Archetypes.tests.test_update_schema.TestUpdateSchema Class Reference
Inheritance diagram for Archetypes.tests.test_update_schema.TestUpdateSchema:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_update_schema.TestUpdateSchema:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def test_instance_schema_is_harmful
def test_no_schema_attribute_added
def test_detect_schema_change
def test_remove_instance_schemas
def test_manage_update_schema
def types_to_update

Public Attributes

 attool

Private Attributes

 _dummy1
 _dummy2

Detailed Description

Definition at line 66 of file test_update_schema.py.


Member Function Documentation

Definition at line 68 of file test_update_schema.py.

00068 
00069     def afterSetUp(self):
00070         ATSiteTestCase.afterSetUp(self)
00071         self.attool = self.portal.archetype_tool
00072         # Calling mkDummyInContext adds content, but also registers
00073         # our classes and adds a copy of the schema.
00074         self._dummy1 = mkDummyInContext(
00075             Dummy1, oid='dummy1', context=self.portal, schema=schema1)
00076         self._dummy2 = mkDummyInContext(
00077             Dummy2, oid='dummy2', context=self.portal, schema=schema2)

Definition at line 163 of file test_update_schema.py.

00163 
00164     def test_detect_schema_change(self):
00165         dummy = self._dummy1
00166         self.failUnless(dummy._isSchemaCurrent())
00167         dummy.__class__.schema = schema2.copy()
00168         # Reregister the type.  (Not needed in AT <= 1.5.1)
00169         registerType(Dummy1, 'Archetypes')
00170         self.failIf(dummy._isSchemaCurrent())
00171         dummy._updateSchema()
00172         self.failUnless(dummy._isSchemaCurrent())

Here is the call graph for this function:

Show that having a schema in the instance is harmful.

schema should be a class attribute, not an instance attribute.

The only thing this really tests is that for AT >= 1.5.2,
having a schema attribute on the instance is bad.  In earlier
ATs this is no problem.  Nothing bad happens due to the
earlier AT code.  But the newer ATs cannot handle older
content that has had a schema update already.

So: if you copy this test to an earlier Archetypes and it
fails, that is okay really.  But in AT >= 1.5.2 it does *not*
fail and this means that some code needs be added to migrate
old content.

Definition at line 78 of file test_update_schema.py.

00078 
00079     def test_instance_schema_is_harmful(self):
00080         """Show that having a schema in the instance is harmful.
00081 
00082         schema should be a class attribute, not an instance attribute.
00083 
00084         The only thing this really tests is that for AT >= 1.5.2,
00085         having a schema attribute on the instance is bad.  In earlier
00086         ATs this is no problem.  Nothing bad happens due to the
00087         earlier AT code.  But the newer ATs cannot handle older
00088         content that has had a schema update already.
00089 
00090         So: if you copy this test to an earlier Archetypes and it
00091         fails, that is okay really.  But in AT >= 1.5.2 it does *not*
00092         fail and this means that some code needs be added to migrate
00093         old content.
00094         """
00095         dummy = self._dummy1
00096         self.failUnless(dummy._isSchemaCurrent())
00097 
00098         # You can make schema an instance attribute if you want (or if
00099         # you are not careful).
00100         self.failIf('schema' in dummy.__dict__)
00101         dummy.schema = dummy.__class__.schema
00102         self.failUnless('schema' in dummy.__dict__)
00103         # The schema has not *really* changed:
00104         self.failUnless(dummy._isSchemaCurrent())
00105         # But the damage has been done, as we will show soon.
00106 
00107         # We give the class of our content a different schema.
00108         dummy.__class__.schema = schema2.copy()
00109         # Reregister the type.  (Not needed in AT <= 1.5.1)
00110         registerType(Dummy1, 'Archetypes')
00111         # We are not testing the _isSchemaCurrent method here, so we
00112         # can simply cheat to let the object know that its schema is
00113         # not current anymore.
00114         dummy._signature = 'bogus'
00115         self.failIf(dummy._isSchemaCurrent())
00116 
00117         # Our class has a TEXTFIELD2, but our content does not now it
00118         # yet.  It *does* already have the getter for that field.
00119         dummy.getTEXTFIELD2
00120         self.assertRaises(KeyError, dummy.getTEXTFIELD2)
00121 
00122         # No problem, we just need to update the schema of the
00123         # content.  Might as well do that for all objects, as that is
00124         # what the user will do in practice.
00125         dummy._updateSchema()
00126 
00127         # And now we can get our second text field, right?  Wrong.
00128         # Only the getter is there and it does not work.
00129         self.failUnless(hasattr(dummy, 'getTEXTFIELD2'))
00130         # Actually, the next two tests fail for AT <= 1.5.1, which is
00131         # actually good.
00132         self.assertRaises(KeyError, dummy.getTEXTFIELD2)
00133         self.failIf(hasattr(dummy, 'TEXTFIELD2'))
00134 
00135         # And the first field was required in the first schema but not
00136         # in the second.  This does not show yet.
00137         self.failUnless(dummy.getField('TEXTFIELD1').required)
00138 
00139         # This can be fixed by deleting the schema attribute of the
00140         # instance.
00141         del dummy.schema
00142         self.failIf(dummy.getField('TEXTFIELD1').required)
00143 
00144         # At first, direct attribute access for the second field still
00145         # does not work:
00146         self.failIf(hasattr(dummy, 'TEXTFIELD2'))
00147         # But calling the getter works.
00148         self.assertEqual(dummy.getTEXTFIELD2(), 'B')
00149         # And after that call, direct attribute access works too.
00150         self.assertEqual(dummy.TEXTFIELD2(), 'B')
00151         # Note: TEXTFIELD is a BaseUnit, which means you need to call
00152         # it to get its value.
        

Here is the call graph for this function:

Definition at line 182 of file test_update_schema.py.

00182 
00183     def test_manage_update_schema(self):
00184         dummy = self._dummy1
00185         dummy.schema = schema2.copy()
00186         self.failUnless('schema' in dummy.__dict__)
00187         self.failIf(dummy._isSchemaCurrent())
00188 
00189         # Now we want to update all schemas, but first archetype_tool
00190         # needs to know that our class needs updating.  The easiest of
00191         # course is to cheat.
00192         self.assertEqual(self.types_to_update(), [])
00193         self.attool._types['Archetypes.Dummy1'] = 'cheat'
00194         self.assertEqual(self.types_to_update(), ['Archetypes.Dummy1'])
00195 
00196         # Now we are ready to call manage_updateSchema
00197         self.attool.manage_updateSchema()
00198         # This will have no effect on the schema attribute:
00199         self.failUnless('schema' in dummy.__dict__)
00200         # It *does* wrongly mark the schema as current.
00201         self.failUnless(dummy._isSchemaCurrent())
00202         # So we cheat again and then it works.
00203         dummy._signature = 'bogus'
00204         self.failIf(dummy._isSchemaCurrent())
00205 
00206         # Let's try again.  But first we cheat again.
00207         self.assertEqual(self.types_to_update(), [])
00208         self.attool._types['Archetypes.Dummy1'] = 'cheat'
00209         self.assertEqual(self.types_to_update(), ['Archetypes.Dummy1'])
00210 
00211         # We need to call manage_updateSchema with an extra option.
00212         self.attool.manage_updateSchema(remove_instance_schemas=True)
00213         self.failIf('schema' in dummy.__dict__)

Here is the call graph for this function:

Does updating the schema mess things up?

Updating the schema should not add the schema as instance
attribute, unless you *really* know what you are doing.

Definition at line 153 of file test_update_schema.py.

00153 
00154     def test_no_schema_attribute_added(self):
00155         """Does updating the schema mess things up?
00156 
00157         Updating the schema should not add the schema as instance
00158         attribute, unless you *really* know what you are doing.
00159         """
00160         dummy = self._dummy1
00161         dummy._updateSchema()
00162         self.failIf('schema' in dummy.__dict__)

Definition at line 173 of file test_update_schema.py.

00173 
00174     def test_remove_instance_schemas(self):
00175         dummy = self._dummy1
00176         dummy.schema = schema2.copy()
00177         self.failUnless('schema' in dummy.__dict__)
00178         dummy._updateSchema()
00179         self.failUnless('schema' in dummy.__dict__)
00180         dummy._updateSchema(remove_instance_schemas=True)
00181         self.failIf('schema' in dummy.__dict__)

Which types have a changed schema?

Definition at line 214 of file test_update_schema.py.

00214 
00215     def types_to_update(self):
00216         """Which types have a changed schema?
00217         """
00218         return [ti[0] for ti in self.attool.getChangedSchema() if ti[1]]

Here is the caller graph for this function:


Member Data Documentation

Definition at line 73 of file test_update_schema.py.

Definition at line 75 of file test_update_schema.py.

Definition at line 70 of file test_update_schema.py.


The documentation for this class was generated from the following file: