📄 functional.py
字号:
#!/usr/bin/pythonimport osimport refrom datetime import datetime, timedeltafrom trac.tests.functional import *from trac.util.datefmt import utc, localtz, format_dateclass TestTickets(FunctionalTwillTestCaseSetup): def runTest(self): """Create a ticket, comment on it, and attach a file""" # TODO: this should be split into multiple tests summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.create_ticket() self._tester.add_comment(ticketid) self._tester.attach_file_to_ticket(ticketid)class TestTicketPreview(FunctionalTwillTestCaseSetup): def runTest(self): """Preview ticket creation""" self._tester.go_to_front() tc.follow('New Ticket') summary = random_sentence(5) desc = random_sentence(5) tc.formvalue('propertyform', 'field-summary', summary) tc.formvalue('propertyform', 'field-description', desc) tc.submit('preview') tc.url(self._tester.url + '/newticket$') tc.find('ticket not yet created') tc.find(summary) tc.find(desc)class TestTicketNoSummary(FunctionalTwillTestCaseSetup): def runTest(self): """Creating a ticket without summary should fail""" self._tester.go_to_front() tc.follow('New Ticket') desc = random_sentence(5) tc.formvalue('propertyform', 'field-description', desc) tc.submit('submit') tc.find(desc) tc.find('Tickets must contain a summary.') tc.find('Create New Ticket') tc.find('ticket not yet created')class TestTicketAltFormats(FunctionalTestCaseSetup): def runTest(self): """Download ticket in alternative formats""" summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.go_to_ticket(ticketid) for format in ['Comma-delimited Text', 'Tab-delimited Text', 'RSS Feed']: tc.follow(format) content = b.get_html() if content.find(summary) < 0: raise AssertionError('Summary missing from %s format' % format) tc.back()class TestTicketCSVFormat(FunctionalTestCaseSetup): def runTest(self): """Download ticket in CSV format""" summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.go_to_ticket(ticketid) tc.follow('Comma-delimited Text') csv = b.get_html() if not csv.startswith('id,summary,'): raise AssertionError('Bad CSV format')class TestTicketTabFormat(FunctionalTestCaseSetup): def runTest(self): """Download ticket in Tab-delimitted format""" summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.go_to_ticket(ticketid) tc.follow('Tab-delimited Text') tab = b.get_html() if not tab.startswith('id\tsummary\t'): raise AssertionError('Bad tab delimitted format')class TestTicketRSSFormat(FunctionalTestCaseSetup): def runTest(self): """Download ticket in RSS format""" summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.go_to_ticket(ticketid) # Make a number of changes to exercise all of the RSS feed code self._tester.go_to_ticket(ticketid) tc.formvalue('propertyform', 'comment', random_sentence(3)) tc.formvalue('propertyform', 'field-type', 'task') tc.formvalue('propertyform', 'description', summary + '\n\n' + random_sentence(8)) tc.formvalue('propertyform', 'field-keywords', 'key') tc.submit('submit') time.sleep(1) # Have to wait a second tc.formvalue('propertyform', 'field-keywords', '') tc.submit('submit') tc.find('RSS Feed') tc.follow('RSS Feed') rss = b.get_html() if not rss.startswith('<?xml version="1.0"?>'): raise AssertionError('RSS Feed not valid feed')class TestTicketSearch(FunctionalTwillTestCaseSetup): def runTest(self): """Test ticket search""" summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.go_to_front() tc.follow('Search') tc.formvalue('fullsearch', 'ticket', True) tc.formvalue('fullsearch', 'q', summary) tc.submit('Search') tc.find('class="searchable">.*' + summary) tc.notfind('No matches found')class TestNonTicketSearch(FunctionalTwillTestCaseSetup): def runTest(self): """Test non-ticket search""" # Create a summary containing only unique words summary = ' '.join([random_word() + '_TestNonTicketSearch' for i in range(5)]) ticketid = self._tester.create_ticket(summary) self._tester.go_to_front() tc.follow('Search') tc.formvalue('fullsearch', 'ticket', False) tc.formvalue('fullsearch', 'q', summary) tc.submit('Search') tc.notfind('class="searchable">' + summary) tc.find('No matches found')class TestTicketHistory(FunctionalTwillTestCaseSetup): def runTest(self): """Test ticket history""" summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) comment = random_sentence(5) self._tester.add_comment(ticketid, comment=comment) self._tester.go_to_ticket(ticketid) url = b.get_url() tc.go(url + '?version=0') tc.find('at <[^>]*>*Initial Version') tc.find(summary) tc.notfind(comment) tc.go(url + '?version=1') tc.find('at <[^>]*>*Version 1') tc.find(summary) tc.find(comment)class TestTicketHistoryDiff(FunctionalTwillTestCaseSetup): def runTest(self): """Test ticket history""" name = 'TestTicketHistoryDiff' ticketid = self._tester.create_ticket(name) self._tester.go_to_ticket(ticketid) tc.formvalue tc.formvalue('propertyform', 'description', random_sentence(6)) tc.submit('submit') tc.find('description<[^>]*>\\s*modified \\(<[^>]*>diff', 's') tc.follow('diff') tc.find('Changes\\s*between\\s*<[^>]*>Initial Version<[^>]*>\\s*and' \ '\\s*<[^>]*>Version 1<[^>]*>\\s*of\\s*<[^>]*>Ticket #' , 's')class TestTicketQueryLinks(FunctionalTwillTestCaseSetup): def runTest(self): """Test ticket query links""" count = 3 ticket_ids = [self._tester.create_ticket( summary='TestTicketQueryLinks%s' % i) for i in range(count)] self._tester.go_to_query() # We don't have the luxury of javascript, so this is a multi-step # process tc.formvalue('query', 'add_filter', 'summary') tc.submit('add') tc.formvalue('query', 'owner', 'nothing') tc.submit('rm_filter_owner_0') tc.formvalue('query', 'summary', 'TestTicketQueryLinks') tc.submit('update') query_url = b.get_url() for i in range(count): tc.find('TestTicketQueryLinks%s' % i) tc.follow('TestTicketQueryLinks0') tc.find('class="missing">← Previous Ticket') tc.find('title="Ticket #%s">Next Ticket' % ticket_ids[1]) tc.follow('Back to Query') tc.url(re.escape(query_url)) tc.follow('TestTicketQueryLinks1') tc.find('title="Ticket #%s">Previous Ticket' % ticket_ids[0]) tc.find('title="Ticket #%s">Next Ticket' % ticket_ids[2]) tc.follow('Next Ticket') tc.find('title="Ticket #%s">Previous Ticket' % ticket_ids[1]) tc.find('class="missing">Next Ticket →')class TestTimelineTicketDetails(FunctionalTwillTestCaseSetup): def runTest(self): """Test ticket details on timeline""" env = self._testenv.get_trac_environment() env.config.set('timeline', 'ticket_show_details', 'yes') env.config.save() summary = random_sentence(5) ticketid = self._tester.create_ticket(summary) self._tester.go_to_ticket(ticketid) self._tester.add_comment(ticketid) self._tester.go_to_timeline() tc.formvalue('prefs', 'ticket_details', True) tc.submit() htmltags = '(<[^>]*>)*' tc.find('Ticket ' + htmltags + '#' + str(ticketid) + htmltags + ' \\(' + summary + '\\) updated\\s+by\\s+' + htmltags + 'admin', 's')class TestAdminComponent(FunctionalTwillTestCaseSetup): def runTest(self): """Admin create component""" self._tester.create_component()class TestAdminComponentDuplicates(FunctionalTwillTestCaseSetup): def runTest(self): """Admin create duplicate component""" name = "DuplicateMilestone" self._tester.create_component(name) component_url = self._tester.url + "/admin/ticket/components" tc.go(component_url) tc.formvalue('addcomponent', 'name', name) tc.submit() tc.notfind(internal_error) tc.find('Component .* already exists')class TestAdminComponentRemoval(FunctionalTwillTestCaseSetup): def runTest(self): """Admin remove component""" name = "RemovalComponent" self._tester.create_component(name) component_url = self._tester.url + "/admin/ticket/components" tc.go(component_url) tc.formvalue('component_table', 'sel', name) tc.submit('remove') tc.notfind(name)class TestAdminComponentNonRemoval(FunctionalTwillTestCaseSetup): def runTest(self): """Admin remove no selected component""" component_url = self._tester.url + "/admin/ticket/components" tc.go(component_url) tc.formvalue('component_table', 'remove', 'Remove selected items') tc.submit('remove') tc.find('No component selected')class TestAdminComponentDefault(FunctionalTwillTestCaseSetup): def runTest(self): """Admin set default component""" name = "DefaultComponent" self._tester.create_component(name) component_url = self._tester.url + "/admin/ticket/components" tc.go(component_url) tc.formvalue('component_table', 'default', name) tc.submit('apply') tc.find('type="radio" name="default" value="%s" checked="checked"' % \ name) tc.go(self._tester.url + '/newticket') tc.find('<option selected="selected">%s</option>' % name)class TestAdminComponentDetail(FunctionalTwillTestCaseSetup): def runTest(self): """Admin component detail""" name = "DetailComponent" self._tester.create_component(name) component_url = self._tester.url + "/admin/ticket/components" tc.go(component_url) tc.follow(name) desc = 'Some component description' tc.formvalue('modcomp', 'description', desc) tc.submit('cancel') tc.url(component_url + '$') tc.follow(name) tc.notfind(desc)class TestAdminMilestone(FunctionalTwillTestCaseSetup): def runTest(self): """Admin create milestone""" self._tester.create_milestone()class TestAdminMilestoneSpace(FunctionalTwillTestCaseSetup): def runTest(self): """Admin create milestone with a space""" self._tester.create_milestone('Milestone 1')class TestAdminMilestoneDuplicates(FunctionalTwillTestCaseSetup): def runTest(self): """Admin create duplicate milestone""" name = "DuplicateMilestone" self._tester.create_milestone(name) milestone_url = self._tester.url + "/admin/ticket/milestones" tc.go(milestone_url) tc.url(milestone_url) tc.formvalue('addmilestone', 'name', name) tc.submit() tc.notfind(internal_error) tc.find('Milestone %s already exists' % name) tc.notfind('%s')class TestAdminMilestoneDetail(FunctionalTwillTestCaseSetup): def runTest(self): """Admin modify milestone details""" name = "DetailMilestone" # Create a milestone self._tester.create_milestone(name) # Modify the details of the milestone milestone_url = self._tester.url + "/admin/ticket/milestones" tc.go(milestone_url) tc.url(milestone_url)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -