# Path: netdevice/tests.py
# def create_router(network_os_name):
#     nos               = network_os.objects.get(name=network_os_name)
#     local_aut_num     = aut_num.objects.create(asn=65000, name='Test ASN')
#     test_router       = router.objects.create(routing_id='1.1.1.1',
#                                               hostname='test-router',
#                                               ibgp=True,
#                                               network_os=nos,
#                                               local_aut_num=local_aut_num,
#                                              )
# 
#     return test_router
# 
# Path: static/models.py
# class ipv6_static(models.Model):
#     """
#     IPv6 Static Routes - Routes set by the user in a given router.
# 
#     router:       The router to place this static route.
#     network:      The network address of the route.                                    [2001:db8::]
#     cidr:         The CIDR length of this static route.                                [64]
#     next-hop:     Next-hop device of this static route.                                [2001:db8:1:1::1]
# 
#     Example string: Router1 2001:db8:: next-hop 2001:db8:1:1::1
#     """
# 
#     router      = models.ForeignKey('netdevice.router', on_delete=models.CASCADE, null=True, blank=True)
#     vrf         = models.ForeignKey(
#                                     'netdevice.vrf',
#                                     on_delete=models.CASCADE,
#                                     null=True,
#                                     blank=True
#                                    )
#     network     = models.GenericIPAddressField(unpack_ipv4=False)
#     cidr        = models.PositiveSmallIntegerField(default=64)
#     next_hop    = models.GenericIPAddressField(unpack_ipv4=True)
# 
#     def __str__(self):
#         return self.router.hostname + " " + str(self.network) + "/" + str(self.cidr) + " next-hop " + str(self.next_hop)
# 
# class ipv4_static(models.Model):
#     """
#     IPv4 Static Routes - Routes set by the user in a given router
# 
#     router:       The router to place this static route.
#     network:      The network address of the route.                                    [198.51.100.0]
#     cidr:         The CIDR length of this static route.                                [24]
#     next-hop:     Next-hop device of this static route.                                [198.51.100.1]
# 
#     Example string: Router1 198.51.100.0/24 next-hop 198.51.100.1
#     """
# 
#     router      = models.ForeignKey('netdevice.router', on_delete=models.CASCADE, null=True, blank=True)
#     vrf         = models.ForeignKey(
#                                     'netdevice.vrf',
#                                     on_delete=models.CASCADE,
#                                     null=True,
#                                     blank=True
#                                    )
#     network     = models.GenericIPAddressField(unpack_ipv4=True)
#     cidr        = models.PositiveSmallIntegerField(default=24)
#     next_hop    = models.GenericIPAddressField(unpack_ipv4=True)
# 
#     def subnet_mask(self):
#         host_bits = 32 - int(self.cidr)
#         netmask = socket.inet_ntoa(struct.pack('!I', (1 << 32) - (1 << host_bits)))
#         return netmask
# 
#     def __str__(self):
#         return self.router.hostname + " " + str(self.network) + "/" + str(self.cidr) + " next-hop " + str(self.next_hop)


from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User
from netdevice.tests import create_router
from static.models import ipv6_static, ipv4_static

        self.assertEqual(response.status_code, 200)

        for i in range(1, route_count):
            self.assertContains(response, 'ip route 10.' + str(i) + '.0.0 255.255.0.0 172.16.0.1')
            self.assertContains(response, 'ipv6 route 2001:db8:' + str(i) + '::/48 2001:db8::1')

    def test_config_view_with_multiple_junos_static_route(self):
        """
        Create 100 static routes, and ensure they are templated properly.
        """
        test_router       = create_router('junos')
        route_count       = 100

        for i in range(1, route_count):
            create_v4_static(test_router, '10.' + str(i) + '.0.0')
            create_v6_static(test_router, '2001:db8:' + str(i) + '::')

        response         = self.client.get(reverse('netdevice:router_config', kwargs={'router_id': test_router.id}))

        self.assertEqual(response.status_code, 200)

        for i in range(1, route_count):
            self.assertContains(response, 'route 10.' + str(i) + '.0.0/16 next-hop 172.16.0.1')
            self.assertContains(response, 'route 2001:db8:' + str(i) + '::/48 next-hop 2001:db8::1')

    def test_create_ipv6_static_route_form_view(self):
        """
        Create a router, then test that the create a static route page view is displayed correctly.
        """

