def test_try_create_ip_associating_to_equipment_and_virtual_interface(self): """V4 Tests if NAPI can allocate two IPv4 Addresses manually and associate it to equipments and for the first equipment associate it also to Virtual Interface in a Network with available addresses. """ name_file = 'api_ip/v4/tests/sanity/ipv4/json/post/' \ 'ipv4_with_two_equipments_and_virtual_interface.json' response = self.client.post( '/api/v4/ipv4/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(201, response.status_code) url = prepare_url('/api/v4/ipv4/%s/' % response.data[0]['id'], include=['equipments']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) name_file = 'api_ip/v4/tests/sanity/ipv4/json/get/' \ 'ipv4_created_with_eqpts_and_virtual_interface.json' del response.data['ips'][0]['id'] self.compare_json(name_file, response.data)
def test_get_two_basic_as_by_search(self): """Success Test of GET two basic AS.""" name_file = json_path % 'get/basic/pk_1;2.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'asnequipment__equipment__in': [1, 2, 3, 4], }] } get_url = prepare_url('/api/v4/as/', search=search, kind=['basic'], exclude=['equipments']) # Make a GET request response = self.client.get(get_url, HTTP_AUTHORIZATION=self.authorization) self.compare_status(200, response.status_code) self.compare_json_lists(name_file, response.data['asns'])
def test_try_create_ip_associating_to_equipment(self): """V4 Tests if NAPI can allocate an IPv6 Address manually and associate it to an equipment in a Network with available addresses. """ name_file = 'api_ip/v4/tests/sanity/ipv6/json/post/' \ 'ipv6_new_ip_manual_net_5.json' response = self.client.post( '/api/v4/ipv6/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(201, response.status_code) url = prepare_url('/api/v4/ipv6/%s/' % response.data[0]['id'], fields=['ip_formated']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values('fc00:0000:0000:0004:0000:0000:0000:0099', response.data['ips'][0]['ip_formated'])
def test_try_update_ip_changing_octets(self): """Tests if NAPI deny or ignore update of IPv6 Address changing its octets.""" name_file = 'api_ip/tests/sanity/ipv6/json/put/ipv6_put_1_change_block_net_5.json' response = self.client.put( '/api/v3/ipv6/1/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v3/ipv6/1/', fields=['id', 'ip_formated']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values('fc00:0000:0000:0004:0000:0000:0000:0001', response.data['ips'][0]['ip_formated'])
def test_get_two_basic_neighbor_by_search(self): """Success Test of GET two basic Neighbor by search.""" name_file = json_path % 'get/basic/pk_1;2.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'virtual_interface__id__in': [1], }] } get_url = prepare_url('/api/v4/neighbor/', search=search) # Make a GET request response = self.client.get( get_url, HTTP_AUTHORIZATION=self.authorization ) self.compare_status(200, response.status_code) response.data['neighbors'].sort(key=operator.itemgetter('id')) self.compare_json_lists(name_file, response.data['neighbors'])
def test_try_get_non_existent_ipv4_by_search(self): """V4 Tests if NAPI returns a dict with zero IPv4 Addresses given a search by not existent IPv4 Address. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 200 }] } url = prepare_url('/api/v4/ipv4/', search=search) response = self.client.get(url, content_type='application/json', HTTP_AUTHORIZATION=self.authorization) self.compare_status(200, response.status_code) self.compare_values(0, response.data['total'])
def test_get_netipv4_by_search_using_details_kind(self): """Test of success to get a Network IPv4 by search using details kind.""" name_file = self.json_path % 'get/details/pk_1.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'oct1': 10, 'oct2': 10, 'oct3': 0, 'oct4': 0 }] } get_url = prepare_url('/api/v3/networkv4/', search=search, kind=['details']) # Make a GET request response = self.client.get(get_url, HTTP_AUTHORIZATION=self.authorization) self.compare_status(200, response.status_code) self.compare_json_lists(name_file, response.data['networks'])
def test_try_update_ip_disassociating_it_of_some_equipments(self): """V4 Tests if NAPI can update IPv4 disassociating it of equipment and at same time associating it to other equipment. """ name_file = 'api_ip/tests/sanity/ipv4/json/put/ipv4_put_2_net_5_eqpt_2.json' response = self.client.put( '/api/v4/ipv4/2/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v4/ipv4/2/', fields=['id', 'equipments']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) name_file = 'api_ip/v4/tests/sanity/ipv4/json/get/ipv4_put_2_net_5_eqpt_2.json' for ip in response.data['ips']: for equipment in ip['equipments']: del equipment['id'] self.compare_json(name_file, response.data)
def test_get_one_virtual_interface_by_search(self): """Success Test of GET basic Virtual Interface by search.""" name_file = json_path % 'get/basic/pk_1.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'ipequipamento__equipamento__in': [1, 2], }] } get_url = prepare_url('/api/v4/virtual-interface/', search=search, kind=['basic']) # Make a GET request response = self.client.get(get_url, HTTP_AUTHORIZATION=self.authorization) self.compare_status(200, response.status_code) self.compare_json_lists(name_file, response.data['virtual_interfaces'])
def test_try_get_non_existent_ipv6_by_search(self): """V4 Tests if NAPI returns a dict with zero IPv6 Addresses given a search by not existent IPv6 Address. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'block1': 'fc00', 'block2': '0000', 'block3': '0000', 'block4': '0004', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0200' }] } url = prepare_url('/api/v4/ipv6/', search=search) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(0, response.data['total'])
def test_get_netipv6_by_search_using_basic_kind(self): """Test of success to get a Network IPv6 by search using basic kind.""" name_file = self.json_path % 'get/basic/pk_1.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [ { 'block1': 'fc00', 'block2': '0000', 'block3': '0000', 'block4': '0000', 'vlan': 1 } ] } get_url = prepare_url('/api/v3/networkv6/', search=search, kind=['basic']) # Make a GET request response = self.client.get( get_url, HTTP_AUTHORIZATION=self.authorization ) self.compare_status(200, response.status_code) self.compare_json_lists(name_file, response.data['networks'])
def test_try_create_auto_ip(self): """V4 Tests if NAPI can allocate automatically an IPv6 Address in a Network with available addresses. """ name_file = 'api_ip/tests/sanity/ipv6/json/post/ipv6_auto_net_free.json' # Does get request response = self.client.post( '/api/v4/ipv6/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(201, response.status_code) url = prepare_url('/api/v4/ipv6/%s/' % response.data[0]['id'], fields=['ip_formated']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values( 'fc00:0000:0000:0004:0000:0000:0000:0004', response.data['ips'][0]['ip_formated'])
def test_get_two_netipv4_by_search_using_details_kind(self): """Test of success to get two Network IPv4 by search using details kind.""" name_file = self.json_path % 'get/details/pk_1;2.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'broadcast': '10.10.0.255' }, { 'broadcast': '10.10.1.127' }] } get_url = prepare_url('/api/v3/networkv4/', search=search, kind=['details']) # Make a GET request response = self.client.get( get_url, HTTP_AUTHORIZATION=self.authorization ) self.compare_status(200, response.status_code) self.compare_json_lists(name_file, response.data['networks'])
def test_try_update_ip_associating_to_equipment(self): """V4 Tests if NAPI can update IPv4 associating it to equipment.""" name_file = 'api_ip/v4/tests/sanity/ipv4/json/put/ipv4_put_1_net_5_eqpt_1.json' response = self.client.put( '/api/v4/ipv4/1/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v4/ipv4/1/', fields=['id', 'equipments']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) del response.data['ips'][0]['equipments'][0]['virtual_interface'] eqpt_id = response.data['ips'][0]['equipments'][0]['equipment'] response.data['ips'][0]['equipments'][0]['equipment'] = \ {'id': eqpt_id} self.compare_json(name_file, response.data)
def test_try_get_one_existent_ipv4_by_search(self): """Tests if NAPI returns a dict with one IPv4 Addresses given a search one existing IPv4 Addresses. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 1 }] } fields = ['ip_formated'] url = prepare_url('/api/v3/ipv4/', search=search, fields=fields) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(1, response.data['total']) self.assertIn({'ip_formated': '10.0.0.1'}, response.data['ips'])
def test_get_two_netipv4_by_search_using_basic_kind(self): """Test of success to get two Network IPv4 by search using basic kind.""" name_file = self.json_path % 'get/basic/pk_1;2.json' search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'broadcast': '10.10.0.255' }, { 'broadcast': '10.10.1.127' }] } get_url = prepare_url('/api/v3/networkv4/', search=search, kind=['basic']) # Make a GET request response = self.client.get(get_url, HTTP_AUTHORIZATION=self.authorization) self.compare_status(200, response.status_code) self.compare_json_lists(name_file, response.data['networks'])
def test_try_create_auto_ip(self): """V4 Tests if NAPI can allocate automatically an IPv4 Address in a Network with available addresses. """ name_file = 'api_ip/tests/sanity/ipv4/json/post/ipv4_auto_net_free.json' # Does get request response = self.client.post( '/api/v4/ipv4/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(201, response.status_code) url = prepare_url('/api/v4/ipv4/%s/' % response.data[0]['id'], fields=['ip_formated']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values('10.0.1.2', response.data['ips'][0]['ip_formated'])
def test_try_update_ip_change_associations_to_eqpts_and_virt_interfaces( self): """V4 Tests if NAPI can update IPv4 changing existing associations to Equipments and Virtual Interfaces. """ name_file = 'api_ip/v4/tests/sanity/ipv4/json/put/' \ 'ipv4_put_2_net_5_two_eqpts_and_virt_interface.json' response = self.client.put( '/api/v4/ipv4/2/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v4/ipv4/2/', include=['equipments']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) name_file = 'api_ip/v4/tests/sanity/ipv4/json/get/' \ 'ipv4_updated_with_eqpts_and_virtual_interface.json' self.compare_json(name_file, response.data)
def test_try_get_one_existent_ipv4_by_search(self): """V4 Tests if NAPI returns a dict with one IPv4 Addresses given a search one existing IPv4 Addresses. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 1 }] } fields = ['ip_formated'] url = prepare_url('/api/v4/ipv4/', search=search, fields=fields) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(1, response.data['total']) self.assertIn({'ip_formated': '10.0.0.1'}, response.data['ips'])
def test_try_get_non_existent_ipv4_by_search(self): """V4 Tests if NAPI returns a dict with zero IPv4 Addresses given a search by not existent IPv4 Address. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 200 }] } url = prepare_url('/api/v4/ipv4/', search=search) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(0, response.data['total'])
def test_try_update_ip_disassociating_it_of_all_equipments(self): """V4 Tests if NAPI can update IPv6 disassociating it of equipment and keep this IPv6. """ name_file = 'api_ip/v4/tests/sanity/ipv6/json/put/' \ 'ipv6_put_2_net_5_eqpt_none.json' response = self.client.put( '/api/v4/ipv6/2/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v4/ipv6/2/', fields=['id', 'equipments']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code)
def create_netv4_with_octs(self): """Creates networks v4 using first vlan.""" networks = [{ 'oct1': 10, 'oct2': 0, 'oct3': 1, 'oct4': 0, 'prefix': 24, 'env': 3 }, { 'oct1': 10, 'oct2': 0, 'oct3': 2, 'oct4': 0, 'prefix': 25, 'env': 3 }, { 'oct1': 10, 'oct2': 0, 'oct3': 3, 'oct4': 0, 'prefix': 24, 'env': 3 }] fields = ['oct1', 'oct2', 'oct3', 'oct4', 'prefix', 'vlan'] for network_send in networks: # Get all vlans of environment ids_vlans = self.search_all_vlans([network_send.get('env')]) del network_send['env'] # Creates networks v4 network_send['vlan'] = ids_vlans[0] network = [{ 'oct1': network_send.get('oct1'), 'oct2': network_send.get('oct2'), 'oct3': network_send.get('oct3'), 'oct4': network_send.get('oct4'), 'prefix': network_send.get('prefix'), 'vlan': network_send.get('vlan'), 'network_type': 3, 'environmentvip': None }] id_network = self.create_networkv4s(network)[0]['id'] # Get object created url = '/api/v3/networkv4/%s/' % id_network url = prepare_url(url, fields=fields) response = self.client.get(url, HTTP_AUTHORIZATION=self.authorization) # Verify if object is right self.compare_values( json.dumps(network_send, sort_keys=True), json.dumps(response.data['networks'][0], sort_keys=True))
def test_try_get_two_existent_ipv6_by_search(self): """Tests if NAPI returns a dict with two IPv6 Addresses given a search making OR by two IPv6 Addresses. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'block1': 'fc00', 'block2': '0000', 'block3': '0000', 'block4': '0004', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0001' }, { 'block1': 'fc00', 'block2': '0000', 'block3': '0000', 'block4': '0004', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0002' }] } fields = ['ip_formated'] url = prepare_url('/api/v3/ipv6/', search=search, fields=fields) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(2, response.data['total']) self.assertIn( {'ip_formated': 'fc00:0000:0000:0004:0000:0000:0000:0001'}, response.data['ips']) self.assertIn( {'ip_formated': 'fc00:0000:0000:0004:0000:0000:0000:0002'}, response.data['ips'])
def test_try_get_two_existent_ipv6_by_search(self): """V4 Tests if NAPI returns a dict with two IPv6 Addresses given a search making OR by two IPv6 Addresses. """ search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'block1': 'fc00', 'block2': '0000', 'block3': '0000', 'block4': '0004', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0001' }, { 'block1': 'fc00', 'block2': '0000', 'block3': '0000', 'block4': '0004', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0002' }] } fields = ['ip_formated'] url = prepare_url('/api/v4/ipv6/', search=search, fields=fields) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(2, response.data['total']) self.assertIn( {'ip_formated': 'fc00:0000:0000:0004:0000:0000:0000:0001'}, response.data['ips']) self.assertIn( {'ip_formated': 'fc00:0000:0000:0004:0000:0000:0000:0002'}, response.data['ips'])
def test_get_inexistent_netipv4_by_search(self): """Test of error to get a inexistent Network IPv4 by search.""" search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'broadcast': '172.0.200.255' }] } get_url = prepare_url('/api/v3/networkv4/', search=search) # Make a GET request response = self.client.get(get_url, HTTP_AUTHORIZATION=self.authorization) self.compare_status(200, response.status_code) self.compare_values(0, response.data['total'])
def search_all_vlans(self, ids_env): search_vlan = { 'start_record': 0, 'end_record': 100, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'ambiente': id_env } for id_env in ids_env] } url = '/api/v3/vlan/' response = self.client.get(prepare_url(url, search=search_vlan, fields=['id']), HTTP_AUTHORIZATION=self.authorization) vlans = response.data['vlans'] ids_vlans = [id_vlan['id'] for id_vlan in vlans] return ids_vlans
def search_all_vlans(self, ids_env): search_vlan = { 'start_record': 0, 'end_record': 100, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [ {'ambiente': id_env} for id_env in ids_env ] } url = '/api/v3/vlan/' response = self.client.get( prepare_url(url, search=search_vlan, fields=['id']), HTTP_AUTHORIZATION=self.authorization ) vlans = response.data['vlans'] ids_vlans = [id_vlan['id'] for id_vlan in vlans] return ids_vlans
def test_get_non_existent_netipv6_by_search(self): """Test of error to get a non existent Network IPv6 by search.""" search = { 'start_record': 0, 'end_record': 25, 'asorting_cols': [], 'searchable_columns': [], 'extends_search': [{ 'block1': 'ffff' }] } get_url = prepare_url('/api/v3/networkv6/', search=search) # Make a GET request response = self.client.get( get_url, HTTP_AUTHORIZATION=self.authorization ) self.compare_status(200, response.status_code) self.compare_values(0, response.data['total'])
def test_try_create_ip_associating_to_equipment(self): """Tests if NAPI can allocate an IPv4 Address manually and associate it to an equipment in a Network with available addresses. """ name_file = 'api_ip/tests/sanity/ipv4/json/post/ipv4_10_0_0_99_net_5_eqpt_1.json' response = self.client.post( '/api/v3/ipv4/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(201, response.status_code) url = prepare_url('/api/v3/ipv4/%s/' % response.data[0]['id'], fields=['ip_formated']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values('10.0.0.99', response.data['ips'][0]['ip_formated'])
def test_try_update_ip_changing_network(self): """V4 Tests if NAPI deny or ignore update of IPv4 Address changing its network.""" name_file = 'api_ip/tests/sanity/ipv4/json/put/ipv4_put_1_net_6.json' response = self.client.put( '/api/v4/ipv4/1/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v4/ipv4/1/', fields=['id', 'networkipv4']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code) self.compare_values(5, response.data['ips'][0]['networkipv4'])
def test_try_update_ip_disassociating_it_of_all_equipments(self): """Tests if NAPI can update IPv4 disassociating it of equipment and keep this IPv4. """ name_file = 'api_ip/tests/sanity/ipv4/json/put/ipv4_put_2_net_5_eqpt_none.json' response = self.client.put( '/api/v3/ipv4/2/', data=json.dumps(self.load_json_file(name_file)), content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) # API will return success but network will not be changed self.compare_status(200, response.status_code) # Does get request url = prepare_url('/api/v3/ipv4/2/', fields=['id', 'equipments']) response = self.client.get( url, content_type='application/json', HTTP_AUTHORIZATION=self.get_http_authorization('test')) self.compare_status(200, response.status_code)
def create_netv6_with_octs(self): """Creates networks v6 using first vlan.""" networks = [{ 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1201', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000', 'env': 3 }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1202', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000', 'env': 3 }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1203', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000', 'env': 3 }] fields = [ 'block1', 'block2', 'block3', 'block4', 'block5', 'block6', 'block7', 'block8', 'prefix', 'mask1', 'mask2', 'mask3', 'mask4', 'mask5', 'mask6', 'mask7', 'mask8', 'vlan' ] for network_send in networks: # Get all vlans of environment ids_vlans = self.search_all_vlans([network_send.get('env')]) del network_send['env'] # Creates networks v4 network_send['vlan'] = ids_vlans[0] network = [{ 'block1': network_send.get('block1'), 'block2': network_send.get('block2'), 'block3': network_send.get('block3'), 'block4': network_send.get('block4'), 'block5': network_send.get('block5'), 'block6': network_send.get('block6'), 'block7': network_send.get('block7'), 'block8': network_send.get('block8'), 'prefix': network_send.get('prefix'), 'vlan': network_send.get('vlan'), 'network_type': 3, 'environmentvip': None }] id_network = self.create_networkv6s(network)[0]['id'] # Get object created url = '/api/v3/networkv6/%s/' % id_network url = prepare_url(url, fields=fields) response = self.client.get( url, HTTP_AUTHORIZATION=self.authorization ) # Verify if object is right self.compare_values( json.dumps(network_send, sort_keys=True), json.dumps(response.data['networks'][0], sort_keys=True) )
def create_netv6_with_octs(self): """Creates networks v6 using first vlan.""" networks = [{ 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1201', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000', 'env': 3 }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1202', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000', 'env': 3 }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1203', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000', 'env': 3 }] fields = [ 'block1', 'block2', 'block3', 'block4', 'block5', 'block6', 'block7', 'block8', 'prefix', 'mask1', 'mask2', 'mask3', 'mask4', 'mask5', 'mask6', 'mask7', 'mask8', 'vlan' ] for network_send in networks: # Get all vlans of environment ids_vlans = self.search_all_vlans([network_send.get('env')]) del network_send['env'] # Creates networks v4 network_send['vlan'] = ids_vlans[0] network = [{ 'block1': network_send.get('block1'), 'block2': network_send.get('block2'), 'block3': network_send.get('block3'), 'block4': network_send.get('block4'), 'block5': network_send.get('block5'), 'block6': network_send.get('block6'), 'block7': network_send.get('block7'), 'block8': network_send.get('block8'), 'prefix': network_send.get('prefix'), 'vlan': network_send.get('vlan'), 'network_type': 3, 'environmentvip': None }] id_network = self.create_networkv6s(network)[0]['id'] # Get object created url = '/api/v3/networkv6/%s/' % id_network url = prepare_url(url, fields=fields) response = self.client.get(url, HTTP_AUTHORIZATION=self.authorization) # Verify if object is right self.compare_values( json.dumps(network_send, sort_keys=True), json.dumps(response.data['networks'][0], sort_keys=True))
def create_netv4_without_octs(self): networks = [{ 'prefix': None, 'env': 3, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 4, 'network_type': 3, 'environmentvip': None }, { 'prefix': 24, 'env': 4, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 3, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 5, 'network_type': 3, 'environmentvip': None }] expected_networks = [{ 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 0, 'prefix': 24, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 0, }, { 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 0, 'prefix': 25, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 128, }, { 'oct1': 10, 'oct2': 0, 'oct3': 1, 'oct4': 0, 'prefix': 24, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 0, }, { 'oct1': 10, 'oct2': 0, 'oct3': 2, 'oct4': 128, 'prefix': 25, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 128 }, { 'oct1': 10, 'oct2': 0, 'oct3': 4, 'oct4': 0, 'prefix': 25, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 128 }, { 'oct1': 10, 'oct2': 0, 'oct3': 5, 'oct4': 0, 'prefix': 24, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 0 }, { 'oct1': 10, 'oct2': 0, 'oct3': 4, 'oct4': 128, 'prefix': 25, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 128 }, { 'oct1': 10, 'oct2': 0, 'oct3': 0, 'oct4': 0, 'prefix': 24, 'mask_oct1': 255, 'mask_oct2': 255, 'mask_oct3': 255, 'mask_oct4': 0 }] fields = [ 'oct1', 'oct2', 'oct3', 'oct4', 'prefix', 'mask_oct1', 'mask_oct2', 'mask_oct3', 'mask_oct4', 'vlan', ] for network_send, expected_network in izip(networks, expected_networks): # Get all vlans of environment ids_vlans = self.search_all_vlans([network_send.get('env')]) # Creates networks v4 network_send['vlan'] = ids_vlans[0] expected_network['vlan'] = ids_vlans[0] id_network = self.create_networkv4s([network_send])[0]['id'] # Get object created url = '/api/v3/networkv4/%s/' % id_network url = prepare_url(url, fields=fields) response = self.client.get(url, HTTP_AUTHORIZATION=self.authorization) # Verify if object is right self.compare_values( json.dumps(expected_network, sort_keys=True), json.dumps(response.data['networks'][0], sort_keys=True))
def create_netv6_without_octs(self): networks = [{ 'prefix': None, 'env': 3, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 4, 'network_type': 3, 'environmentvip': None }, { 'prefix': 64, 'env': 4, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 3, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 5, 'network_type': 3, 'environmentvip': None }] expected_networks = [{ 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1200', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1200', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1201', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1202', 'block5': '8000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1204', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1205', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1204', 'block5': '8000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1200', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }] fields = [ 'block1', 'block2', 'block3', 'block4', 'block5', 'block6', 'block7', 'block8', 'prefix', 'mask1', 'mask2', 'mask3', 'mask4', 'mask5', 'mask6', 'mask7', 'mask8', 'vlan', ] for network_send, expected_network in izip(networks, expected_networks): # Get all vlans of environment ids_vlans = self.search_all_vlans([network_send.get('env')]) # Creates networks v4 network_send['vlan'] = ids_vlans[0] expected_network['vlan'] = ids_vlans[0] id_network = self.create_networkv6s([network_send])[0]['id'] # Get object created url = '/api/v3/networkv6/%s/' % id_network url = prepare_url(url, fields=fields) response = self.client.get(url, HTTP_AUTHORIZATION=self.authorization) # Verify if object is right self.compare_values( json.dumps(expected_network, sort_keys=True), json.dumps(response.data['networks'][0], sort_keys=True))
def create_netv6_without_octs(self): networks = [ { 'prefix': None, 'env': 3, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 4, 'network_type': 3, 'environmentvip': None }, { 'prefix': 64, 'env': 4, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 3, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 2, 'network_type': 3, 'environmentvip': None }, { 'prefix': None, 'env': 5, 'network_type': 3, 'environmentvip': None } ] expected_networks = [{ 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1200', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1200', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1201', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1202', 'block5': '8000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1204', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1205', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1204', 'block5': '8000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 65, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '8000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }, { 'block1': 'fdbe', 'block2': 'bebe', 'block3': 'bebe', 'block4': '1200', 'block5': '0000', 'block6': '0000', 'block7': '0000', 'block8': '0000', 'prefix': 64, 'mask1': 'ffff', 'mask2': 'ffff', 'mask3': 'ffff', 'mask4': 'ffff', 'mask5': '0000', 'mask6': '0000', 'mask7': '0000', 'mask8': '0000' }] fields = [ 'block1', 'block2', 'block3', 'block4', 'block5', 'block6', 'block7', 'block8', 'prefix', 'mask1', 'mask2', 'mask3', 'mask4', 'mask5', 'mask6', 'mask7', 'mask8', 'vlan', ] for network_send, expected_network in izip(networks, expected_networks): # Get all vlans of environment ids_vlans = self.search_all_vlans([network_send.get('env')]) # Creates networks v4 network_send['vlan'] = ids_vlans[0] expected_network['vlan'] = ids_vlans[0] id_network = self.create_networkv6s([network_send])[0]['id'] # Get object created url = '/api/v3/networkv6/%s/' % id_network url = prepare_url(url, fields=fields) response = self.client.get( url, HTTP_AUTHORIZATION=self.authorization ) # Verify if object is right self.compare_values( json.dumps(expected_network, sort_keys=True), json.dumps(response.data['networks'][0], sort_keys=True) )