<s> import unittest <EOL> from trac . resource import ResourceNotFound <EOL> from trac . test import EnvironmentStub , MockRequest <EOL> from trac . ticket . admin import ComponentAdminPanel , MilestoneAdminPanel , PriorityAdminPanel , ResolutionAdminPanel , SeverityAdminPanel , TicketTypeAdminPanel , VersionAdminPanel <EOL> from trac . ticket . model import Component , Milestone , Priority , Resolution , Severity , Type , Version <EOL> from trac . web . api import RequestDone <EOL> class BaseTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . env = EnvironmentStub ( default_data = True ) <EOL> def tearDown ( self ) : <EOL> self . env . reset_db ( ) <EOL> class ComponentAdminPanelTestCase ( BaseTestCase ) : <EOL> def test_add_component ( self ) : <EOL> cap = ComponentAdminPanel ( self . env ) <EOL> name , owner = '<STR_LIT>' , '<STR_LIT>' <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:name>' : name , '<STR_LIT>' : owner , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( ResourceNotFound , Component , self . env , name ) <EOL> self . assertRaises ( RequestDone , cap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> component = Component ( self . env , name ) <EOL> self . assertEqual ( name , component . name ) <EOL> self . assertEqual ( owner , component . owner ) <EOL> def test_remove_component ( self ) : <EOL> cap = ComponentAdminPanel ( self . env ) <EOL> name = '<STR_LIT>' <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> component = Component ( self . env , name ) <EOL> self . assertEqual ( name , component . name ) <EOL> self . assertEqual ( '<STR_LIT>' , component . owner ) <EOL> self . assertRaises ( RequestDone , cap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> self . assertRaises ( ResourceNotFound , Component , self . env , name ) <EOL> def test_remove_multiple_components ( self ) : <EOL> cap = ComponentAdminPanel ( self . env ) <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : names , '<STR_LIT>' : True } ) <EOL> for name in names : <EOL> component = Component ( self . env , name ) <EOL> self . assertEqual ( name , component . name ) <EOL> self . assertEqual ( '<STR_LIT>' , component . owner ) <EOL> self . assertRaises ( RequestDone , cap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> for name in names : <EOL> self . assertRaises ( ResourceNotFound , Component , self . env , name ) <EOL> def test_set_default_component ( self ) : <EOL> name = '<STR_LIT>' <EOL> config_key = '<STR_LIT>' <EOL> cap = ComponentAdminPanel ( self . env ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:default>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , cap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> self . assertEqual ( name , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> def test_remove_default_component ( self ) : <EOL> name = '<STR_LIT>' <EOL> cap = ComponentAdminPanel ( self . env ) <EOL> config_key = '<STR_LIT>' <EOL> self . env . config . set ( '<STR_LIT>' , config_key , name ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , cap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> self . assertEqual ( '<STR_LIT>' , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> class MilestoneAdminPanelTestCase ( BaseTestCase ) : <EOL> def test_add_milestone ( self ) : <EOL> name = '<STR_LIT>' <EOL> map = MilestoneAdminPanel ( self . env ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:name>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( ResourceNotFound , Milestone , self . env , name ) <EOL> self . assertRaises ( RequestDone , map . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> milestone = Milestone ( self . env , name ) <EOL> self . assertEqual ( name , milestone . name ) <EOL> def test_set_default_milestone ( self ) : <EOL> name = '<STR_LIT>' <EOL> config_key = '<STR_LIT>' <EOL> map = MilestoneAdminPanel ( self . env ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , map . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> self . assertEqual ( name , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> def test_set_default_retarget_to ( self ) : <EOL> name = '<STR_LIT>' <EOL> config_key = '<STR_LIT>' <EOL> map = MilestoneAdminPanel ( self . env ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , map . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> self . assertEqual ( name , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> def test_remove_default_milestone ( self ) : <EOL> name = '<STR_LIT>' <EOL> map = MilestoneAdminPanel ( self . env ) <EOL> self . env . config . set ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . env . config . set ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , map . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT>' , None ) <EOL> self . assertEqual ( '<STR_LIT>' , self . env . config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> self . assertEqual ( '<STR_LIT>' , self . env . config . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> class AbstractEnumTestCase ( BaseTestCase ) : <EOL> type = None <EOL> cls = None <EOL> def _test_add ( self , panel , name ) : <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:name>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( ResourceNotFound , self . cls , self . env , name ) <EOL> self . assertRaises ( RequestDone , panel . render_admin_panel , req , <EOL> '<STR_LIT>' , self . type , None ) <EOL> item = self . cls ( self . env , name ) <EOL> self . assertEqual ( name , item . name ) <EOL> def _test_set_default ( self , panel , name ) : <EOL> config_key = '<STR_LIT>' + self . type <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:default>' : name , '<STR_LIT>' : True } ) <EOL> for item in self . cls . select ( self . env ) : <EOL> req . args . update ( { '<STR_LIT>' + str ( item . value ) : str ( item . value ) } ) <EOL> self . assertRaises ( RequestDone , panel . render_admin_panel , req , <EOL> '<STR_LIT>' , self . type , None ) <EOL> self . assertEqual ( name , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> def _test_remove_default ( self , panel , name ) : <EOL> config_key = '<STR_LIT>' + self . type <EOL> self . env . config . set ( '<STR_LIT>' , config_key , name ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , panel . render_admin_panel , req , <EOL> '<STR_LIT>' , self . type , None ) <EOL> self . assertEqual ( '<STR_LIT>' , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> class PriorityAdminPanelTestCase ( AbstractEnumTestCase ) : <EOL> type = '<STR_LIT>' <EOL> cls = Priority <EOL> def test_add_priority ( self ) : <EOL> ap = PriorityAdminPanel ( self . env ) <EOL> self . _test_add ( ap , '<STR_LIT>' ) <EOL> def test_set_default_priority ( self ) : <EOL> ap = PriorityAdminPanel ( self . env ) <EOL> self . _test_set_default ( ap , '<STR_LIT>' ) <EOL> def test_remove_default_priority ( self ) : <EOL> ap = PriorityAdminPanel ( self . env ) <EOL> self . _test_remove_default ( ap , '<STR_LIT>' ) <EOL> class ResolutionAdminPanelTestCase ( AbstractEnumTestCase ) : <EOL> type = '<STR_LIT>' <EOL> cls = Resolution <EOL> def test_add_resolution ( self ) : <EOL> ap = ResolutionAdminPanel ( self . env ) <EOL> self . _test_add ( ap , '<STR_LIT>' ) <EOL> def test_set_default_resolution ( self ) : <EOL> ap = ResolutionAdminPanel ( self . env ) <EOL> self . _test_set_default ( ap , '<STR_LIT>' ) <EOL> def test_remove_default_resolution ( self ) : <EOL> ap = ResolutionAdminPanel ( self . env ) <EOL> self . _test_remove_default ( ap , '<STR_LIT>' ) <EOL> class SeverityAdminPanelTestCase ( AbstractEnumTestCase ) : <EOL> type = '<STR_LIT>' <EOL> cls = Severity <EOL> def test_add_severity ( self ) : <EOL> ap = SeverityAdminPanel ( self . env ) <EOL> self . _test_add ( ap , '<STR_LIT>' ) <EOL> def test_set_default_severity ( self ) : <EOL> s = Severity ( self . env ) <EOL> s . name = '<STR_LIT>' <EOL> s . insert ( ) <EOL> ap = SeverityAdminPanel ( self . env ) <EOL> self . _test_set_default ( ap , '<STR_LIT>' ) <EOL> def test_remove_default_severity ( self ) : <EOL> s = Severity ( self . env ) <EOL> s . name = '<STR_LIT>' <EOL> s . insert ( ) <EOL> ap = SeverityAdminPanel ( self . env ) <EOL> self . _test_remove_default ( ap , '<STR_LIT>' ) <EOL> class TicketTypeAdminPanelTestCase ( AbstractEnumTestCase ) : <EOL> type = '<STR_LIT:type>' <EOL> cls = Type <EOL> def test_add_type ( self ) : <EOL> ap = TicketTypeAdminPanel ( self . env ) <EOL> self . _test_add ( ap , '<STR_LIT>' ) <EOL> def test_set_default_type ( self ) : <EOL> ap = TicketTypeAdminPanel ( self . env ) <EOL> self . _test_set_default ( ap , '<STR_LIT>' ) <EOL> def test_remove_default_type ( self ) : <EOL> ap = TicketTypeAdminPanel ( self . env ) <EOL> self . _test_remove_default ( ap , '<STR_LIT>' ) <EOL> class VersionAdminPanelTestCase ( BaseTestCase ) : <EOL> def test_add_version ( self ) : <EOL> name = '<STR_LIT>' <EOL> ap = VersionAdminPanel ( self . env ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:name>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( ResourceNotFound , Version , self . env , name ) <EOL> self . assertRaises ( RequestDone , ap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT:version>' , None ) <EOL> version = Version ( self . env , name ) <EOL> self . assertEqual ( name , version . name ) <EOL> def test_set_default_version ( self ) : <EOL> name = '<STR_LIT:1.0>' <EOL> ap = VersionAdminPanel ( self . env ) <EOL> config_key = '<STR_LIT>' <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT:default>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , ap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT:version>' , None ) <EOL> self . assertEqual ( name , self . env . config . get ( '<STR_LIT>' , config_key ) ) <EOL> def test_remove_default_version ( self ) : <EOL> name = '<STR_LIT:1.0>' <EOL> ap = VersionAdminPanel ( self . env ) <EOL> config_key = '<STR_LIT>' <EOL> self . env . config . set ( '<STR_LIT>' , config_key , name ) <EOL> req = MockRequest ( self . env , method = '<STR_LIT:POST>' , <EOL> args = { '<STR_LIT>' : name , '<STR_LIT>' : True } ) <EOL> self . assertRaises ( RequestDone , ap . render_admin_panel , req , <EOL> '<STR_LIT>' , '<STR_LIT:version>' , None ) <EOL> self . assertEqual ( self . env . config . get ( '<STR_LIT>' , config_key ) , '<STR_LIT>' ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( ComponentAdminPanelTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( MilestoneAdminPanelTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( PriorityAdminPanelTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( ResolutionAdminPanelTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( SeverityAdminPanelTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( TicketTypeAdminPanelTestCase ) ) <EOL> suite . addTest ( unittest . makeSuite ( VersionAdminPanelTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
