<s> """<STR_LIT>""" <EOL> import re <EOL> from genshi . builder import tag <EOL> from trac . tests . functional import internal_error <EOL> from trac . tests . functional . better_twill import tc , b <EOL> from trac . tests . contentgen import random_page , random_sentence , random_word , random_unique_camel <EOL> from trac . util . text import to_utf8 , unicode_quote <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> class FunctionalTester ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url ) : <EOL> """<STR_LIT>""" <EOL> self . url = url <EOL> self . ticketcount = <NUM_LIT:0> <EOL> self . go_to_front ( ) <EOL> self . login ( '<STR_LIT>' ) <EOL> def login ( self , username ) : <EOL> """<STR_LIT>""" <EOL> username = to_utf8 ( username ) <EOL> tc . add_auth ( "<STR_LIT>" , self . url , username , username ) <EOL> self . go_to_front ( ) <EOL> tc . find ( "<STR_LIT>" ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . find ( '<STR_LIT>' <EOL> % username ) <EOL> tc . find ( "<STR_LIT>" ) <EOL> tc . url ( self . url ) <EOL> tc . notfind ( internal_error ) <EOL> def logout ( self ) : <EOL> """<STR_LIT>""" <EOL> tc . submit ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> tc . notfind ( internal_error ) <EOL> tc . notfind ( '<STR_LIT>' ) <EOL> def create_ticket ( self , summary = None , info = None ) : <EOL> """<STR_LIT>""" <EOL> info = info or { } <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . notfind ( internal_error ) <EOL> if summary is None : <EOL> summary = random_sentence ( <NUM_LIT:5> ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , summary ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , random_page ( ) ) <EOL> if '<STR_LIT>' in info : <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:action>' , '<STR_LIT>' ) <EOL> tc . formvalue ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> info . pop ( '<STR_LIT>' ) ) <EOL> for field , value in info . items ( ) : <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' % field , value ) <EOL> tc . submit ( '<STR_LIT>' ) <EOL> tc . notfind ( internal_error ) <EOL> tc . url ( self . url + '<STR_LIT>' % ( self . ticketcount + <NUM_LIT:1> ) ) <EOL> self . ticketcount += <NUM_LIT:1> <EOL> return self . ticketcount <EOL> def quickjump ( self , search ) : <EOL> """<STR_LIT>""" <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:q>' , search ) <EOL> tc . submit ( ) <EOL> tc . notfind ( internal_error ) <EOL> def go_to_url ( self , url ) : <EOL> tc . go ( url ) <EOL> tc . url ( re . escape ( url ) ) <EOL> tc . notfind ( internal_error ) <EOL> def go_to_front ( self ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_url ( self . url ) <EOL> def go_to_ticket ( self , ticketid = None ) : <EOL> """<STR_LIT>""" <EOL> if ticketid is not None : <EOL> ticket_url = self . url + '<STR_LIT>' % ticketid <EOL> else : <EOL> ticket_url = self . url + '<STR_LIT>' <EOL> self . go_to_url ( ticket_url ) <EOL> tc . url ( ticket_url + '<STR_LIT:$>' ) <EOL> def go_to_wiki ( self , name , version = None ) : <EOL> """<STR_LIT>""" <EOL> wiki_url = self . url + '<STR_LIT>' % name <EOL> if version : <EOL> wiki_url += '<STR_LIT>' % version <EOL> self . go_to_url ( wiki_url ) <EOL> def go_to_timeline ( self ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT>' ) <EOL> def go_to_view_tickets ( self , href = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT:/>' + href . lstrip ( '<STR_LIT:/>' ) ) <EOL> def go_to_query ( self ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT>' ) <EOL> def go_to_admin ( self , panel_label = None ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT>' ) <EOL> if panel_label is not None : <EOL> tc . follow ( r"<STR_LIT>" % panel_label ) <EOL> def go_to_roadmap ( self ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT>' ) <EOL> def go_to_milestone ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_roadmap ( ) <EOL> tc . follow ( r"<STR_LIT>" % name ) <EOL> tc . url ( self . url + '<STR_LIT>' % name ) <EOL> def go_to_report ( self , id , args = None ) : <EOL> """<STR_LIT>""" <EOL> report_url = self . url + "<STR_LIT>" % id <EOL> if args : <EOL> arglist = [ ] <EOL> for param , value in args . items ( ) : <EOL> arglist . append ( '<STR_LIT>' % ( param . upper ( ) , unicode_quote ( value ) ) ) <EOL> report_url += '<STR_LIT:?>' + '<STR_LIT:&>' . join ( arglist ) <EOL> tc . go ( report_url ) <EOL> tc . url ( report_url . encode ( '<STR_LIT>' ) . replace ( '<STR_LIT:?>' , '<STR_LIT>' ) ) <EOL> def go_to_preferences ( self , panel_label = None ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT>' ) <EOL> if panel_label is not None : <EOL> tc . follow ( r"<STR_LIT>" % panel_label ) <EOL> def add_comment ( self , ticketid , comment = None ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_ticket ( ticketid ) <EOL> if comment is None : <EOL> comment = random_sentence ( ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , comment ) <EOL> tc . submit ( "<STR_LIT>" ) <EOL> tc . url ( self . url + '<STR_LIT>' % ticketid ) <EOL> return comment <EOL> def attach_file_to_ticket ( self , ticketid , data = None , filename = None , <EOL> description = None , replace = False , <EOL> content_type = None ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_ticket ( ticketid ) <EOL> return self . _attach_file_to_resource ( '<STR_LIT>' , ticketid , data , <EOL> filename , description , <EOL> replace , content_type ) <EOL> def clone_ticket ( self , ticketid ) : <EOL> """<STR_LIT>""" <EOL> ticket_url = self . url + '<STR_LIT>' % ticketid <EOL> tc . go ( ticket_url ) <EOL> tc . url ( ticket_url ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> tc . submit ( ) <EOL> self . ticketcount += <NUM_LIT:1> <EOL> tc . url ( self . url + "<STR_LIT>" % self . ticketcount ) <EOL> return self . ticketcount <EOL> def create_wiki_page ( self , name = None , content = None , comment = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = random_unique_camel ( ) <EOL> if content is None : <EOL> content = random_page ( ) <EOL> self . go_to_wiki ( name ) <EOL> tc . find ( "<STR_LIT>" % tag . strong ( name ) ) <EOL> self . edit_wiki_page ( name , content , comment ) <EOL> self . go_to_timeline ( ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> tc . submit ( ) <EOL> tc . find ( name + "<STR_LIT>" ) <EOL> self . go_to_wiki ( name ) <EOL> return name <EOL> def edit_wiki_page ( self , name , content = None , comment = None ) : <EOL> """<STR_LIT>""" <EOL> if content is None : <EOL> content = random_page ( ) <EOL> if comment is None : <EOL> comment = random_sentence ( ) <EOL> self . go_to_wiki ( name ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:action>' , '<STR_LIT>' ) <EOL> tc . submit ( ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:text>' , content ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , comment ) <EOL> tc . submit ( '<STR_LIT>' ) <EOL> page_url = self . url + '<STR_LIT>' % name <EOL> tc . url ( page_url + '<STR_LIT:$>' ) <EOL> return content <EOL> def attach_file_to_wiki ( self , name , data = None , filename = None , <EOL> description = None , replace = False , <EOL> content_type = None ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_wiki ( name ) <EOL> return self . _attach_file_to_resource ( '<STR_LIT>' , name , data , <EOL> filename , description , <EOL> replace , content_type ) <EOL> def create_milestone ( self , name = None , due = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = random_unique_camel ( ) <EOL> milestone_url = self . url + "<STR_LIT>" <EOL> tc . go ( milestone_url ) <EOL> tc . url ( milestone_url ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:name>' , name ) <EOL> if due : <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , due ) <EOL> tc . submit ( ) <EOL> tc . notfind ( internal_error ) <EOL> tc . notfind ( '<STR_LIT>' ) <EOL> tc . url ( milestone_url ) <EOL> tc . find ( name ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . url ( self . url + "<STR_LIT>" ) <EOL> tc . find ( '<STR_LIT>' % name ) <EOL> tc . follow ( r"<STR_LIT>" % name ) <EOL> tc . url ( '<STR_LIT>' % ( self . url , unicode_quote ( name ) ) ) <EOL> if not due : <EOL> tc . find ( '<STR_LIT>' ) <EOL> return name <EOL> def attach_file_to_milestone ( self , name , data = None , filename = None , <EOL> description = None , replace = False , <EOL> content_type = None ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_milestone ( name ) <EOL> return self . _attach_file_to_resource ( '<STR_LIT>' , name , data , <EOL> filename , description , <EOL> replace , content_type ) <EOL> def create_component ( self , name = None , owner = None , description = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = random_unique_camel ( ) <EOL> component_url = self . url + "<STR_LIT>" <EOL> tc . go ( component_url ) <EOL> tc . url ( component_url ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:name>' , name ) <EOL> if owner is not None : <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , owner ) <EOL> tc . submit ( ) <EOL> tc . url ( component_url ) <EOL> tc . find ( name ) <EOL> tc . notfind ( internal_error ) <EOL> if description is not None : <EOL> tc . follow ( r"<STR_LIT>" % name ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:description>' , description ) <EOL> tc . submit ( '<STR_LIT>' ) <EOL> tc . url ( component_url ) <EOL> tc . find ( "<STR_LIT>" ) <EOL> tc . notfind ( internal_error ) <EOL> return name <EOL> def create_enum ( self , kind , name = None ) : <EOL> """<STR_LIT>""" <EOL> if name is None : <EOL> name = random_unique_camel ( ) <EOL> priority_url = self . url + "<STR_LIT>" + kind <EOL> tc . go ( priority_url ) <EOL> tc . url ( priority_url ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:name>' , name ) <EOL> tc . submit ( ) <EOL> tc . url ( priority_url ) <EOL> tc . find ( name ) <EOL> tc . notfind ( internal_error ) <EOL> return name <EOL> def create_priority ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> return self . create_enum ( '<STR_LIT>' , name ) <EOL> def create_resolution ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> return self . create_enum ( '<STR_LIT>' , name ) <EOL> def create_severity ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> return self . create_enum ( '<STR_LIT>' , name ) <EOL> def create_type ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> return self . create_enum ( '<STR_LIT:type>' , name ) <EOL> def create_version ( self , name = None , releasetime = None ) : <EOL> """<STR_LIT>""" <EOL> version_admin = self . url + "<STR_LIT>" <EOL> if name is None : <EOL> name = random_unique_camel ( ) <EOL> tc . go ( version_admin ) <EOL> tc . url ( version_admin ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:name>' , name ) <EOL> if releasetime is not None : <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:time>' , releasetime ) <EOL> tc . submit ( ) <EOL> tc . url ( version_admin ) <EOL> tc . find ( name ) <EOL> tc . notfind ( internal_error ) <EOL> def create_report ( self , title , query , description ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_front ( ) <EOL> tc . follow ( r"<STR_LIT>" ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:action>' , '<STR_LIT>' ) <EOL> tc . submit ( ) <EOL> tc . find ( '<STR_LIT>' ) <EOL> tc . notfind ( internal_error ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:title>' , title ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:description>' , description ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , query ) <EOL> tc . submit ( ) <EOL> reportnum = b . get_url ( ) . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> return reportnum <EOL> def ticket_set_milestone ( self , ticketid , milestone ) : <EOL> """<STR_LIT>""" <EOL> self . go_to_ticket ( ticketid ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT>' , milestone ) <EOL> tc . submit ( '<STR_LIT>' ) <EOL> def _attach_file_to_resource ( self , realm , name , data = None , <EOL> filename = None , description = None , <EOL> replace = False , content_type = None ) : <EOL> """<STR_LIT>""" <EOL> if data is None : <EOL> data = random_page ( ) <EOL> if description is None : <EOL> description = random_sentence ( ) <EOL> if filename is None : <EOL> filename = random_word ( ) <EOL> tc . submit ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> tc . url ( self . url + r'<STR_LIT>' % ( realm , name ) ) <EOL> fp = StringIO ( data ) <EOL> tc . formfile ( '<STR_LIT>' , '<STR_LIT>' , filename , <EOL> content_type = content_type , fp = fp ) <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:description>' , description ) <EOL> if replace : <EOL> tc . formvalue ( '<STR_LIT>' , '<STR_LIT:replace>' , True ) <EOL> tc . submit ( ) <EOL> tc . url ( self . url + r'<STR_LIT>' % ( realm , name ) ) <EOL> return filename </s>
