<s> """<STR_LIT>""" <EOL> from django . test import TestCase <EOL> from django . core . exceptions import ValidationError <EOL> import ipaddr <EOL> from mozdns . ip . models import ipv6_to_longs , Ip <EOL> from mozdns . domain . models import boot_strap_ipv6_reverse_domain , Domain <EOL> from mozdns . ip . utils import ip_to_domain_name <EOL> class SimpleTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . arpa = self . create_domain ( name = '<STR_LIT>' ) <EOL> self . arpa . save ( ) <EOL> self . i_arpa = self . create_domain ( name = '<STR_LIT>' ) <EOL> self . i_arpa . save ( ) <EOL> self . i6_arpa = self . create_domain ( name = '<STR_LIT>' ) <EOL> self . i6_arpa . save ( ) <EOL> rd = self . create_domain ( name = '<STR_LIT>' , ip_type = '<STR_LIT:4>' ) <EOL> rd . save ( ) <EOL> def create_domain ( self , name , ip_type = None , delegated = False ) : <EOL> if ip_type is None : <EOL> ip_type = '<STR_LIT:4>' <EOL> if name in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> pass <EOL> else : <EOL> name = ip_to_domain_name ( name , ip_type = ip_type ) <EOL> d = Domain ( name = name , delegated = delegated ) <EOL> d . clean ( ) <EOL> self . assertTrue ( d . is_reverse ) <EOL> return d <EOL> def test_ipv4_str ( self ) : <EOL> rd = self . create_domain ( name = '<STR_LIT>' , ip_type = '<STR_LIT:4>' ) <EOL> rd . save ( ) <EOL> ip_str = '<STR_LIT>' <EOL> ipaddr . IPv4Address ( ip_str ) <EOL> Ip ( ip_str = ip_str , ip_type = '<STR_LIT:4>' ) . clean_ip ( ) <EOL> rd = self . create_domain ( name = '<STR_LIT>' , ip_type = '<STR_LIT:4>' ) <EOL> rd . save ( ) <EOL> ip_str = '<STR_LIT>' <EOL> ipaddr . IPv4Address ( ip_str ) <EOL> Ip ( ip_str = ip_str , ip_type = '<STR_LIT:4>' ) . clean_ip ( ) <EOL> def test_update_ipv4_str ( self ) : <EOL> ip_str = '<STR_LIT>' <EOL> v_ip = ipaddr . IPv4Address ( ip_str ) <EOL> ip = Ip ( ip_str = ip_str , ip_type = '<STR_LIT:4>' ) <EOL> ip . clean_ip ( ) <EOL> self . assertEqual ( ip . ip_upper , <NUM_LIT:0> ) <EOL> self . assertEqual ( ip . ip_lower , int ( v_ip ) ) <EOL> ip_str = '<STR_LIT>' <EOL> v_ip = ipaddr . IPv4Address ( ip_str ) <EOL> ip . ip_str = ip_str <EOL> ip . clean_ip ( ) <EOL> self . assertEqual ( ip . ip_upper , <NUM_LIT:0> ) <EOL> self . assertEqual ( ip . ip_lower , int ( v_ip ) ) <EOL> def test_ipv6_str ( self ) : <EOL> boot_strap_ipv6_reverse_domain ( '<STR_LIT>' ) <EOL> ip_str = '<STR_LIT>' <EOL> new_ip = Ip ( ip_str = ip_str , ip_type = '<STR_LIT>' ) <EOL> new_ip . clean_ip ( ) <EOL> ip_upper , ip_lower = ipv6_to_longs ( ip_str ) <EOL> self . assertEqual ( new_ip . ip_upper , ip_upper ) <EOL> self . assertEqual ( new_ip . ip_lower , ip_lower ) <EOL> ip_str = '<STR_LIT>' <EOL> new_ip = Ip ( ip_str = ip_str , ip_type = '<STR_LIT>' ) <EOL> new_ip . clean_ip ( ) <EOL> ip_upper , ip_lower = ipv6_to_longs ( ip_str ) <EOL> self . assertEqual ( new_ip . ip_upper , ip_upper ) <EOL> self . assertEqual ( new_ip . ip_lower , ip_lower ) <EOL> def test_large_ipv6 ( self ) : <EOL> boot_strap_ipv6_reverse_domain ( '<STR_LIT:f>' ) <EOL> ip_str = '<STR_LIT>' <EOL> ip = ipaddr . IPv6Address ( ip_str ) <EOL> ip_upper , ip_lower = ipv6_to_longs ( ip_str ) <EOL> self . assertEqual ( ip . __int__ ( ) , ( <NUM_LIT:2> ** <NUM_LIT:64> ) * ip_upper + ip_lower ) <EOL> new_ip = Ip ( ip_str = ip_str , ip_upper = ip_upper , <EOL> ip_lower = ip_lower , ip_type = '<STR_LIT>' ) <EOL> new_ip . clean_ip ( ) <EOL> self . assertEqual ( ip_str , new_ip . ip_str ) <EOL> self . assertEqual ( ip . __int__ ( ) , new_ip . __int__ ( ) ) <EOL> def bad_ipv6 ( self ) : <EOL> self . assertRaises ( ValidationError , ipv6_to_longs , { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> def test_int_ip ( self ) : <EOL> rd = self . create_domain ( name = '<STR_LIT>' , ip_type = '<STR_LIT:4>' ) <EOL> rd . save ( ) <EOL> ip = Ip ( ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:4>' ) <EOL> ip . clean_ip ( ) <EOL> ip . __int__ ( ) <EOL> ip . __repr__ ( ) <EOL> rd = boot_strap_ipv6_reverse_domain ( '<STR_LIT:e>' ) <EOL> ip_str = '<STR_LIT>' <EOL> ip = Ip ( ip_str = ip_str , ip_type = '<STR_LIT>' ) <EOL> ip . clean_ip ( ) <EOL> ip . __int__ ( ) <EOL> ip . __repr__ ( ) <EOL> def test_creation ( self ) : <EOL> rd = self . create_domain ( name = '<STR_LIT>' , ip_type = '<STR_LIT:4>' ) <EOL> rd . save ( ) <EOL> try : <EOL> ip = Ip ( ip_str = "<STR_LIT>" ) <EOL> ip . clean_ip ( ) <EOL> except ValidationError , e : <EOL> pass <EOL> self . assertEqual ( ValidationError , type ( e ) ) <EOL> ip = Ip ( ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:4>' ) <EOL> self . assertFalse ( ip . ip_upper and ip . ip_lower and ip . reverse_domain ) <EOL> ip . clean_ip ( ) <EOL> ip . update_reverse_domain ( ) <EOL> self . assertTrue ( <EOL> ip . ip_upper == <NUM_LIT:0> and ip . ip_lower and ip . reverse_domain ) <EOL> def test_bad_create ( self ) : <EOL> ip = Ip ( ip_str = "<STR_LIT>" , ip_type = '<STR_LIT:x>' ) <EOL> self . assertRaises ( ValidationError , ip . clean_ip ) <EOL> ip = Ip ( ip_str = "<STR_LIT>" , ip_type = None ) <EOL> self . assertRaises ( ValidationError , ip . clean_ip ) <EOL> ip = Ip ( ip_str = "<STR_LIT>" , ip_type = <NUM_LIT> ) <EOL> self . assertRaises ( ValidationError , ip . clean_ip ) <EOL> def test_ipv6_to_longs ( self ) : <EOL> addr = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , ipv6_to_longs , addr ) <EOL> def test1_ipv6_to_longs ( self ) : <EOL> ip_str = "<STR_LIT>" <EOL> ip_upper , ip_lower = ipv6_to_longs ( ip_str ) <EOL> self . assertEqual ( hex ( ip_upper ) . lower ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( hex ( ip_lower ) . lower ( ) , "<STR_LIT>" ) <EOL> def test2_ipv6_to_longs ( self ) : <EOL> ip_upper_str = "<STR_LIT>" <EOL> ip_lower_str = "<STR_LIT>" <EOL> ip_upper , ip_lower = ipv6_to_longs ( ip_upper_str + "<STR_LIT::>" + ip_lower_str ) <EOL> self . assertEqual ( hex ( ip_upper ) . lower ( ) , "<STR_LIT>" % ( ip_upper_str . lower ( ) <EOL> . replace ( '<STR_LIT::>' , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( hex ( ip_lower ) . lower ( ) , "<STR_LIT>" % ( ip_lower_str . lower ( ) <EOL> . replace ( '<STR_LIT::>' , '<STR_LIT>' ) ) ) <EOL> def test2_ipv6_to_longs2 ( self ) : <EOL> ip_upper_str = "<STR_LIT>" <EOL> ip_lower_str = "<STR_LIT>" <EOL> ip_upper , ip_lower = ipv6_to_longs ( ip_upper_str + "<STR_LIT::>" + ip_lower_str ) <EOL> self . assertEqual ( hex ( ip_upper ) . lower ( ) , "<STR_LIT>" % ( ip_upper_str . lower ( ) <EOL> . replace ( '<STR_LIT::>' , '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( hex ( ip_lower ) . lower ( ) , "<STR_LIT>" ) </s>
