Ejemplo n.º 1
0
    def test_can_create_before_and_after_delete_events_custom(self):
        mapper = Mapper(TC)

        class MyNode4(Node):
            pass

        class MyNodeMapper4(EntityMapper):
            entity = MyNode4

            def on_before_delete(self, entity):
                self.before_delete = self.deleted_before

            def on_after_delete(self, entity, response, **kwargs):
                self.after_delete = self.deleted_after

        mn = mapper.create(entity=MyNode4, id=999)
        my_mapper = mapper.get_mapper(mn)
        my_mapper.after_delete = 'AFTERDELETE'
        my_mapper.before_delete = 'BEFOEREDELETE'
        my_mapper.deleted_before = 'UDPATED{}'.format(random())
        my_mapper.deleted_after = 'UDPATED{}'.format(random())
        work = mapper.delete(mn)
        query = work.queries()
        work.send()

        self.assertEqual(my_mapper.after_delete, my_mapper.deleted_after)
        self.assertEqual(my_mapper.before_delete, my_mapper.deleted_before)
        self.assertEqual(1, len(query))
        self.assertIn('MATCH', query[0][0])
Ejemplo n.º 2
0
class MapperDeleteTests(unittest.TestCase):

    def setUp(self):
        self.mapper = Mapper(TC)

    def test_can_delete_single_node(self):
        _id = 999
        n = Node(id=_id)
        work = self.mapper.delete(n)
        query = work.queries()

        self.assertEqual(1, len(query))
        self.assertEqual(1, len(query[0][1]))
        self.assertTrue('DETACH DELETE' in query[0][0])

    def test_can_delete_multiple_nodes(self):
        _id = 999
        n = Node(id=_id)
        _id2 = 9998
        n2 = Node(id=_id2)
        work = self.mapper.delete(n)
        self.mapper.delete(n2, work=work)
        query = work.queries()

        self.assertEqual(2, len(query))
        self.assertEqual(1, len(query[0][1]))
        self.assertEqual(1, len(query[1][1]))

        for q in query:
            self.assertTrue('DETACH DELETE' in q[0])

    def test_can_delete_single_relationship(self):
        _id = 999
        n = Node(id=_id)
        _id2 = 999
        n2 = Node(id=_id2)
        _id3 = 8989
        rel = Relationship(start=n, end=n2, id=_id3)
        work = self.mapper.delete(rel)
        query = work.queries()

        self.assertEqual(1, len(query))
        self.assertEqual(1, len(query[0][1]))
        self.assertTrue('DELETE' in query[0][0])

    def test_can_delete_multiple_relationships(self):
        _id = 999
        n = Node(id=_id)
        _id2 = 999
        n2 = Node(id=_id2)
        _id3 = 8989
        rel = Relationship(start=n, end=n2, id=_id3)

        _iid = 134
        nn = Node(id=_iid)
        _id22 = 323
        nn2 = Node(id=_id22)
        _id4 = 9991
        rel2 = Relationship(start=nn, end=nn2, id=_id4)
        work = self.mapper.delete(rel)
        work.delete(rel2)
        query = work.queries()

        self.assertEqual(2, len(query))
        self.assertEqual(1, len(query[0][1]))
        self.assertEqual(1, len(query[1][1]))

        for q in query:
            self.assertTrue('DELETE' in q[0])