<s> """<STR_LIT>""" <EOL> from django . contrib . auth . models import User <EOL> from django . test import TestCase <EOL> from powerdns . models . powerdns import Domain , Record <EOL> from powerdns . tests . utils import ( <EOL> DomainFactory , <EOL> DomainTemplateFactory , <EOL> RecordFactory , <EOL> RecordTemplateFactory , <EOL> assert_does_exist , <EOL> assert_not_exists , <EOL> ) <EOL> from powerdns . utils import AutoPtrOptions <EOL> class TestAutoPtr ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_superuser ( <EOL> '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT:password>' <EOL> ) <EOL> self . reverse_template = DomainTemplateFactory ( name = '<STR_LIT>' ) <EOL> self . alt_reverse_template = DomainTemplateFactory ( name = '<STR_LIT>' ) <EOL> self . soa_record = RecordTemplateFactory ( <EOL> type = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> content = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> domain_template = self . reverse_template , <EOL> ) <EOL> self . alt_soa_record = RecordTemplateFactory ( <EOL> type = '<STR_LIT>' , <EOL> name = '<STR_LIT>' , <EOL> content = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> domain_template = self . alt_reverse_template , <EOL> ) <EOL> self . domain = DomainFactory ( <EOL> name = '<STR_LIT>' , <EOL> template = None , <EOL> reverse_template = None , <EOL> type = '<STR_LIT>' , <EOL> ) <EOL> def tearDown ( self ) : <EOL> for Model in [ Domain , Record , User ] : <EOL> Model . objects . all ( ) . delete ( ) <EOL> def test_default_ptr_created ( self ) : <EOL> """<STR_LIT>""" <EOL> RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ALWAYS , <EOL> owner = self . user , <EOL> ) <EOL> domain = Domain . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( domain . type , '<STR_LIT>' ) <EOL> self . assertTrue ( domain . get_soa ( ) . content . endswith ( '<STR_LIT>' ) ) <EOL> assert_does_exist ( <EOL> Record , <EOL> domain = domain , <EOL> name = '<STR_LIT>' , <EOL> owner = self . user , <EOL> ) <EOL> def test_auto_ptr_edit ( self ) : <EOL> """<STR_LIT>""" <EOL> record = RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ALWAYS , <EOL> ) <EOL> record . content = '<STR_LIT>' <EOL> record . save ( ) <EOL> domain = Domain . objects . get ( name = '<STR_LIT>' ) <EOL> assert_does_exist ( <EOL> Record , <EOL> domain = domain , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> assert_not_exists ( <EOL> Record , <EOL> domain = domain , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> def test_auto_ptr_off ( self ) : <EOL> """<STR_LIT>""" <EOL> record = RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ALWAYS , <EOL> ) <EOL> domain = Domain . objects . get ( name = '<STR_LIT>' ) <EOL> record . auto_ptr = AutoPtrOptions . NEVER <EOL> record . save ( ) <EOL> assert_not_exists ( <EOL> Record , <EOL> domain = domain , <EOL> name = '<STR_LIT>' , <EOL> ) <EOL> def test_default_ptr_never ( self ) : <EOL> """<STR_LIT>""" <EOL> domain = DomainFactory ( name = '<STR_LIT>' ) <EOL> RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . NEVER , <EOL> ) <EOL> assert_not_exists ( <EOL> Record , <EOL> domain = domain , <EOL> name = '<STR_LIT>' <EOL> ) <EOL> def test_ptr_domain_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> domain = DomainFactory ( name = '<STR_LIT>' ) <EOL> RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ONLY_IF_DOMAIN , <EOL> ) <EOL> assert_does_exist ( <EOL> Record , <EOL> domain = domain , <EOL> name = '<STR_LIT>' <EOL> ) <EOL> def test_ptr_domain_not_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ONLY_IF_DOMAIN , <EOL> ) <EOL> assert_not_exists ( <EOL> Record , <EOL> name = '<STR_LIT>' <EOL> ) <EOL> def test_alt_ptr_created ( self ) : <EOL> """<STR_LIT>""" <EOL> self . domain . reverse_template = self . alt_reverse_template <EOL> RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ALWAYS , <EOL> ) <EOL> domain = Domain . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertTrue ( domain . get_soa ( ) . content . endswith ( '<STR_LIT>' ) ) <EOL> def test_ptr_autoremove ( self ) : <EOL> """<STR_LIT>""" <EOL> a = RecordFactory ( <EOL> domain = self . domain , <EOL> type = '<STR_LIT:A>' , <EOL> name = '<STR_LIT>' , <EOL> content = '<STR_LIT>' , <EOL> auto_ptr = AutoPtrOptions . ALWAYS , <EOL> ) <EOL> assert_does_exist ( Record , name = '<STR_LIT>' , type = '<STR_LIT>' ) <EOL> a . delete ( ) <EOL> assert_not_exists ( Record , name = '<STR_LIT>' , type = '<STR_LIT>' ) </s>
