Commits

Olemis Lang committed f4b8760

BH Multiproduct #387 : Augment functional testers API with 'find_ticket_field' function

Comments (0)

Files changed (1)

t387/t387_r1485255_functional_test_infra.diff

 
 diff -r ab4d5983c6ca bloodhound_multiproduct/tests/functional/__init__.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/functional/__init__.py	Tue Jun 11 13:29:14 2013 -0500
-@@ -0,0 +1,737 @@
++++ b/bloodhound_multiproduct/tests/functional/__init__.py	Wed Jun 12 00:07:46 2013 -0500
+@@ -0,0 +1,743 @@
 +# -*- coding: utf-8 -*-
 +#
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +    - View Tickets renamed to Tickets pointing at dashboard
 +    - Milestones `No date set` label replaced by `Unscheduled`
 +    - There's no actual button to submit `propertyform` in new ticket page
-+    - 'Create New Ticket' label in new ticket page replaced with 'New Ticket' 
++    - Different markup used to render ticket fields
 +
 +    Other notable differences not solved by this class (target test cases
 +    should be rewritten?)
 +
 +    - 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' 
 +
 +    As a consequence some methods of Trac functional tester have to be updated.
 +    """
 +
 +        return self.ticketcount
 +
++    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))
++
 +
 +class BloodhoundGlobalEnvFunctionalTester(BloodhoundFunctionalTester):
 +    """Library of higher-level operations for interacting with
 +del attr, mdl
 +
 +def trac_functionalSuite(suite):
-+#    from trac.tests.functional import testcases
-+#    suite.addTest(testcases.RegressionTestRev6017())
-+#    suite.addTest(testcases.RegressionTestTicket3833a())
-+#    suite.addTest(testcases.RegressionTestTicket3833b())
-+#    suite.addTest(testcases.RegressionTestTicket3833c())
-+#    suite.addTest(testcases.RegressionTestTicket5572())
-+#    suite.addTest(testcases.RegressionTestTicket7209())
-+#    suite.addTest(testcases.RegressionTestTicket9880())
-+#    suite.addTest(testcases.ErrorPageValidation())
-+#    suite.addTest(testcases.RegressionTestTicket3663())
-+#
-+#    import trac.versioncontrol.tests
-+#    trac.versioncontrol.tests.functionalSuite(suite)
++    from trac.tests.functional import testcases
++    suite.addTest(testcases.RegressionTestRev6017())
++    suite.addTest(testcases.RegressionTestTicket3833a())
++    suite.addTest(testcases.RegressionTestTicket3833b())
++    suite.addTest(testcases.RegressionTestTicket3833c())
++    suite.addTest(testcases.RegressionTestTicket5572())
++    suite.addTest(testcases.RegressionTestTicket7209())
++    suite.addTest(testcases.RegressionTestTicket9880())
++    suite.addTest(testcases.ErrorPageValidation())
++    suite.addTest(testcases.RegressionTestTicket3663())
 +
-+#    # import trac.ticket.tests
-+#    # trac.ticket.tests.functionalSuite(suite)
++    import trac.versioncontrol.tests
++    trac.versioncontrol.tests.functionalSuite(suite)
++
++    # import trac.ticket.tests
++    # trac.ticket.tests.functionalSuite(suite)
 +    import tests.functional.ticket
 +    tests.functional.ticket.functionalSuite(suite)
 +
-+#    # import trac.prefs.tests
-+#    # trac.prefs.tests.functionalSuite(suite)
-+#    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)
++    # import trac.prefs.tests
++    # trac.prefs.tests.functionalSuite(suite)
++    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)
 +
 +
 +def functionalSuite():
 +    unittest.main(defaultTest='test_suite')
 diff -r ab4d5983c6ca bloodhound_multiproduct/tests/functional/prefs.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/functional/prefs.py	Tue Jun 11 13:29:14 2013 -0500
++++ b/bloodhound_multiproduct/tests/functional/prefs.py	Wed Jun 12 00:07:46 2013 -0500
 @@ -0,0 +1,94 @@
 +# -*- coding: utf-8 -*-
 +#
 +    unittest.main(defaultTest='functionalSuite')
 diff -r ab4d5983c6ca bloodhound_multiproduct/tests/functional/ticket.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/functional/ticket.py	Tue Jun 11 13:29:14 2013 -0500
-@@ -0,0 +1,177 @@
++++ b/bloodhound_multiproduct/tests/functional/ticket.py	Wed Jun 12 00:07:46 2013 -0500
+@@ -0,0 +1,415 @@
 +# -*- coding: utf-8 -*-
 +#
 +#  Licensed to the Apache Software Foundation (ASF) under one
 +"""Override a few functional tests for tickets.
 +"""
 +
++from urlparse import urlsplit
++
 +from trac.ticket.tests.functional import *
 +
 +#----------------
 +        tc.find('ticket not yet created')
 +
 +
