def test_versioning_and_postsave_attributes(self): """ Checks the versioning. """ from aiida.orm.test import myNodeWithFields # Has 'state' as updatable attribute a = myNodeWithFields() attrs_to_set = { 'bool': self.boolval, 'integer': self.intval, 'float': self.floatval, 'string': self.stringval, 'dict': self.dictval, 'list': self.listval, 'state': 267, } for k, v in attrs_to_set.iteritems(): a._set_attr(k, v) # Check before storing self.assertEquals(267, a.get_attr('state')) a.store() # Check after storing self.assertEquals(267, a.get_attr('state')) # Even if I stored many attributes, this should stay at 1 self.assertEquals(a.dbnode.nodeversion, 1) # I check increment on new version a.set_extra('a', 'b') self.assertEquals(a.dbnode.nodeversion, 2) # I check that I can set this attribute a._set_attr('state', 999) # I check increment on new version self.assertEquals(a.dbnode.nodeversion, 3) with self.assertRaises(ModificationNotAllowed): # I check that I cannot modify this attribute a._set_attr('otherattribute', 222) # I check that the counter was not incremented self.assertEquals(a.dbnode.nodeversion, 3) # In both cases, the node version must increase a.label = 'test' self.assertEquals(a.dbnode.nodeversion, 4) a.description = 'test description' self.assertEquals(a.dbnode.nodeversion, 5) b = a.copy() # updatable attributes are not copied with self.assertRaises(AttributeError): b.get_attr('state')
def test_versioning_lowlevel(self): """ Checks the versioning. """ from aiida.orm.test import myNodeWithFields a = myNodeWithFields() a.store() # Even if I stored many attributes, this should stay at 1 self.assertEquals(a._dbnode.nodeversion, 1) self.assertEquals(a.dbnode.nodeversion, 1) self.assertEquals(a._dbnode.nodeversion, 1) a.label = "label1" a.label = "label2" self.assertEquals(a._dbnode.nodeversion, 3) self.assertEquals(a.dbnode.nodeversion, 3) self.assertEquals(a._dbnode.nodeversion, 3) a.description = "desc1" a.description = "desc2" a.description = "desc3" self.assertEquals(a._dbnode.nodeversion, 6) self.assertEquals(a.dbnode.nodeversion, 6) self.assertEquals(a._dbnode.nodeversion, 6)
def test_updatable_not_copied(self): """ Checks the versioning. """ from aiida.orm.test import myNodeWithFields # Has 'state' as updatable attribute a = myNodeWithFields() a._set_attr('state', 267) a.store() b = a.copy() # updatable attributes are not copied with self.assertRaises(AttributeError): b.get_attr('state')
def test_delete_updatable_attributes(self): """ Checks the versioning. """ from aiida.orm.test import myNodeWithFields # Has 'state' as updatable attribute a = myNodeWithFields() attrs_to_set = { 'bool': self.boolval, 'integer': self.intval, 'float': self.floatval, 'string': self.stringval, 'dict': self.dictval, 'list': self.listval, 'state': 267, # updatable } for k, v in attrs_to_set.iteritems(): a._set_attr(k, v) # Check before storing self.assertEquals(267, a.get_attr('state')) a.store() # Check after storing self.assertEquals(267, a.get_attr('state')) # Even if I stored many attributes, this should stay at 1 self.assertEquals(a.dbnode.nodeversion, 1) # I should be able to delete the attribute a._del_attr('state') # I check increment on new version self.assertEquals(a.dbnode.nodeversion, 2) with self.assertRaises(AttributeError): # I check that I cannot modify this attribute _ = a.get_attr('state')