Ejemplo n.º 1
0
    def test_add_host(self):

        hive = Hive(self.host, self.db)

        for x in right_host:
            self.assertEqual(hive.add_host(x), True, x)

        for y in wrong_host:
            self.assertEqual(hive.add_host(y), False, y)
Ejemplo n.º 2
0
    def test_add_network(self):
        hive = Hive(self.host, self.db)

        # Must catch ValueError bacause each net has a wrong format
        for y in wrong_network:
            self.assertRaises(ValueError, hive.add_network, y)

        # Must return True because these net's formats are valid.
        for x in right_network:
            self.assertEqual(hive.add_network(x), True)
Ejemplo n.º 3
0
    def test_is_supernet(self):

        hive = Hive(self.host, self.db)

        # First we need to add these networks to hive
        self.assertEqual(hive.add_network(subnet), True)
        self.assertEqual(hive.add_network(supernet), True)

        # Set supernet to net
        self.assertEqual(hive.set_supernet(subnet, supernet), True)

        # Must be False
        self.assertEqual(is_supernet(subnet, omeganet), False)

        # Must be True
        self.assertEqual(is_supernet(subnet, supernet), True)
Ejemplo n.º 4
0
    def test_add_child_to_net(self):
        hive = Hive(self.host, self.db)

        net = "10.0.0.0/24"

        subnet1 = "10.0.0.0/25"
        subnet2 = "10.0.0.128/25"

        # Must be failed because net is not added yet
        self.assertRaises(ValueError, hive.add_child_to_net, net, subnet1)
        self.assertRaises(ValueError, hive.add_child_to_net, net, subnet2)

        # Create set of NetworkEntry before addition a net child to it
        self.assertEqual(hive.add_network(net), True)
        self.assertEqual(hive.add_network(subnet1), True)
        self.assertEqual(hive.add_network(subnet2), True)

        # Must be true
        self.assertEqual(hive.add_child_to_net(net, subnet1), True)
        self.assertEqual(hive.add_child_to_net(net, subnet2), True)
Ejemplo n.º 5
0
    def test_set_supernet(self):
        hive = Hive(self.host, self.db)

        # Must be false, because these news are not added yet
        self.assertEqual(hive.set_supernet(subnet, supernet), False)

        # First we need to add these networks to hive
        self.assertEqual(hive.add_network(subnet), True)
        self.assertEqual(hive.add_network(supernet), True)

        # Then set_supernet
        hive.set_supernet(subnet, supernet)

        # Check if a supernet is a parent for subnet
        self.assertEqual(hive.get_supernet(subnet), supernet)
Ejemplo n.º 6
0
    def test_get_children(self):
        hive = Hive(self.host)
        self.assertEqual(hive.add_network(subnet), True)
        self.assertEqual(hive.add_network(supernet), True)

        # Add subnet to supernet as a child
        self.assertEqual(hive.add_child_to_net(supernet, subnet), True)

        # Check if a subnet is a child of a supernet
        self.assertEqual(subnet in hive.get_children(supernet), True)
Ejemplo n.º 7
0
    def test_is_added(self):

        hive = Hive(self.host, self.db)

        # Must be False
        for net in right_network:
            self.assertEqual(hive.is_added(net), False)

        # Then add these networks to the hive
        for net in right_network:
            hive.add_network(net)

        # Must be True
        for net in right_network:
            self.assertEqual(hive.is_added(net), True)
Ejemplo n.º 8
0
from models import Hive

if __name__ == '__main__':

    net1 = "192.168.23.0/24"
    net2 = "192.168.24.0/24"

    host1 = "192.168.23.25"

    hive = Hive('192.168.149.138')

    # Must be TRUE
    print(hive.add_network(net1))
    # FALSE
    print(hive.add_host(net2))

    # FALSE
    print(hive.add_network(host1))
    # TRUE
    print(hive.add_host(host1))