Commits

Olemis Lang committed 4a8dca6

BH Multiproduct #355 : Base URL for product envs. Test cases for batch ticket ops ... ok

  • Participants
  • Parent commits 38c1f99
  • Branches t355_trac_test_suite

Comments (0)

Files changed (3)

 #t355/t355_r1442601_trac_test_ticket_conversion.diff
 #t355/t355_r1442601_trac_test_ticket_model.diff
 #t355/t355_r1442601_trac_test_ticket_enum.diff
-#t355/t355_r1442601_trac_test_ticket_batch.diff
+t355/t355_r1444754_trac_test_ticket_batch.diff

t355/t355_r1442601_trac_test_ticket_batch.diff

-# HG changeset patch
-# Parent 79b0b3cbb7de0c316daf012d19876f52761a98bd
-BH Multiproduct #355 : Rewrite Trac test cases for batch ticket updates so as to run them against product environments
-
-diff -r 79b0b3cbb7de bloodhound_multiproduct/tests/ticket/batch.py
---- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/bloodhound_multiproduct/tests/ticket/batch.py	Wed Feb 06 00:45:53 2013 -0500
-@@ -0,0 +1,93 @@
-+
-+#  Licensed to the Apache Software Foundation (ASF) under one
-+#  or more contributor license agreements.  See the NOTICE file
-+#  distributed with this work for additional information
-+#  regarding copyright ownership.  The ASF licenses this file
-+#  to you under the Apache License, Version 2.0 (the
-+#  "License"); you may not use this file except in compliance
-+#  with the License.  You may obtain a copy of the License at
-+#
-+#   http://www.apache.org/licenses/LICENSE-2.0
-+#
-+#  Unless required by applicable law or agreed to in writing,
-+#  software distributed under the License is distributed on an
-+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-+#  KIND, either express or implied.  See the License for the
-+#  specific language governing permissions and limitations
-+#  under the License.
-+
-+"""Tests for Apache(TM) Bloodhound's tickets API in product environments"""
-+
-+import unittest
-+
-+from trac.perm import PermissionCache
-+from trac.test import Mock
-+from trac.ticket.batch import BatchModifyModule
-+from trac.ticket.tests.batch import BatchModifyTestCase
-+from trac.util.datefmt import utc
-+
-+from multiproduct.env import ProductEnvironment
-+from tests.env import MultiproductTestCase
-+
-+class ProductBatchModifyTestCase(BatchModifyTestCase, MultiproductTestCase):
-+
-+    def setUp(self):
-+        self.global_env = self._setup_test_env(create_folder=False)
-+        self._upgrade_mp(self.global_env)
-+        self._setup_test_log(self.global_env)
-+        self._load_product_from_data(self.global_env, self.default_product)
-+        self.env = ProductEnvironment(self.global_env, self.default_product)
-+
-+        self.perm = PermissionSystem(self.env)
-+        self.ticket_system = TicketSystem(self.env)
-+        self.req = Mock()
-+
-+    def tearDown(self):
-+        self.global_env.reset_db()
-+
-+    def test_custom_field_isolation(self):
-+        self.env.config.set('ticket-custom', 'test', 'select')
-+        self.env.config.set('ticket-custom', 'test.label', 'Test')
-+        self.env.config.set('ticket-custom', 'test.value', '1')
-+        self.env.config.set('ticket-custom', 'test.options', 'option1|option2')
-+
-+        self.global_env.config.set('ticket-custom', 'test', 'text')
-+        self.global_env.config.set('ticket-custom', 'test.label', 'Test')
-+        self.global_env.config.set('ticket-custom', 'test.value', 'Foo bar')
-+        self.global_env.config.set('ticket-custom', 'test.format', 'wiki')
-+
-+        product_fields = TicketSystem(self.env).get_custom_fields()
-+        global_fields = TicketSystem(self.global_env).get_custom_fields()
-+
-+        self.assertEqual({'name': 'test', 'type': 'select', 'label': 'Test',
-+                          'value': '1', 'options': ['option1', 'option2'],
-+                          'order': 0},
-+                         product_fields[0])
-+        self.assertEqual({'name': 'test', 'type': 'text', 'label': 'Test',
-+                          'value': 'Foo bar', 'order': 0, 'format': 'wiki'},
-+                         global_fields[0])
-+
-+    def test_available_actions_isolation(self):
-+        # Grant TICKET_CREATE in product environment ...
-+        self.perm.grant_permission('anonymous', 'TICKET_CREATE')
-+        self.req.perm = PermissionCache(self.env)
-+        self.assertEqual(['leave', 'reopen'],
-+                         self._get_actions({'status': 'closed'}))
-+
-+        # ... but no perms in global environment
-+        self.req.perm = PermissionCache(self.global_env)
-+        product_env = self.env
-+        try:
-+            self.env = self.global_env
-+            self.assertEqual(['leave'], self._get_actions({'status': 'closed'}))
-+        finally:
-+            self.env = product_env
-+
-+def test_suite():
-+    return unittest.TestSuite([
-+            unittest.makeSuite(ProductTicketSystemTestCase,'test'),
-+        ])
-+
-+if __name__ == '__main__':
-+    unittest.main(defaultTest='test_suite')
-+