++class TestTicketCustomFieldTextNoFormat(FunctionalTwillTestCaseSetup):
++    def runTest(self):
++        """Test custom text field with no format explicitly specified.
++        Its contents should be rendered as plain text.
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'text')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'Another Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', '')
++        env.config.save()
++
++        self._testenv.restart()
++        val = "%s %s" % (random_unique_camel(), random_word())
++        ticketid = self._tester.create_ticket(summary=random_sentence(3),
++                                              info={'newfield': val})
++        self._tester.go_to_ticket(ticketid)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', val) 
++
++
++class TestTicketCustomFieldTextAreaNoFormat(FunctionalTwillTestCaseSetup):
++    def runTest(self):
++        """Test custom textarea field with no format explicitly specified,
++        its contents should be rendered as plain text.
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'textarea')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'Another Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', '')
++        env.config.save()
++
++        self._testenv.restart()
++        val = "%s %s" % (random_unique_camel(), random_word())
++        ticketid = self._tester.create_ticket(summary=random_sentence(3),
++                                              info={'newfield': val})
++        self._tester.go_to_ticket(ticketid)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', val)
++
++
++class TestTicketCustomFieldTextWikiFormat(FunctionalTwillTestCaseSetup):
++    def runTest(self):
++        """Test custom text field with `wiki` format.
++        Its contents should through the wiki engine, wiki-links and all.
++        Feature added in http://trac.edgewall.org/ticket/1791
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'text')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'Another Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', 'wiki')
++        env.config.save()
++
++        self._testenv.restart()
++        word1 = random_unique_camel()
++        word2 = random_word()
++        val = "%s %s" % (word1, word2)
++        ticketid = self._tester.create_ticket(summary=random_sentence(3),
++                                              info={'newfield': val})
++        self._tester.go_to_ticket(ticketid)
++        wiki = '<a [^>]*>%s\??</a> %s' % (word1, word2)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', wiki) 
++
++
++class TestTicketCustomFieldTextAreaWikiFormat(FunctionalTwillTestCaseSetup):
++    def runTest(self):
++        """Test custom textarea field with no format explicitly specified,
++        its contents should be rendered as plain text.
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'textarea')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'Another Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', 'wiki')
++        env.config.save()
++
++        self._testenv.restart()
++        word1 = random_unique_camel()
++        word2 = random_word()
++        val = "%s %s" % (word1, word2)
++        ticketid = self._tester.create_ticket(summary=random_sentence(3),
++                                              info={'newfield': val})
++        self._tester.go_to_ticket(ticketid)
++        wiki = '<p>\s*<a [^>]*>%s\??</a> %s<br />\s*</p>' % (word1, word2)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', wiki) 
++
++
++class TestTicketCustomFieldTextReferenceFormat(FunctionalTwillTestCaseSetup):
++    # Run this test case in default product context to keep body agnostic to
++    # context switching
++    BH_IN_DEFAULT_PRODUCT = True
++
++    def runTest(self):
++        """Test custom text field with `reference` format.
++        Its contents are treated as a single value
++        and are rendered as an auto-query link.
++        Feature added in http://trac.edgewall.org/ticket/10643
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'text')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'Another Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', 'reference')
++        env.config.save()
++
++        self._testenv.restart()
++        word1 = random_unique_camel()
++        word2 = random_word()
++        val = "%s %s" % (word1, word2)
++        ticketid = self._tester.create_ticket(summary=random_sentence(3),
++                                              info={'newfield': val})
++        self._tester.go_to_ticket(ticketid)
++        query = 'status=!closed&amp;newfield=%s\+%s' % (word1, word2)
++
++        path_prefix = urlsplit(self._tester.url).path
++        querylink = '<a href="%s/query\?%s">%s</a>' % (path_prefix, query, val)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', querylink) 
++
++
++class TestTicketCustomFieldTextListFormat(FunctionalTwillTestCaseSetup):
++    # Run this test case in default product context to keep body agnostic to
++    # context switching
++    BH_IN_DEFAULT_PRODUCT = True
++
++    def runTest(self):
++        """Test custom text field with `list` format.
++        Its contents are treated as a space-separated list of values
++        and are rendered as separate auto-query links per word.
++        Feature added in http://trac.edgewall.org/ticket/10643
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'text')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'Another Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', 'list')
++        env.config.save()
++
++        self._testenv.restart()
++        word1 = random_unique_camel()
++        word2 = random_word()
++        val = "%s %s" % (word1, word2)
++        ticketid = self._tester.create_ticket(summary=random_sentence(3),
++                                              info={'newfield': val})
++        self._tester.go_to_ticket(ticketid)
++        query1 = 'status=!closed&amp;newfield=~%s' % word1
++        query2 = 'status=!closed&amp;newfield=~%s' % word2
++
++        path_prefix = urlsplit(self._tester.url).path
++        querylink1 = '<a href="%s/query\?%s">%s</a>' % (path_prefix,
++                                                        query1, word1)
++        querylink2 = '<a href="%s/query\?%s">%s</a>' % (path_prefix,
++                                                        query2, word2)
++        querylinks = '%s %s' % (querylink1, querylink2)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', querylinks) 
++
++
++class RegressionTestTicket10828(FunctionalTwillTestCaseSetup):
++    # Run this test case in default product context to keep body agnostic to
++    # context switching
++    BH_IN_DEFAULT_PRODUCT = True
++
++    def runTest(self):
++        """Test for regression of http://trac.edgewall.org/ticket/10828
++        Rendered property changes should be described as lists of added and
++        removed items, even in the presence of comma and semicolon separators.
++        """
++        env = self._testenv.get_trac_environment()
++        env.config.set('ticket-custom', 'newfield', 'text')
++        env.config.set('ticket-custom', 'newfield.label',
++                       'A Custom Field')
++        env.config.set('ticket-custom', 'newfield.format', 'list')
++        env.config.save()
++
++        self._testenv.restart()
++        ticketid = self._tester.create_ticket(summary=random_sentence(3))
++        self._tester.go_to_ticket(ticketid)
++
++        word1 = random_unique_camel()
++        word2 = random_word()
++        val = "%s %s" % (word1, word2)
++        tc.formvalue('propertyform', 'field-newfield', val)
++        tc.submit('submit')
++        tc.find('<em>%s</em> <em>%s</em> added' % (word1, word2))
++
++        word3 = random_unique_camel()
++        word4 = random_unique_camel()
++        val = "%s,  %s; %s" % (word2, word3, word4)
++        tc.formvalue('propertyform', 'field-newfield', val)
++        tc.submit('submit')
++        tc.find('<em>%s</em> <em>%s</em> added; <em>%s</em> removed'
++                % (word3, word4, word1))
++
++        tc.formvalue('propertyform', 'field-newfield', '')
++        tc.submit('submit')
++        tc.find('<em>%s</em> <em>%s</em> <em>%s</em> removed'
++                % (word2, word3, word4))
++
++        val = "%s %s,%s" % (word1, word2, word3)
++        tc.formvalue('propertyform', 'field-newfield', val)
++        tc.submit('submit')
++        tc.find('<em>%s</em> <em>%s</em> <em>%s</em> added'
++                % (word1, word2, word3))
++        query1 = 'status=!closed&amp;newfield=~%s' % word1
++        query2 = 'status=!closed&amp;newfield=~%s' % word2
++        query3 = 'status=!closed&amp;newfield=~%s' % word3
++
++        
++        path_prefix = urlsplit(self._tester.url).path
++        querylink1 = '<a href="%s/query\?%s">%s</a>' % (path_prefix,
++                                                        query1, word1)
++        querylink2 = '<a href="%s/query\?%s">%s</a>' % (path_prefix,
++                                                        query2, word2)
++        querylink3 = '<a href="%s/query\?%s">%s</a>' % (path_prefix,
++                                                        query3, word3)
++        querylinks = '%s %s, %s' % (querylink1, querylink2, querylink3)
++
++        # [BLOODHOUND] Different markup to render field values
++        self._tester.find_ticket_field('newfield', querylinks) 
++
++
 +# Ensure that overridden code will be loaded
 +def functionalSuite(suite=None):
 +    if not suite:
 +        import trac.tests.functional.testcases
 +        suite = trac.tests.functional.testcases.functionalSuite()
