<s> from __future__ import unicode_literals <EOL> import pytest <EOL> pytestmark = pytest . mark . django_db <EOL> import copy <EOL> from django . core . urlresolvers import reverse <EOL> import json <EOL> import logging <EOL> from rest_framework import status <EOL> from . fixtures import live_server , client , user , site <EOL> from . util import ( <EOL> assert_created , assert_error , assert_success , assert_deleted , load_json , <EOL> Client , load , filter_networks , mkcidr , get_result <EOL> ) <EOL> log = logging . getLogger ( __name__ ) <EOL> def test_creation ( live_server , user , site ) : <EOL> """<STR_LIT>""" <EOL> admin_client = Client ( live_server , '<STR_LIT>' ) <EOL> user_client = Client ( live_server , '<STR_LIT:user>' ) <EOL> cidr = '<STR_LIT>' <EOL> site_uri = site . list_uri ( ) <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> admin_client . create ( attr_uri , resource_name = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> assert_error ( <EOL> user_client . create ( <EOL> net_uri , cidr = cidr , attributes = { '<STR_LIT>' : '<STR_LIT:foo>' } <EOL> ) , <EOL> status . HTTP_403_FORBIDDEN <EOL> ) <EOL> assert_error ( <EOL> admin_client . create ( net_uri , attributes = { '<STR_LIT>' : '<STR_LIT:foo>' } ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> assert_error ( <EOL> admin_client . create ( net_uri , cidr = None ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> net_resp = admin_client . create ( <EOL> net_uri , cidr = cidr , attributes = { '<STR_LIT>' : '<STR_LIT:foo>' } , <EOL> state = '<STR_LIT>' , <EOL> ) <EOL> net = get_result ( net_resp ) <EOL> net_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net [ '<STR_LIT:id>' ] ) <EOL> assert_created ( net_resp , net_obj_uri ) <EOL> payload = get_result ( net_resp ) <EOL> expected = [ payload ] <EOL> assert_success ( admin_client . get ( net_uri ) , expected ) <EOL> assert_success ( admin_client . get ( net_obj_uri ) , net ) <EOL> net_natural_uri = site . detail_uri ( '<STR_LIT>' , id = cidr ) <EOL> assert_success ( admin_client . get ( net_natural_uri ) , net ) <EOL> params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:16> } <EOL> net2_resp = admin_client . create ( net_uri , ** params ) <EOL> net2 = get_result ( net2_resp ) <EOL> net2_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net2 [ '<STR_LIT:id>' ] ) <EOL> assert_created ( net2_resp , net2_obj_uri ) <EOL> assert_deleted ( admin_client . delete ( net2_obj_uri ) ) <EOL> net2a_resp = admin_client . create ( net_uri , ** params ) <EOL> net2a = get_result ( net2a_resp ) <EOL> net2a_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net2a [ '<STR_LIT:id>' ] ) <EOL> assert_created ( net2a_resp , net2a_obj_uri ) <EOL> def test_bulk_operations ( site , client ) : <EOL> """<STR_LIT>""" <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> collection = [ <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , <EOL> ] <EOL> collection_response = client . post ( <EOL> net_uri , <EOL> data = json . dumps ( collection ) <EOL> ) <EOL> assert_created ( collection_response , None ) <EOL> output = collection_response . json ( ) <EOL> payload = get_result ( output ) <EOL> assert_success ( client . get ( net_uri ) , payload ) <EOL> client . create ( attr_uri , resource_name = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> updated = copy . deepcopy ( payload ) <EOL> for item in updated : <EOL> item [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT>' } <EOL> updated_resp = client . put ( net_uri , data = json . dumps ( updated ) ) <EOL> expected = updated_resp . json ( ) <EOL> assert updated == expected <EOL> def test_filters ( site , client ) : <EOL> """<STR_LIT>""" <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> client . post ( attr_uri , data = load ( '<STR_LIT>' ) ) <EOL> client . post ( net_uri , data = load ( '<STR_LIT>' ) ) <EOL> net_resp = client . retrieve ( net_uri ) <EOL> networks = get_result ( net_resp ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , cidr = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , attributes = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , attributes = [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , network_address = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , prefix_length = <NUM_LIT:16> ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , network_address = '<STR_LIT>' , prefix_length = <NUM_LIT:8> ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , include_ips = True , include_networks = False ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , include_ips = False , include_networks = True ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , include_ips = True , include_networks = True ) , <EOL> expected <EOL> ) <EOL> wanted = [ ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( net_uri , include_ips = False , include_networks = False ) , <EOL> expected <EOL> ) <EOL> ipv6_resp = client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> ipv6 = get_result ( ipv6_resp ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = [ ipv6 ] <EOL> assert_success ( <EOL> client . retrieve ( net_uri , ip_version = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> def test_set_queries ( client , site ) : <EOL> """<STR_LIT>""" <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> query_uri = site . query_uri ( '<STR_LIT>' ) <EOL> client . post ( attr_uri , data = load ( '<STR_LIT>' ) ) <EOL> client . post ( net_uri , data = load ( '<STR_LIT>' ) ) <EOL> net_resp = client . retrieve ( net_uri ) <EOL> networks = get_result ( net_resp ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( query_uri , query = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( query_uri , query = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( query_uri , query = '<STR_LIT>' , include_ips = False ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( query_uri , query = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> wanted = [ '<STR_LIT>' ] <EOL> expected = filter_networks ( networks , wanted ) <EOL> assert_success ( <EOL> client . retrieve ( query_uri , query = '<STR_LIT>' ) , <EOL> expected <EOL> ) <EOL> assert_error ( <EOL> client . retrieve ( query_uri , query = '<STR_LIT>' ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> def test_update ( live_server , user , site ) : <EOL> """<STR_LIT>""" <EOL> admin_client = Client ( live_server , '<STR_LIT>' ) <EOL> user_client = Client ( live_server , '<STR_LIT:user>' ) <EOL> cidr = '<STR_LIT>' <EOL> site_uri = site . list_uri ( ) <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> admin_client . create ( attr_uri , resource_name = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> net_resp = admin_client . create ( <EOL> net_uri , cidr = cidr , attributes = { '<STR_LIT>' : '<STR_LIT:foo>' } , <EOL> state = '<STR_LIT>' <EOL> ) <EOL> net = get_result ( net_resp ) <EOL> net_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net [ '<STR_LIT:id>' ] ) <EOL> params = { '<STR_LIT>' : { } , '<STR_LIT:state>' : '<STR_LIT>' } <EOL> net . update ( params ) <EOL> assert_success ( <EOL> admin_client . update ( net_obj_uri , ** params ) , <EOL> net <EOL> ) <EOL> params [ '<STR_LIT>' ] = { '<STR_LIT>' : '<STR_LIT:foo>' } <EOL> net . update ( params ) <EOL> assert_success ( <EOL> admin_client . update ( net_obj_uri , ** params ) , <EOL> net <EOL> ) <EOL> assert_error ( user_client . update ( net_obj_uri ) , status . HTTP_403_FORBIDDEN ) <EOL> params = { '<STR_LIT>' : { } , '<STR_LIT:state>' : '<STR_LIT>' } <EOL> net . update ( params ) <EOL> net_natural_uri = site . detail_uri ( '<STR_LIT>' , id = cidr ) <EOL> assert_success ( <EOL> admin_client . update ( net_natural_uri , ** params ) , <EOL> net <EOL> ) <EOL> def test_partial_update ( site , client ) : <EOL> """<STR_LIT>""" <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> cidr = '<STR_LIT>' <EOL> client . create ( attr_uri , resource_name = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> net_resp = client . create ( <EOL> net_uri , cidr = cidr , attributes = { '<STR_LIT>' : '<STR_LIT:foo>' } <EOL> ) <EOL> net = get_result ( net_resp ) <EOL> net_pk_uri = site . detail_uri ( '<STR_LIT>' , id = net [ '<STR_LIT:id>' ] ) <EOL> net_natural_uri = site . detail_uri ( '<STR_LIT>' , id = cidr ) <EOL> params = { '<STR_LIT:state>' : '<STR_LIT>' } <EOL> net . update ( params ) <EOL> assert_success ( <EOL> client . partial_update ( net_pk_uri , ** params ) , <EOL> net <EOL> ) <EOL> assert_error ( <EOL> client . update ( net_pk_uri , ** params ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> def test_deletion ( site , client ) : <EOL> """<STR_LIT>""" <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> attr_uri = site . list_uri ( '<STR_LIT>' ) <EOL> net1_resp = client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> net1 = get_result ( net1_resp ) <EOL> net1_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net1 [ '<STR_LIT:id>' ] ) <EOL> net2_resp = client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> net2 = get_result ( net2_resp ) <EOL> net2_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net2 [ '<STR_LIT:id>' ] ) <EOL> assert_error ( client . delete ( net1_obj_uri ) , status . HTTP_409_CONFLICT ) <EOL> client . delete ( net2_obj_uri ) <EOL> assert_deleted ( client . delete ( net1_obj_uri ) ) <EOL> net3_resp = client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> net3 = get_result ( net3_resp ) <EOL> net3_natural_uri = site . detail_uri ( '<STR_LIT>' , id = mkcidr ( net3 ) ) <EOL> assert_deleted ( client . delete ( net3_natural_uri ) ) <EOL> def test_mptt_detail_routes ( site , client ) : <EOL> """<STR_LIT>""" <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_8_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_8 = get_result ( net_8_resp ) [ <NUM_LIT:0> ] <EOL> net_8_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net_8 [ '<STR_LIT:id>' ] ) <EOL> net_12_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_12 = get_result ( net_12_resp ) [ <NUM_LIT:0> ] <EOL> net_12_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net_12 [ '<STR_LIT:id>' ] ) <EOL> net_14_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_14 = get_result ( net_14_resp ) [ <NUM_LIT:0> ] <EOL> net_14_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net_14 [ '<STR_LIT:id>' ] ) <EOL> net_25_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_25 = get_result ( net_25_resp ) [ <NUM_LIT:0> ] <EOL> net_25_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net_25 [ '<STR_LIT:id>' ] ) <EOL> ip1_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> ip1 = get_result ( ip1_resp ) [ <NUM_LIT:0> ] <EOL> ip1_obj_uri = site . detail_uri ( '<STR_LIT>' , id = ip1 [ '<STR_LIT:id>' ] ) <EOL> ip2_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> ip2 = get_result ( ip2_resp ) [ <NUM_LIT:0> ] <EOL> ip2_obj_uri = site . detail_uri ( '<STR_LIT>' , id = ip2 [ '<STR_LIT:id>' ] ) <EOL> expected = [ net_8 , net_12 , net_14 ] <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_25 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( net_25 ) ) ) <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> expected = [ net_14 , net_12 , net_8 ] <EOL> assert_success ( client . retrieve ( uri , ascending = True ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri , ascending = True ) , expected ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_25 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( net_25 ) ) ) <EOL> wanted = [ ip1 , ip2 ] <EOL> expected = wanted <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri ) , expected ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_12 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( net_12 ) ) ) <EOL> wanted = [ net_14 ] <EOL> expected = wanted <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri ) , expected ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_8 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( net_8 ) ) ) <EOL> wanted = [ net_12 , net_14 , net_25 , ip1 , ip2 ] <EOL> expected = wanted <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri ) , expected ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_14 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , mkcidr ( net_14 ) ) <EOL> ) <EOL> wanted = [ net_25 , ip1 , ip2 ] <EOL> expected = wanted <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri ) , expected ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , ip2 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( ip2 ) ) ) <EOL> expected = [ ] <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri ) , expected ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , ip2 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( ip2 ) ) ) <EOL> assert_success ( client . retrieve ( uri ) , net_25 ) <EOL> assert_success ( client . retrieve ( natural_uri ) , net_25 ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , ip1 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( ip1 ) ) ) <EOL> assert_success ( client . retrieve ( uri ) , net_8 ) <EOL> assert_success ( client . retrieve ( natural_uri ) , net_8 ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_8 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( net_8 ) ) ) <EOL> assert_error ( client . retrieve ( uri ) , status . HTTP_404_NOT_FOUND ) <EOL> assert_error ( client . retrieve ( natural_uri ) , status . HTTP_404_NOT_FOUND ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , ip1 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( '<STR_LIT>' , args = ( site . id , mkcidr ( ip1 ) ) ) <EOL> wanted = [ ip2 ] <EOL> expected = wanted <EOL> assert_success ( client . retrieve ( uri ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri ) , expected ) <EOL> wanted = [ ip1 , ip2 ] <EOL> expected = wanted <EOL> assert_success ( client . retrieve ( uri , include_self = True ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri , include_self = True ) , expected ) <EOL> def test_get_next_detail_routes ( site , client ) : <EOL> """<STR_LIT>""" <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_25_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_25 = get_result ( net_25_resp ) [ <NUM_LIT:0> ] <EOL> net_25_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net_25 [ '<STR_LIT:id>' ] ) <EOL> net_29_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> net_29 = get_result ( net_29_resp ) [ <NUM_LIT:0> ] <EOL> net_29_obj_uri = site . detail_uri ( '<STR_LIT>' , id = net_29 [ '<STR_LIT:id>' ] ) <EOL> ip1_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> ip1 = get_result ( ip1_resp ) [ <NUM_LIT:0> ] <EOL> ip1_obj_uri = site . detail_uri ( '<STR_LIT>' , id = ip1 [ '<STR_LIT:id>' ] ) <EOL> ip2_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> ip2 = get_result ( ip2_resp ) [ <NUM_LIT:0> ] <EOL> ip2_obj_uri = site . detail_uri ( '<STR_LIT>' , id = ip2 [ '<STR_LIT:id>' ] ) <EOL> ip3_resp = client . retrieve ( net_uri , cidr = '<STR_LIT>' ) <EOL> ip3 = get_result ( ip3_resp ) [ <NUM_LIT:0> ] <EOL> ip3_obj_uri = site . detail_uri ( '<STR_LIT>' , id = ip3 [ '<STR_LIT:id>' ] ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_25 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , mkcidr ( net_25 ) ) <EOL> ) <EOL> expected = [ u'<STR_LIT>' ] <EOL> assert_success ( client . retrieve ( uri , prefix_length = <NUM_LIT> ) , expected ) <EOL> assert_success ( client . retrieve ( natural_uri , prefix_length = <NUM_LIT> ) , expected ) <EOL> networks = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> assert_success ( <EOL> client . retrieve ( uri , prefix_length = <NUM_LIT> , num = <NUM_LIT:4> ) , <EOL> networks <EOL> ) <EOL> assert_success ( <EOL> client . retrieve ( natural_uri , prefix_length = <NUM_LIT> , num = <NUM_LIT:4> ) , <EOL> networks <EOL> ) <EOL> assert_error ( client . retrieve ( uri ) , status . HTTP_400_BAD_REQUEST ) <EOL> assert_error ( client . retrieve ( uri , prefix_length = '<STR_LIT>' ) , status . HTTP_400_BAD_REQUEST ) <EOL> assert_error ( client . retrieve ( uri , prefix_length = <NUM_LIT> ) , status . HTTP_400_BAD_REQUEST ) <EOL> assert_error ( client . retrieve ( uri , prefix_length = <NUM_LIT> ) , status . HTTP_400_BAD_REQUEST ) <EOL> assert_error ( client . retrieve ( natural_uri ) , status . HTTP_400_BAD_REQUEST ) <EOL> assert_error ( <EOL> client . retrieve ( natural_uri , prefix_length = '<STR_LIT>' ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> assert_error ( <EOL> client . retrieve ( natural_uri , prefix_length = <NUM_LIT> ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> assert_error ( <EOL> client . retrieve ( natural_uri , prefix_length = <NUM_LIT> ) , status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> assert_error ( <EOL> client . retrieve ( uri , prefix_length = <NUM_LIT> , num = '<STR_LIT>' ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> uri = reverse ( '<STR_LIT>' , args = ( site . id , net_25 [ '<STR_LIT:id>' ] ) ) <EOL> natural_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , mkcidr ( net_25 ) ) <EOL> ) <EOL> assert_success ( client . retrieve ( uri ) , [ u'<STR_LIT>' ] ) <EOL> assert_success ( client . retrieve ( natural_uri ) , [ u'<STR_LIT>' ] ) <EOL> addresses = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> assert_success ( client . retrieve ( uri , num = <NUM_LIT:3> ) , addresses ) <EOL> assert_success ( client . retrieve ( natural_uri , num = <NUM_LIT:3> ) , addresses ) <EOL> assert_error ( <EOL> client . retrieve ( uri , num = '<STR_LIT>' ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> assert_error ( <EOL> client . retrieve ( natural_uri , num = '<STR_LIT>' ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> def test_reservation_list_route ( site , client ) : <EOL> """<STR_LIT>""" <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> res_uri = reverse ( '<STR_LIT>' , args = ( site . id , ) ) <EOL> net_resp = client . create ( net_uri , cidr = '<STR_LIT>' , state = '<STR_LIT>' ) <EOL> net = get_result ( net_resp ) <EOL> networks = [ net ] <EOL> expected = networks <EOL> assert_success ( client . retrieve ( res_uri ) , expected ) <EOL> def test_closest_parent_detail_route ( site , client ) : <EOL> """<STR_LIT>""" <EOL> net_uri = site . list_uri ( '<STR_LIT>' ) <EOL> root_resp = client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> root = get_result ( root_resp ) <EOL> parent_resp = client . create ( net_uri , cidr = '<STR_LIT>' ) <EOL> parent = get_result ( parent_resp ) <EOL> closest_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , '<STR_LIT>' ) <EOL> ) <EOL> expected = parent <EOL> assert_success ( client . retrieve ( closest_uri ) , expected ) <EOL> assert_error ( <EOL> client . retrieve ( closest_uri , prefix_length = <NUM_LIT> ) , <EOL> status . HTTP_404_NOT_FOUND <EOL> ) <EOL> assert_error ( <EOL> client . retrieve ( closest_uri , prefix_length = '<STR_LIT>' ) , <EOL> status . HTTP_400_BAD_REQUEST <EOL> ) <EOL> bad_closest_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , <NUM_LIT:1> ) <EOL> ) <EOL> assert_error ( client . retrieve ( bad_closest_uri ) , status . HTTP_400_BAD_REQUEST ) <EOL> abc_closest_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , '<STR_LIT>' ) <EOL> ) <EOL> assert_error ( client . retrieve ( abc_closest_uri ) , status . HTTP_404_NOT_FOUND ) <EOL> no_closest_uri = reverse ( <EOL> '<STR_LIT>' , args = ( site . id , '<STR_LIT>' ) <EOL> ) <EOL> assert_error ( client . retrieve ( no_closest_uri ) , status . HTTP_404_NOT_FOUND ) </s>
