Beispiel #1
0
 def test_delete_project(self):
     p = Project(name="Test Project")
     n0 = Node(name="n0", project=p)
     n1 = Node(name="n1", project=p)
     n2 = Node(name="n2", project=p)
     n3 = Node(name="n3")
     db.session.add_all([p, n0, n1, n2, n3])
     n1.add_sink(n0)
     n1.add_source(n2)
     db.session.commit()
     self.assertEqual(p.nodes.all(), [n0, n1, n2])
     p.delete()
     db.session.commit()
     self.assertEqual(Node.query.all(), [n3])
     self.assertEqual(Edge.query.all(), [])
     self.assertEqual(Project.query.all(), [])
Beispiel #2
0
    def test_delete_nodes(self):
        n1 = Node(name="Test Node")
        n2 = Node(name="Test Sink")
        n3 = Node(name="Test Source")

        db.session.add_all([n1, n2, n3])

        n1.add_sink(n2)
        n1.add_source(n3)
        db.session.commit()

        self.assertFalse(Edge.query.all() == [])
        self.assertFalse(Node.query.all() == [])

        n1.delete()
        db.session.commit()
        self.assertEqual(Node.query.all(), [n2, n3])
        self.assertEqual(Edge.query.all(), [])
Beispiel #3
0
    def test_addition_and_removal_of_sinks_and_sources(self):
        # create 4 nodes
        n0 = Node(name="n0")
        n1 = Node(name="n1")
        n2 = Node(name="n2")
        n3 = Node(name='n3')
        db.session.add_all([n0, n1, n2, n3])
        db.session.commit()

        # create the following tree:
        # n2 --> n1 --> n0
        # n3 --> n0

        n1.add_sink(n0)
        n1.add_source(n2)
        n0.add_source(n3)
        db.session.commit()

        self.assertTrue(n1.is_sink_for(n2))
        self.assertTrue(n1.is_source_for(n0))
        self.assertTrue(n2.is_source_for(n1))
        self.assertTrue(n0.is_sink_for(n1))

        self.assertEqual(n0.sinks(), [])
        self.assertEqual(n0.sources(), [n1, n3])
        self.assertEqual(n1.sinks(), [n0])
        self.assertEqual(n1.sources(), [n2])
        self.assertEqual(n2.sinks(), [n1])
        self.assertEqual(n2.sources(), [])
        self.assertEqual(n3.sinks(), [n0])
        self.assertEqual(n3.sources(), [])

        # test if clauses

        e = Edge.query.all()
        n1.add_source(n0)
        n1.add_sink(n2)
        db.session.commit()
        e_test = Edge.query.all()
        self.assertFalse(n2.is_sink_for(n1))
        self.assertEqual(n1.edges_sinks.count(), 1)
        self.assertEqual(n2.edges_sources.count(), 0)
        self.assertEqual(e, e_test)

        # part removal of tree
        n1.remove_sink(n0)
        n1.remove_source(n2)
        db.session.commit()

        self.assertFalse(n1.is_sink_for(n2))
        self.assertFalse(n1.is_source_for(n0))
        self.assertFalse(n2.is_source_for(n1))
        self.assertFalse(n0.is_sink_for(n1))

        self.assertEqual(n0.sinks(), [])
        self.assertEqual(n0.sources(), [n3])
        self.assertEqual(n1.sinks(), [])
        self.assertEqual(n1.sources(), [])
        self.assertEqual(n2.sinks(), [])
        self.assertEqual(n2.sources(), [])
        self.assertEqual(n3.sinks(), [n0])
        self.assertEqual(n3.sources(), [])