Source

bloodhound-mq / t387 / t387_r1495238_functional_test.2.diff

# HG changeset patch
# Parent d404667f80fa2eb56f5bc4db0889b208d9e095bb
BH Multiproduct #387 : Bloodhound functional test cases (cont.)

diff -r d404667f80fa bloodhound_multiproduct/tests/functional/__init__.py
--- a/bloodhound_multiproduct/tests/functional/__init__.py	Mon Jul 01 23:35:39 2013 -0500
+++ b/bloodhound_multiproduct/tests/functional/__init__.py	Tue Jul 02 15:47:49 2013 -0500
@@ -333,7 +333,13 @@
 
     - Preferences link removed in Bloodhound UI
     - There's no such thing like ticket preview in Bloodhound UI
-    - 'Create New Ticket' label in new ticket page replaced by 'New Ticket' 
+    - 'Create New Ticket' label in new ticket page replaced by 'New Ticket'
+    - Ticket owner label changed from 'Owned by' to 'Assigned to' 
+    - Source files (*.py) files copied in /plugins folder not enabled ootb
+    - Twitter Bootstrap class="input-mini" added in 'Max items per page'
+      input control in query view.
+    - Ticket comment header changed 
+    - 'Page PageName created' is not shown anymore for new wiki page
 
     As a consequence some methods of Trac functional tester have to be updated.
     """
@@ -412,9 +418,9 @@
         """
         self.go_to_front()
         # [BLOODHOUND] View Tickets renamed to Tickets pointing at dashboard
-        tc.follow('Tickets')
+        tc.follow(r'\bTickets\b')
         tc.notfind(internal_error)
-        tc.follow('Reports')
+        tc.follow(r'\bReports\b')
         tc.notfind(internal_error)
         tc.formvalue('create_report', 'action', 'new') # select new report form
         tc.submit()
@@ -462,6 +468,32 @@
 
         return name
 
+    def create_wiki_page(self, page, content=None):
+        """Creates the specified wiki page, with random content if none is
+        provided.
+        """
+        if content == None:
+            content = random_page()
+        page_url = self.url + "/wiki/" + page
+        tc.go(page_url)
+        tc.url(page_url)
+        tc.find("The page %s does not exist." % page)
+        tc.formvalue('modifypage', 'action', 'edit')
+        tc.submit()
+        tc.url(page_url + r'\?action=edit')
+
+        tc.formvalue('edit', 'text', content)
+        tc.submit('save')
+        tc.url(page_url+'$')
+
+        # verify the event shows up in the timeline
+        self.go_to_timeline()
+        tc.formvalue('prefs', 'wiki', True)
+        tc.submit()
+
+        # [BLOODHOUND] No label 'Page CamelCase created'
+        tc.find("Your changes have been saved in version 1")
+
     def go_to_query(self):
         """Surf to the custom query page.
         """
@@ -473,6 +505,12 @@
         tc.follow('Custom Query')
         tc.url(self.url + '/query')
 
+    def quickjump(self, search):
+        """Do a quick search to jump to a page."""
+        tc.formvalue('mainsearch', 'q', search)
+        tc.submit()
+        tc.notfind(internal_error)
+
     # Bloodhound functional tester extensions
 
     def go_to_newticket(self):
@@ -513,10 +551,32 @@
 
         return self.ticketcount
 
+    @staticmethod
+    def regex_ticket_field(fieldname, fieldval):
+        return r'<td [^>]*\bid="vc-%s"[^>]*>\s*%s\s*</td>' % (fieldname, fieldval)
+
+    @staticmethod
+    def regex_owned_by(username):
+        return '(Assigned to(<[^>]*>|\\n| )*%s)' % username
+
+    @staticmethod
+    def regex_query_column_selector(fieldname, fieldlbl):
+        return r'<label>( |\n)*<input[^<]*value="custfield"[^<]*>' \
+                '( |\n)*<[^<]*>( |\n)*Custom Field( |\n)*</[^<]*>' \
+                '(.|\n)*</label>' % (fieldname, fieldlbl)
+
     def find_ticket_field(self, fieldname, fieldval):
         """Assert that expected value (pattern) matches value in ticket view
         """