# Path: netdevice/tests.py
# def create_router(network_os_name):
#     nos               = network_os.objects.get(name=network_os_name)
#     local_aut_num     = aut_num.objects.create(asn=65000, name='Test ASN')
#     test_router       = router.objects.create(routing_id='1.1.1.1',
#                                               hostname='test-router',
#                                               ibgp=True,
#                                               network_os=nos,
#                                               local_aut_num=local_aut_num,
#                                              )
# 
#     return test_router
# 
# Path: static/models.py
# class ipv6_static(models.Model):
#     """
#     IPv6 Static Routes - Routes set by the user in a given router.
# 
#     router:       The router to place this static route.
#     network:      The network address of the route.                                    [2001:db8::]
#     cidr:         The CIDR length of this static route.                                [64]
#     next-hop:     Next-hop device of this static route.                                [2001:db8:1:1::1]
# 
#     Example string: Router1 2001:db8:: next-hop 2001:db8:1:1::1
#     """
# 
#     router      = models.ForeignKey('netdevice.router', on_delete=models.CASCADE, null=True, blank=True)
#     vrf         = models.ForeignKey(
#                                     'netdevice.vrf',
#                                     on_delete=models.CASCADE,
#                                     null=True,
#                                     blank=True
#                                    )
#     network     = models.GenericIPAddressField(unpack_ipv4=False)
#     cidr        = models.PositiveSmallIntegerField(default=64)
#     next_hop    = models.GenericIPAddressField(unpack_ipv4=True)
# 
#     def __str__(self):
#         return self.router.hostname + " " + str(self.network) + "/" + str(self.cidr) + " next-hop " + str(self.next_hop)
# 
# class ipv4_static(models.Model):
#     """
#     IPv4 Static Routes - Routes set by the user in a given router
# 
#     router:       The router to place this static route.
#     network:      The network address of the route.                                    [198.51.100.0]
#     cidr:         The CIDR length of this static route.                                [24]
#     next-hop:     Next-hop device of this static route.                                [198.51.100.1]
# 
#     Example string: Router1 198.51.100.0/24 next-hop 198.51.100.1
#     """
# 
#     router      = models.ForeignKey('netdevice.router', on_delete=models.CASCADE, null=True, blank=True)
#     vrf         = models.ForeignKey(
#                                     'netdevice.vrf',
#                                     on_delete=models.CASCADE,
#                                     null=True,
#                                     blank=True
#                                    )
#     network     = models.GenericIPAddressField(unpack_ipv4=True)
#     cidr        = models.PositiveSmallIntegerField(default=24)
#     next_hop    = models.GenericIPAddressField(unpack_ipv4=True)
# 
#     def subnet_mask(self):
#         host_bits = 32 - int(self.cidr)
#         netmask = socket.inet_ntoa(struct.pack('!I', (1 << 32) - (1 << host_bits)))
#         return netmask
# 
#     def __str__(self):
#         return self.router.hostname + " " + str(self.network) + "/" + str(self.cidr) + " next-hop " + str(self.next_hop)


# Path: static/tests.py
from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User
from netdevice.tests import create_router
from static.models import ipv6_static, ipv4_static


        self.assertEqual(response.status_code, 200)

        for i in range(1, route_count):
            self.assertContains(response, 'ip route 10.' + str(i) + '.0.0 255.255.0.0 172.16.0.1')
            self.assertContains(response, 'ipv6 route 2001:db8:' + str(i) + '::/48 2001:db8::1')

    def test_config_view_with_multiple_junos_static_route(self):
        """
        Create 100 static routes, and ensure they are templated properly.
        """
        test_router       = create_router('junos')
        route_count       = 100

        for i in range(1, route_count):
            create_v4_static(test_router, '10.' + str(i) + '.0.0')
            create_v6_static(test_router, '2001:db8:' + str(i) + '::')

        response         = self.client.get(reverse('netdevice:router_config', kwargs={'router_id': test_router.id}))

        self.assertEqual(response.status_code, 200)

        for i in range(1, route_count):
            self.assertContains(response, 'route 10.' + str(i) + '.0.0/16 next-hop 172.16.0.1')
            self.assertContains(response, 'route 2001:db8:' + str(i) + '::/48 next-hop 2001:db8::1')

    def test_create_ipv6_static_route_form_view(self):
        """
        Create a router, then test that the create a static route page view is displayed correctly.
        """

        test_router        = create_router('junos')