++
 +    suite.addTest(TestTickets())
 +
 +    # [BLOODHOUND] there's no such thing like ticket preview
 +    suite.addTest(TestTicketCSVFormat())
 +    suite.addTest(TestTicketTabFormat())
 +    suite.addTest(TestTicketRSSFormat())
-+    suite.addTest(TestTicketSearch())
-+    suite.addTest(TestNonTicketSearch())
++
++    # [BLOODHOUND] TODO: Move to BloodhoundSearch plugin 
++    # suite.addTest(TestTicketSearch())
++    # suite.addTest(TestNonTicketSearch())
++
 +    suite.addTest(TestTicketHistory())
 +    suite.addTest(TestTicketHistoryDiff())
 +    suite.addTest(TestTicketQueryLinks())
 +    unittest.main(defaultTest='functionalSuite')
 diff -r ab4d5983c6ca trac/trac/tests/functional/__init__.py
 --- a/trac/trac/tests/functional/__init__.py	Wed Jun 05 14:34:14 2013 -0500
-+++ b/trac/trac/tests/functional/__init__.py	Tue Jun 11 13:29:14 2013 -0500
++++ b/trac/trac/tests/functional/__init__.py	Wed Jun 12 00:07:46 2013 -0500
 @@ -104,6 +104,8 @@
          else:
              env_class = FunctionalTestEnvironment