-        tc.find(r'<td [^>]*\bid="vc-%s"[^>]*>\s*%s\s*</td>' % (fieldname, fieldval))
+        tc.find(self.regex_ticket_field(fieldname, fieldval))
+
+    def find_owned_by(self, username):
+        """Assert that a ticket is owned by a given user
+        """
+        tc.find(self.regex_owned_by(username))
+
+    def find_query_column_selector(self, fieldname, fieldlbl):
+        tc.find(self.regex_query_column_selector(fieldname, fieldlbl), 's')
 
 
 class BloodhoundGlobalEnvFunctionalTester(BloodhoundFunctionalTester):
@@ -609,6 +669,13 @@
         with self.in_defaut_product(self):
             return superobj.create_version(name, releasetime)
 
+#----------------
+# Twill's find command accepts regexes; some convenient but complex regexes
+# & regex factories are provided here :
+#----------------
+
+regex_owned_by = BloodhoundFunctionalTester.regex_owned_by
+regex_ticket_field = BloodhoundFunctionalTester.regex_ticket_field
 
 #----------------
 # Product-aware functional setup
@@ -680,8 +747,9 @@
 for mdl in (trac.ticket.tests.functional, trac.admin.tests.functional):
     for attr in dir(mdl):
         attr = getattr(mdl, attr)
-        if isclass(attr) and issubclass(attr, 
-                                        functional.FunctionalTwillTestCaseSetup):
+        if isclass(attr) and \
+                attr is not functional.FunctionalTwillTestCaseSetup and \
+                issubclass(attr, functional.FunctionalTwillTestCaseSetup):
             attr.BH_IN_DEFAULT_PRODUCT = True
 del attr, mdl
 
@@ -697,8 +765,14 @@
     suite.addTest(testcases.ErrorPageValidation())
     suite.addTest(testcases.RegressionTestTicket3663())
 
+    import trac.admin.tests
+    trac.admin.tests.functionalSuite(suite)
     import trac.versioncontrol.tests
     trac.versioncontrol.tests.functionalSuite(suite)
+    import trac.wiki.tests
+    trac.wiki.tests.functionalSuite(suite)
+    import trac.timeline.tests
+    trac.timeline.tests.functionalSuite(suite)
 
     # import trac.ticket.tests
     # trac.ticket.tests.functionalSuite(suite)
@@ -710,12 +784,6 @@
     import tests.functional.prefs
     tests.functional.prefs.functionalSuite(suite)
 
-    import trac.wiki.tests
-    trac.wiki.tests.functionalSuite(suite)
-    import trac.timeline.tests
-    trac.timeline.tests.functionalSuite(suite)
-    import trac.admin.tests
-    trac.admin.tests.functionalSuite(suite)
     # The db tests should be last since the backup test occurs there.
     import trac.db.tests
     trac.db.tests.functionalSuite(suite)
diff -r d404667f80fa bloodhound_multiproduct/tests/functional/ticket.py
--- a/bloodhound_multiproduct/tests/functional/ticket.py	Mon Jul 01 23:35:39 2013 -0500
+++ b/bloodhound_multiproduct/tests/functional/ticket.py	Tue Jul 02 15:47:49 2013 -0500
@@ -24,6 +24,8 @@
 
 from trac.ticket.tests.functional import *
 
+from tests.functional import regex_owned_by
+
 #----------------
 # Functional test cases for tickets (rewritten) 
 #----------------
@@ -301,6 +303,214 @@
         self._tester.find_ticket_field('newfield', querylinks) 
 
 
