<s> from django . test import TestCase <EOL> from django . core . exceptions import ValidationError <EOL> from core . registration . static . models import StaticReg <EOL> from systems . tests . utils import create_fake_host <EOL> from mozdns . domain . models import Domain <EOL> from mozdns . address_record . models import AddressRecord <EOL> from mozdns . ptr . models import PTR <EOL> from mozdns . view . models import View <EOL> from mozdns . ip . utils import ip_to_domain_name <EOL> class StaticRegTests ( TestCase ) : <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 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 . c = Domain ( name = "<STR_LIT>" ) <EOL> self . c . save ( ) <EOL> self . f_c = Domain ( name = "<STR_LIT>" ) <EOL> self . f_c . save ( ) <EOL> self . r1 = self . create_domain ( name = "<STR_LIT>" ) <EOL> self . r1 . save ( ) <EOL> self . r2 = self . create_domain ( name = "<STR_LIT>" ) <EOL> self . r2 . save ( ) <EOL> self . n = create_fake_host ( hostname = "<STR_LIT>" ) <EOL> self . n . clean ( ) <EOL> self . n . save ( ) <EOL> View . objects . get_or_create ( name = "<STR_LIT>" ) <EOL> def do_add ( self , label , domain , ip_str , ip_type = '<STR_LIT:4>' ) : <EOL> r = StaticReg ( <EOL> label = label , domain = domain , ip_str = ip_str , ip_type = ip_type , <EOL> system = self . n <EOL> ) <EOL> r . clean ( ) <EOL> r . save ( ) <EOL> r . details ( ) <EOL> r . get_edit_url ( ) <EOL> r . get_delete_url ( ) <EOL> r . get_absolute_url ( ) <EOL> repr ( r ) <EOL> return r <EOL> def do_delete ( self , r ) : <EOL> ip_str = r . ip_str <EOL> fqdn = r . fqdn <EOL> r . delete ( ) <EOL> self . assertFalse ( <EOL> AddressRecord . objects . filter ( ip_str = ip_str , fqdn = fqdn ) <EOL> ) <EOL> def test1_create_basic ( self ) : <EOL> label = "<STR_LIT:foo>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , <EOL> '<STR_LIT>' : ip_str <EOL> } <EOL> self . do_add ( ** kwargs ) <EOL> def test2_create_basic ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> i = self . do_add ( ** kwargs ) <EOL> self . assertEqual ( self . r1 , i . reverse_domain ) <EOL> i2 = StaticReg . objects . get ( pk = i . pk ) <EOL> self . assertEqual ( self . r1 , i2 . reverse_domain ) <EOL> def test3_create_basic ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> self . do_add ( ** kwargs ) <EOL> def test4_create_basic ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> self . do_add ( ** kwargs ) <EOL> def test6_create_basic ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> i = self . do_add ( ** kwargs ) <EOL> self . assertEqual ( self . r2 , i . reverse_domain ) <EOL> def test1_delete ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str } <EOL> r = self . do_add ( ** kwargs ) <EOL> self . do_delete ( r ) <EOL> def test1_dup_create_basic ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> self . do_add ( ** kwargs ) <EOL> self . assertRaises ( ValidationError , self . do_add , ** kwargs ) <EOL> def test1_bad_add_for_a_ptr ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> ip_type = '<STR_LIT:4>' <EOL> i = self . do_add ( ** kwargs ) <EOL> i . clean ( ) <EOL> i . save ( ) <EOL> a = AddressRecord ( label = label , domain = domain , ip_str = ip_str , <EOL> ip_type = ip_type ) <EOL> self . assertRaises ( ValidationError , a . save ) <EOL> ptr = PTR ( ip_str = ip_str , ip_type = ip_type , name = i . fqdn ) <EOL> self . assertRaises ( ValidationError , ptr . save ) <EOL> def test2_bad_add_for_a_ptr ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> ip_type = '<STR_LIT:4>' <EOL> a = AddressRecord . objects . create ( <EOL> label = label , domain = domain , ip_str = ip_str , ip_type = ip_type <EOL> ) <EOL> PTR . objects . create ( ip_str = ip_str , ip_type = ip_type , name = a . fqdn ) <EOL> self . assertRaises ( ValidationError , self . do_add , ** kwargs ) <EOL> def test1_bad_reverse_domain ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> kwargs = { <EOL> '<STR_LIT:label>' : label , '<STR_LIT>' : domain , '<STR_LIT>' : ip_str , <EOL> } <EOL> i = self . do_add ( ** kwargs ) <EOL> i . ip_str = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , i . save ) <EOL> def test1_no_system ( self ) : <EOL> label = "<STR_LIT>" <EOL> domain = self . f_c <EOL> ip_str = "<STR_LIT>" <EOL> ip_type = '<STR_LIT:4>' <EOL> r = StaticReg ( <EOL> label = label , domain = domain , ip_str = ip_str , ip_type = ip_type , <EOL> system = None <EOL> ) <EOL> self . assertRaises ( ValidationError , r . save ) </s>
