Пример #1
0
    def test_replacement_1(self):
        from aiida.backends.djsite.db.models import DbExtra

        n1 = Node().store()
        n2 = Node().store()

        DbExtra.set_value_for_node(n1._dbnode, "pippo", [1, 2, 'a'])
        DbExtra.set_value_for_node(n1._dbnode, "pippobis", [5, 6, 'c'])
        DbExtra.set_value_for_node(n2._dbnode, "pippo2", [3, 4, 'b'])

        self.assertEquals(n1.get_extras(), {'pippo': [1, 2, 'a'],
                                            'pippobis': [5, 6, 'c'],
                                            '_aiida_hash': n1.get_hash()
                                            })
        self.assertEquals(n2.get_extras(), {'pippo2': [3, 4, 'b'],
                                            '_aiida_hash': n2.get_hash()
                                            })

        new_attrs = {"newval1": "v", "newval2": [1, {"c": "d", "e": 2}]}

        DbExtra.reset_values_for_node(n1._dbnode, attributes=new_attrs)
        self.assertEquals(n1.get_extras(), new_attrs)
        self.assertEquals(n2.get_extras(), {'pippo2': [3, 4, 'b'], '_aiida_hash': n2.get_hash()})

        DbExtra.del_value_for_node(n1._dbnode, key='newval2')
        del new_attrs['newval2']
        self.assertEquals(n1.get_extras(), new_attrs)
        # Also check that other nodes were not damaged
        self.assertEquals(n2.get_extras(), {'pippo2': [3, 4, 'b'], '_aiida_hash': n2.get_hash()})
Пример #2
0
 def _del_db_extra(self, key):
     from aiida.backends.djsite.db.models import DbExtra
     if not DbExtra.has_key(self.dbnode, key):
         raise AttributeError("DbExtra {} does not exist".format(
             key))
     return DbExtra.del_value_for_node(self.dbnode, key)
     self._increment_version_number_db()
Пример #3
0
 def del_extra(self, key):
     from aiida.backends.djsite.db.models import DbExtra
     if self._to_be_stored:
         raise ModificationNotAllowed(
             "The extras of a node can be set and deleted "
             "only after storing the node")
     if not DbExtra.has_key(self.dbnode, key):
         raise AttributeError("DbExtra {} does not exist".format(key))
     return DbExtra.del_value_for_node(self.dbnode, key)
     self._increment_version_number_db()