Пример #1
0
    def test_validate_incoming_sealed(self):
        """Verify that trying to add a link to a sealed node will raise."""
        data = Int(1).store()
        node = CalculationNode().store()
        node.seal()

        with self.assertRaises(exceptions.ModificationNotAllowed):
            node.validate_incoming(data,
                                   link_type=LinkType.INPUT_CALC,
                                   link_label='input')
Пример #2
0
    def test_validate_outgoing_sealed(self):
        """Verify that trying to add a link from a sealed node will raise."""
        data = Int(1).store()
        node = CalculationNode().store()
        node.seal()

        with self.assertRaises(exceptions.ModificationNotAllowed):
            node.validate_outgoing(data,
                                   link_type=LinkType.CREATE,
                                   link_label='create')
Пример #3
0
    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)