def test_change_updatable_attrs_after_store(): """Verify that a Sealable node can alter updatable attributes even after storing.""" node = CalculationNode().store() for attr in CalculationNode._updatable_attributes: # pylint: disable=protected-access,not-an-iterable if attr != Sealable.SEALED_KEY: node.set_attribute(attr, 'a')
def test_process_node_updatable_attribute(self): """Check that updatable attributes and only those can be mutated for a stored but unsealed CalculationNode.""" node = CalculationNode() attrs_to_set = { 'bool': self.boolval, 'integer': self.intval, 'float': self.floatval, 'string': self.stringval, 'dict': self.dictval, 'list': self.listval, 'state': self.stateval } for key, value in attrs_to_set.items(): node.set_attribute(key, value) # Check before storing node.set_attribute(CalculationNode.PROCESS_STATE_KEY, self.stateval) self.assertEqual(node.get_attribute(CalculationNode.PROCESS_STATE_KEY), self.stateval) node.store() # Check after storing self.assertEqual(node.get_attribute(CalculationNode.PROCESS_STATE_KEY), self.stateval) # I should be able to mutate the updatable attribute but not the others node.set_attribute(CalculationNode.PROCESS_STATE_KEY, 'FINISHED') node.delete_attribute(CalculationNode.PROCESS_STATE_KEY) # Deleting non-existing attribute should raise attribute error with self.assertRaises(AttributeError): node.delete_attribute(CalculationNode.PROCESS_STATE_KEY) with self.assertRaises(ModificationNotAllowed): node.set_attribute('bool', False) with self.assertRaises(ModificationNotAllowed): node.delete_attribute('bool') node.seal() # After sealing, even updatable attributes should be immutable with self.assertRaises(ModificationNotAllowed): node.set_attribute(CalculationNode.PROCESS_STATE_KEY, 'FINISHED') with self.assertRaises(ModificationNotAllowed): node.delete_attribute(CalculationNode.PROCESS_STATE_KEY)