Beispiel #1
0
 def setUp(self):
     BaseRelationsTestCase.setUp(self)
     # bhrelations point from destination to source
     for destination, source, type in self.edges:
         self.env.db_direct_transaction(
             """INSERT INTO bloodhound_relations (source, destination, type)
                     VALUES ('%s', '%s', '%s')""" %
             (source, destination, type))
     self.validator = Validator(self.env)
Beispiel #2
0
 def setUp(self):
     BaseRelationsTestCase.setUp(self)
     # bhrelations point from destination to source
     for destination, source, type in self.edges:
         self.env.db_direct_transaction(
             """INSERT INTO bloodhound_relations (source, destination, type)
                     VALUES ('%s', '%s', '%s')""" %
             (source, destination, type)
         )
     self.validator = Validator(self.env)
Beispiel #3
0
class GraphFunctionsTestCase(BaseRelationsTestCase):
    edges = [
        ('A', 'B', 'p'),  #      A    H
        ('A', 'C', 'p'),  #     /  \ /
        ('C', 'D', 'p'),  #    B    C
        ('C', 'E', 'p'),  #        /  \
        ('E', 'F', 'p'),  #       D    E - F - G
        ('F', 'G', 'p'),  #
        ('H', 'C', 'p'),
    ]

    def setUp(self):
        BaseRelationsTestCase.setUp(self)
        # bhrelations point from destination to source
        for destination, source, type in self.edges:
            self.env.db_direct_transaction(
                """INSERT INTO bloodhound_relations (source, destination, type)
                        VALUES ('%s', '%s', '%s')""" %
                (source, destination, type))
        self.validator = Validator(self.env)

    def test_find_path(self):
        self.assertEqual(self.validator._find_path(u'A', u'E', u'p'),
                         [u'A', u'C', u'E'])
        self.assertEqual(self.validator._find_path(u'A', u'G', u'p'),
                         [u'A', u'C', u'E', u'F', u'G'])
        self.assertEqual(self.validator._find_path(u'H', u'D', u'p'),
                         [u'H', u'C', u'D'])
        self.assertEqual(self.validator._find_path(u'E', u'A', u'p'), None)
        self.assertEqual(self.validator._find_path(u'B', u'D', u'p'), None)

    def test_descendants(self):
        self.assertEqual(self.validator._descendants(u'B', u'p'), set())
        self.assertEqual(self.validator._descendants(u'E', u'p'),
                         set([u'F', u'G']))
        self.assertEqual(self.validator._descendants(u'H', u'p'),
                         set([u'C', u'D', u'E', u'F', u'G']))

    def test_ancestors(self):
        self.assertEqual(self.validator._ancestors(u'B', u'p'), set([u'A']))
        self.assertEqual(self.validator._ancestors(u'E', u'p'),
                         set([u'A', u'C', u'H']))
        self.assertEqual(self.validator._ancestors(u'H', u'p'), set())
Beispiel #4
0
class GraphFunctionsTestCase(BaseRelationsTestCase):
    edges = [
        ('A', 'B', 'p'),  #      A    H
        ('A', 'C', 'p'),  #     /  \ /
        ('C', 'D', 'p'),  #    B    C
        ('C', 'E', 'p'),  #        /  \
        ('E', 'F', 'p'),  #       D    E - F - G
        ('F', 'G', 'p'),  #
        ('H', 'C', 'p'),
    ]

    def setUp(self):
        BaseRelationsTestCase.setUp(self)
        # bhrelations point from destination to source
        for destination, source, type in self.edges:
            self.env.db_direct_transaction(
                """INSERT INTO bloodhound_relations (source, destination, type)
                        VALUES ('%s', '%s', '%s')""" %
                (source, destination, type)
            )
        self.validator = Validator(self.env)

    def test_find_path(self):
        self.assertEqual(
            self.validator._find_path(u'A', u'E', u'p'),
            [u'A', u'C', u'E'])
        self.assertEqual(
            self.validator._find_path(u'A', u'G', u'p'),
            [u'A', u'C', u'E', u'F', u'G'])
        self.assertEqual(
            self.validator._find_path(u'H', u'D', u'p'),
            [u'H', u'C', u'D'])
        self.assertEqual(
            self.validator._find_path(u'E', u'A', u'p'),
            None)
        self.assertEqual(
            self.validator._find_path(u'B', u'D', u'p'),
            None)

    def test_descendants(self):
        self.assertEqual(
            self.validator._descendants(u'B', u'p'),
            set()
        )
        self.assertEqual(
            self.validator._descendants(u'E', u'p'),
            set([u'F', u'G'])
        )
        self.assertEqual(
            self.validator._descendants(u'H', u'p'),
            set([u'C', u'D', u'E', u'F', u'G'])
        )

    def test_ancestors(self):
        self.assertEqual(
            self.validator._ancestors(u'B', u'p'),
            set([u'A'])
        )
        self.assertEqual(
            self.validator._ancestors(u'E', u'p'),
            set([u'A', u'C', u'H'])
        )
        self.assertEqual(
            self.validator._ancestors(u'H', u'p'),
            set()
        )