# 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
# 
# def create_interface(test_router):
#     test_interface          = interface.objects.create(router=test_router,
#                                                        name='ge-0/0/0',
#                                                        description="A test description.",
#                                                        mtu=9000,
#                                                        dot1q=True,
#                                                       )
# 
#     test_logical_interface  = logical_interface.objects.create(interface=test_interface,
#                                                                name='10',
#                                                                description="A logical test description.",
#                                                                mtu=4170,
#                                                                vlan=10,
#                                                                physical_interface=False,
#                                                                ldp=True,
#                                                                inet_dhcp_client=False,
#                                                                inet6_dhcp_client=False,
#                                                               )
# 
#     return test_logical_interface
# 
# Path: address/models.py
# class ipv6_address(models.Model):
#     """
#     IPv6 Addresses - 128 bit Internet Protocol Addresses
#     interface:    The logical interface the IP is tied to. (optional)
#     host:         IP Address itself
#                   [2001:db8:1:1::1]
#     cidr:         The CIDR (Classless Inter-Domain Routing)
#                   notation of mask length
#                   [64]
#     Example string: 2001:db8:1:1::1/64
#     """
# 
#     interface    = models.ForeignKey(
#                                      'netdevice.logical_interface',
#                                      on_delete=models.CASCADE,
#                                      null=True,
#                                      blank=True
#                                     )
#     host         = models.GenericIPAddressField(unpack_ipv4=False)
#     cidr         = models.PositiveSmallIntegerField(default=64)
# 
#     def __str__(self):
#         return str(self.host) + "/" + str(self.cidr)
# 
# class ipv4_address(models.Model):
#     """
#     IPv4 Addresses - 32 bit Internet Protocol Addresses
#     interface:      The logical interface the IP is tied to. (optional)
#     host:           IP Address itself
#                     [198.51.100.0]
#     cidr:           The CIDR (Classless Inter-Domain Routing)
#                     notation of mask length
#                     [24]
#     Example string: 198.51.100.0/24
#     """
# 
#     interface    = models.ForeignKey(
#                                      'netdevice.logical_interface',
#                                      on_delete=models.CASCADE,
#                                      null=True,
#                                      blank=True
#                                     )
#     host         = models.GenericIPAddressField(unpack_ipv4=True)
#     cidr         = models.PositiveSmallIntegerField(default=24)
# 
#     def subnet_mask(self):
#         host_bits = 32 - int(self.cidr)
#         bitmask = struct.pack('!I', (1 << 32) - (1 << host_bits))
#         netmask = socket.inet_ntoa(bitmask)
#         return netmask
# 
#     def __str__(self):
#         return str(self.host) + "/" + str(self.cidr)


from django.test import TestCase
from django.urls import reverse
from django.contrib.auth.models import User
from netdevice.tests import create_router, create_interface
from address.models import ipv6_address, ipv4_address
        Create a test IOS router, then add 100 ipv4 and ipv6 addresses,
        confirm they are in the final template.
        """
        test_router     = create_router('junos')
        test_interface  = create_interface(test_router)
        address_count   = 100

        for i in range(1, address_count):
            create_v4_address(test_interface, '1.1.' + str(i) + '.1')
            create_v6_address(test_interface, '2600:' + str(i) + '::1')

        url      = reverse(
                           'netdevice:router_config',
                           kwargs={'router_id': test_router.id},
                          )

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)

        for i in range(1, address_count):
            self.assertContains(response, 'address 1.1.' + str(i) + '.1/24')
            self.assertContains(response, 'address 2600:' + str(i) + '::1/64')

    def test_ipv6_address_create_form_view(self):
        """
        Create a test router and interface, then test the
        form view of ipv6_address_create is displayed correctly.
        """
        test_router    = create_router('junos')

# 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
# 
# def create_interface(test_router):
#     test_interface          = interface.objects.create(router=test_router,
#                                                        name='ge-0/0/0',
#                                                        description="A test description.",
#                                                        mtu=9000,
#                                                        dot1q=True,
#                                                       )
# 
#     test_logical_interface  = logical_interface.objects.create(interface=test_interface,
#                                                                name='10',
#                                                                description="A logical test description.",
#                                                                mtu=4170,
#                                                                vlan=10,
#                                                                physical_interface=False,
#                                                                ldp=True,
#                                                                inet_dhcp_client=False,
#                                                                inet6_dhcp_client=False,
#                                                               )
# 
#     return test_logical_interface
# 
# Path: address/models.py
# class ipv6_address(models.Model):
#     """
#     IPv6 Addresses - 128 bit Internet Protocol Addresses
#     interface:    The logical interface the IP is tied to. (optional)
#     host:         IP Address itself
#                   [2001:db8:1:1::1]
#     cidr:         The CIDR (Classless Inter-Domain Routing)
#                   notation of mask length
#                   [64]
#     Example string: 2001:db8:1:1::1/64
#     """
# 
#     interface    = models.ForeignKey(
#                                      'netdevice.logical_interface',
#                                      on_delete=models.CASCADE,
#                                      null=True,
#                                      blank=True
#                                     )
#     host         = models.GenericIPAddressField(unpack_ipv4=False)
#     cidr         = models.PositiveSmallIntegerField(default=64)
# 
#     def __str__(self):
#         return str(self.host) + "/" + str(self.cidr)
# 
# class ipv4_address(models.Model):
#     """
#     IPv4 Addresses - 32 bit Internet Protocol Addresses
#     interface:      The logical interface the IP is tied to. (optional)
#     host:           IP Address itself
#                     [198.51.100.0]
#     cidr:           The CIDR (Classless Inter-Domain Routing)
#                     notation of mask length
#                     [24]
#     Example string: 198.51.100.0/24
#     """
# 
#     interface    = models.ForeignKey(
#                                      'netdevice.logical_interface',
#                                      on_delete=models.CASCADE,
#                                      null=True,
#                                      blank=True
#                                     )
#     host         = models.GenericIPAddressField(unpack_ipv4=True)
#     cidr         = models.PositiveSmallIntegerField(default=24)
# 
#     def subnet_mask(self):
#         host_bits = 32 - int(self.cidr)
#         bitmask = struct.pack('!I', (1 << 32) - (1 << host_bits))
#         netmask = socket.inet_ntoa(bitmask)
#         return netmask
# 
#     def __str__(self):
#         return str(self.host) + "/" + str(self.cidr)


# Path: address/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, create_interface
from address.models import ipv6_address, ipv4_address

        Create a test IOS router, then add 100 ipv4 and ipv6 addresses,
        confirm they are in the final template.
        """
        test_router     = create_router('junos')
        test_interface  = create_interface(test_router)
        address_count   = 100

        for i in range(1, address_count):
            create_v4_address(test_interface, '1.1.' + str(i) + '.1')
            create_v6_address(test_interface, '2600:' + str(i) + '::1')

        url      = reverse(
                           'netdevice:router_config',
                           kwargs={'router_id': test_router.id},
                          )

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)

        for i in range(1, address_count):
            self.assertContains(response, 'address 1.1.' + str(i) + '.1/24')
            self.assertContains(response, 'address 2600:' + str(i) + '::1/64')

    def test_ipv6_address_create_form_view(self):
        """
        Create a test router and interface, then test the
        form view of ipv6_address_create is displayed correctly.
        """
        test_router    = create_router('junos')

        test_interface = create_interface(test_router)