+class RegressionTestTicket5394b(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/5394 b
+        Order user list alphabetically on new ticket page
+        """
+        #FIXME : Test is missing a lot of context. See RegressionTestTicket5394a
+
+        # Must run after RegressionTestTicket5394a
+        self._tester.go_to_front()
+
+        # [BLOODHOUND] New Ticket => More fields (in create ticket menu)
+        self.go_to_newticket()
+
+        tc.find('Create New Ticket')
+
+        test_users = ['alice', 'bob', 'jane', 'john', 'charlie', 'alan',
+                      'zorro']
+        options = 'id="field-owner"[^>]*>[[:space:]]*<option/>.*' + \
+            '.*'.join(['<option[^>]*>%s</option>' % user for user in
+                     sorted(test_users + ['admin', 'user'])])
+        options = '.*'.join(sorted(test_users + ['admin', 'user']))
+        tc.find(options, 's')
+
+# FIXME: Verbatim copy of its peer just to override regex_owned_by
+class RegressionTestTicket5497a(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/5497 a
+        Open ticket, component changed, owner not changed"""
+        ticketid = self._tester.create_ticket("regression test 5497a")
+        self._tester.go_to_ticket(ticketid)
+        tc.formvalue('propertyform', 'field-component', 'regression5497')
+        tc.submit('submit')
+        tc.find(regex_owned_by('user'))
+
+
+# FIXME: Verbatim copy of its peer just to override regex_owned_by
+class RegressionTestTicket5497b(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/5497 b
+        Open ticket, component changed, owner changed"""
+        ticketid = self._tester.create_ticket("regression test 5497b")
+        self._tester.go_to_ticket(ticketid)
+        tc.formvalue('propertyform', 'field-component', 'regression5497')
+        tc.formvalue('propertyform', 'action', 'reassign')
+        tc.formvalue('propertyform', 'action_reassign_reassign_owner', 'admin')
+        tc.submit('submit')
+        tc.notfind(regex_owned_by('user'))
+        tc.find(regex_owned_by('admin'))
+
+
+# FIXME: Verbatim copy of its peer just to override regex_owned_by
+class RegressionTestTicket5497c(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/5497 c
+        New ticket, component changed, owner not changed"""
+        ticketid = self._tester.create_ticket("regression test 5497c",
+            {'component':'regression5497'})
+        self._tester.go_to_ticket(ticketid)
+        tc.find(regex_owned_by('user'))
+
+
+# FIXME: Verbatim copy of its peer just to override regex_owned_by
+class RegressionTestTicket5497d(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/5497 d
+        New ticket, component changed, owner changed"""
+        ticketid = self._tester.create_ticket("regression test 5497d",
+            {'component':'regression5497', 'owner':'admin'})
+        self._tester.go_to_ticket(ticketid)
+        tc.find(regex_owned_by('admin'))
+
+class RegressionTestRev5994(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of the column label fix in r5994"""
+        env = self._testenv.get_trac_environment()
+        env.config.set('ticket-custom', 'custfield', 'text')
+        env.config.set('ticket-custom', 'custfield.label', 'Custom Field')
+        env.config.save()
+        try:
+            self._testenv.restart()
+            self._tester.go_to_query()
+            self._tester.find_query_column_selector('custfield', 'Custom Field')
+        finally:
+            pass
+            #env.config.set('ticket', 'restrict_owner', 'no')
+            #env.config.save()
+            #self._testenv.restart()
+
+
+class RegressionTestTicket6048(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/6048"""
+        # Setup the DeleteTicket plugin
+        plugin = open(os.path.join(self._testenv.command_cwd, 'sample-plugins',
+                                   'workflow', 'DeleteTicket.py')).read()
+        open(os.path.join(self._testenv.tracdir, 'plugins', 'DeleteTicket.py'),
+             'w').write(plugin)
+        env = self._testenv.get_trac_environment()
+
+        # [BLOODHOUND] Ensure plugin will be enabled in target scope
+        env.config.set('components', 'DeleteTicket.*', 'enabled')
+
+        prevconfig = env.config.get('ticket', 'workflow')
+        env.config.set('ticket', 'workflow',
+                       prevconfig + ',DeleteTicketActionController')
+        env.config.save()
+        env = self._testenv.get_trac_environment() # reload environment
+
+        # Create a ticket and delete it
+        ticket_id = self._tester.create_ticket(
+            summary='RegressionTestTicket6048')
+        # (Create a second ticket so that the ticket id does not get reused
+        # and confuse the tester object.)
+        self._tester.create_ticket(summary='RegressionTestTicket6048b')
+        self._tester.go_to_ticket(ticket_id)
+        tc.find('delete ticket')
+        tc.formvalue('propertyform', 'action', 'delete')
+        tc.submit('submit')
+
+        self._tester.go_to_ticket(ticket_id)
+        tc.find('Error: Invalid ticket number')
+        tc.find('Ticket %s does not exist.' % ticket_id)
+
+        # Remove the DeleteTicket plugin
+        env.config.set('ticket', 'workflow', prevconfig)
+        env.config.save()
+        env = self._testenv.get_trac_environment() # reload environment
+        for ext in ('py', 'pyc', 'pyo'):
+            filename = os.path.join(self._testenv.tracdir, 'plugins',
+                                    'DeleteTicket.%s' % ext)
+            if os.path.exists(filename):
+                os.unlink(filename)
+
+
+class RegressionTestTicket7821group(FunctionalTwillTestCaseSetup):
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/7821 group"""
+        env = self._testenv.get_trac_environment()
+        saved_default_query = env.config.get('query', 'default_query')
+        default_query = 'status!=closed&order=status&group=status&max=42' \
+                        '&desc=1&groupdesc=1&col=summary|status|cc' \
+                        '&cc~=$USER'
+        env.config.set('query', 'default_query', default_query)
+        env.config.save()
+        try:
+            self._testenv.restart()
+            self._tester.create_ticket('RegressionTestTicket7821 group')
+            self._tester.go_to_query()
+            # $USER
+            tc.find('<input type="text" name="0_cc" value="admin"'
+                    ' size="[0-9]+" />')
+            # col
+            tc.find('<input type="checkbox" name="col" value="summary"'
+                    ' checked="checked" />')
+            tc.find('<input type="checkbox" name="col" value="owner" />')
+            tc.find('<input type="checkbox" name="col" value="status"'
+                    ' checked="checked" />')
+            tc.find('<input type="checkbox" name="col" value="cc"'
+                    ' checked="checked" />')
+            # group
+            tc.find('<option selected="selected" value="status">Status'
+                    '</option>')
+            # groupdesc
+            tc.find('<input type="checkbox" name="groupdesc" id="groupdesc"'
+                    ' checked="checked" />')
+            # max
+            # [BLOODHOUND] class="input-mini" added (Twitter Bootstrap)
+            tc.find('<input type="text" name="max" id="max" size="[0-9]*?"'
+                    ' value="42" [^/]*/>')
+            # col in results
+            tc.find('<a title="Sort by Ticket [(]ascending[)]" ')
+            tc.find('<a title="Sort by Summary [(]ascending[)]" ')
+            tc.find('<a title="Sort by Status [(]ascending[)]" ')
+            tc.find('<a title="Sort by Cc [(]ascending[)]" ')
+            tc.notfind('<a title="Sort by Owner "')
+        finally:
+            env.config.set('query', 'default_query', saved_default_query)
+            env.config.save()
+            self._testenv.restart()
+
+
+class RegressionTestTicket8247(FunctionalTwillTestCaseSetup):
+    BH_IN_DEFAULT_PRODUCT = True
+
+    def runTest(self):
+        """Test for regression of http://trac.edgewall.org/ticket/8247
+        Author field of ticket comment corresponding to the milestone removal
+        was always 'anonymous'.
+        """
+        name = "MilestoneRemove"
+        self._tester.create_milestone(name)
+        id = self._tester.create_ticket(info={'milestone': name})
+        ticket_url = self._tester.url + "/ticket/%d" % id
+        tc.go(ticket_url)
+        tc.find(name)
+        tc.go(self._tester.url + "/admin/ticket/milestones")
+        tc.formvalue('milestone_table', 'sel', name)
+        tc.submit('remove')
+        tc.go(ticket_url)
+
+        # [BLOODHOUND] Ticket comment header changed 
+        tc.find('<strong class="trac-field-milestone">Milestone</strong>'
+                '[ \n\t]*<span>[ \n\t]*<em>%s</em> deleted' % name)
+        tc.find('by admin<span>, <a.* ago</a></span>')
+
+        tc.notfind('anonymous')
+
+
 # Ensure that overridden code will be loaded
 def functionalSuite(suite=None):
     if not suite: