def test_config_view_with_multiple_ios_address(self): """ Create a test IOS router, then add 100 ipv4 and ipv6 addresses, confirm they are in the final template. """ test_router = create_router('ios') 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( 'op_webgui: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, 'ip address 1.1.' + str(i) + '.1 255.255.255.0') self.assertContains(response, 'ipv6 address 2600:' + str(i) + '::1/64')
def test_ipv4_address_create_form_view(self): """ Create a test router and interface, then test the form view of ipv4_address_create is displayed correctly. """ test_router = create_router('junos') test_interface = create_interface(test_router) url = reverse( 'op_webgui:ipv4_address_create', kwargs={'logical_interface_id': test_interface.id}, ) response = self.client.get(url) test_text = 'test-router ge-0/0/0.10 (A logical test description.)' self.assertEqual(response.status_code, 200) self.assertContains(response, test_text)
def test_create_logical_interface_and_view_detail(self): """ Create a logical_interface object, then view the detailed api call. """ test_router = create_router('junos') test_interface = create_interface(test_router) url = reverse( 'api:logical_interfaces_detail', kwargs={'pk': test_interface.pk}, ) response = self.client.get(url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(logical_interface.objects.count(), 1) self.assertEqual(logical_interface.objects.get(name='10'), test_interface)
def test_create_ipv4_address(self): """ Create an ipv4_address object, then view it in the api. """ test_router = create_router('junos') test_interface = create_interface(test_router) data = { "interface": test_interface.pk, "host": '192.0.2.1', "cidr": '24', } url = reverse('api:ipv4_address') response = self.client.post(url, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(ipv4_address.objects.count(), 1) self.assertEqual(str(ipv4_address.objects.get().host), '192.0.2.1')
def test_config_view_with_one_junos_address(self): """ Create a test JunOS router, with one ipv4 and one ipv6 address then check config view. """ test_router = create_router('junos') test_interface = create_interface(test_router) test_v4_address = create_v4_address(test_interface, '1.1.1.1') test_v6_address = create_v6_address(test_interface, '2600::1') url = reverse( 'op_webgui:router_config', kwargs={'router_id': test_router.id}, ) response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, 'address 1.1.1.1/24') self.assertContains(response, 'address 2600::1/64')
def test_create_ipv4_address_and_view_detail(self): """ Create an ipv4_address object, then view the detailed api call. """ test_router = create_router('junos') test_interface = create_interface(test_router) test_address = ipv4_address.objects.create( interface=test_interface, host='192.0.2.1', cidr=24, ) url = reverse( 'api:ipv4_address_detail', kwargs={'pk': test_address.pk}, ) response = self.client.get(url, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(ipv4_address.objects.count(), 1) self.assertEqual(ipv4_address.objects.get(host='192.0.2.1'), test_address)
def test_ipv4_address_edit_form_view(self): """ Create a test router, interface and address, then test the form view of ipv4_address_edit is displayed correctly. """ test_router = create_router('junos') test_interface = create_interface(test_router) test_address = create_v4_address(test_interface, '192.0.2.1') url = reverse( 'op_webgui:ipv4_address_edit', kwargs={'ipv4_address_id': test_address.id}, ) response = self.client.get(url) test_text = ''.join([ '<input type="text" name="host" value="192.0.2.1" ', 'title="" required id="id_host" placeholder="Host" ', 'class="form-control" />', ]) self.assertEqual(response.status_code, 200) self.assertContains(response, test_text)