t355/t355_r1444754_trac_test_ticket_batch.diff

+# HG changeset patch
+# Parent cf0ddd5cff5431dbb9863630582cf889bcbb6895
+BH Multiproduct #355 : Rewrite Trac test cases for batch ticket updates so as to run them against product environments
+
+diff -r cf0ddd5cff54 bloodhound_multiproduct/multiproduct/api.py
+--- a/bloodhound_multiproduct/multiproduct/api.py	Tue Feb 12 22:57:35 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/api.py	Wed Feb 13 01:40:24 2013 -0500
+@@ -24,7 +24,7 @@
+ import copy
+ 
+ from pkg_resources import resource_filename
+-from trac.config import PathOption
++from trac.config import Option, PathOption
+ from trac.core import Component, TracError, implements
+ from trac.db import Table, Column, DatabaseManager, Index
+ from trac.env import IEnvironmentSetupParticipant
+@@ -46,6 +46,19 @@
+     implements(IEnvironmentSetupParticipant, ITemplateProvider,
+             IPermissionRequestor, ITicketFieldProvider, IResourceManager)
+ 
++    product_base_url = Option('multiproduct', 'product_base_url', ''
++        """A pattern used to generate the base URL of product environments,
++        e.g. the use cases listed in bh:wiki:/Proposals/BEP-0003#url-mapping .
++        Both absolute as well as relative URLs are supported. The later 
++        will be resolved with respect to the base URL of the parent global
++        environment. The pattern may contain references to $(prefix)s and 
++        $(name)s placeholders representing the product prefix and name
++        respectively . If nothing is set the following will be used 
++        `products/$(prefix)s`
++
++        Note the usage of $(...)s instead of %(...)s as the later form 
++        would be interpreted by the ConfigParser itself. """)
++
+     product_config_parent = PathOption('inherit', 'multiproduct', '',
+         """The path to the configuration file containing the settings shared
+         by sibling product environments. By default will inherit 
+diff -r cf0ddd5cff54 bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Tue Feb 12 22:57:35 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/env.py	Wed Feb 13 01:40:24 2013 -0500
+@@ -22,7 +22,7 @@
+ from urlparse import urlsplit
+ from sqlite3 import OperationalError
+ 
+-from trac.config import ConfigSection, Option
++from trac.config import BoolOption, ConfigSection, Option
+ from trac.core import Component, ComponentManager, implements
+ from trac.db.api import TransactionContextManager, QueryContextManager
+ from trac.util import get_pkginfo, lazy
+@@ -240,11 +240,25 @@
+         """
+         return ''
+ 
+-    # TODO: Estimate product base URL considering global base URL, pattern, ...
+-    base_url = ''
++    base_url = Option('trac', 'base_url', '',
++        """Reference URL for the Trac deployment.
++        
++        This is the base URL that will be used when producing
++        documents that will be used outside of the web browsing
++        context, like for example when inserting URLs pointing to Trac
++        resources in notification e-mails.""")
+ 
+-    # TODO: Estimate product base URL considering global base URL, pattern, ...
+-    base_url_for_redirect = ''
++    base_url_for_redirect = BoolOption('trac', 'use_base_url_for_redirect',
++            False, 
++        """Optionally use `[trac] base_url` for redirects.
++        
++        In some configurations, usually involving running Trac behind
++        a HTTP proxy, Trac can't automatically reconstruct the URL
++        that is used to access it. You may need to use this option to
++        force Trac to use the `base_url` setting also for
++        redirects. This introduces the obvious limitation that this
++        environment will only be usable when accessible from that URL,
++        as redirects are frequently used. ''(since 0.10.5)''""")
+ 
+     @property
+     def project_name(self):
+@@ -590,9 +604,16 @@
+         """The application URL"""
+         if not self._abs_href:
+             if not self.base_url:
+-                self.log.warn("base_url option not set in configuration, "
+-                              "generated links may be incorrect")
+-                self._abs_href = Href('')
++                urlpattern = MultiProductSystem(self.parent).product_base_url
++                if not urlpattern:
++                    self.log.warn("product_base_url option not set in "
++                                  "configuration, generated links may be "
++                                  "incorrect")
++                    urlpattern = 'product/$(prefix)s'
++                url = urlpattern.replace('$(', '%(') \
++                     .replace('%(prefix)s', self.product.prefix) \
++                     .replace('%(name)s', self.product.name)
++                self._abs_href = Href(self.parent.abs_href(url))
+             else:
+                 self._abs_href = Href(self.base_url)
+         return self._abs_href
+diff -r cf0ddd5cff54 bloodhound_multiproduct/tests/ticket/batch.py
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/bloodhound_multiproduct/tests/ticket/batch.py	Wed Feb 13 01:40:24 2013 -0500
+@@ -0,0 +1,65 @@
++
++#  Licensed to the Apache Software Foundation (ASF) under one
++#  or more contributor license agreements.  See the NOTICE file
++#  distributed with this work for additional information
++#  regarding copyright ownership.  The ASF licenses this file
++#  to you under the Apache License, Version 2.0 (the
++#  "License"); you may not use this file except in compliance
++#  with the License.  You may obtain a copy of the License at
++#
++#   http://www.apache.org/licenses/LICENSE-2.0
++#
++#  Unless required by applicable law or agreed to in writing,
++#  software distributed under the License is distributed on an
++#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
++#  KIND, either express or implied.  See the License for the
++#  specific language governing permissions and limitations
++#  under the License.
++
++"""Tests for Apache(TM) Bloodhound's tickets API in product environments"""
++
++import unittest
++
++from trac.perm import PermissionCache
++from trac.test import Mock
++from trac.ticket.batch import BatchModifyModule
++from trac.ticket.tests.batch import BatchModifyTestCase
++from trac.ticket.default_workflow import ConfigurableTicketWorkflow
++from trac.util.datefmt import utc
++
++from multiproduct.env import ProductEnvironment
++from multiproduct.ticket.web_ui import ProductTicketModule
++from tests.env import MultiproductTestCase
++
++class ProductBatchModifyTestCase(BatchModifyTestCase, MultiproductTestCase):
++
++    def setUp(self):
++        self.global_env = self._setup_test_env(create_folder=False)
++        self._upgrade_mp(self.global_env)
++        self._setup_test_log(self.global_env)
++        self._load_product_from_data(self.global_env, self.default_product)
++        self.env = ProductEnvironment(self.global_env, self.default_product)
++
++        self.global_env.enable_component_in_config(self.env, 
++                ConfigurableTicketWorkflow)
++        self.global_env.enable_component_in_config(self.env, 
++                ProductTicketModule)
++
++        self._load_default_data(self.env)
++
++        self.req = Mock(href=self.env.href, authname='anonymous', tz=utc)
++        self.req.session = {}
++        self.req.perm = PermissionCache(self.env)
++
++    def tearDown(self):
++        self.global_env.reset_db()
++
++
++def test_suite():
++    return unittest.TestSuite([
++            unittest.makeSuite(ProductBatchModifyTestCase,'test'),
++        ])
++
++if __name__ == '__main__':
++    unittest.main(defaultTest='test_suite')
++