1. Olemis Lang
  2. bloodhound-mq

Commits

Olemis Lang  committed 3cb1f3a

BH Multiproduct #355 : Rewrite Trac's test cases for ticket models. Load test data after MP upgrade

  • Participants
  • Parent commits 14366d6
  • Branches t355_trac_test_suite

Comments (0)

Files changed (2)

File series

View file
  • Ignore whitespace
 #t288/t288_r1438538_sql_translate_global_env.diff
-t288/t288_r1438538_sql_translate_global_env_pending.diff
-t288/t288_r1441419_sql_translate_cursor.diff
+#t288/t288_r1438538_sql_translate_global_env_pending.diff
+#t288/t288_r1441419_sql_translate_cursor.diff
 #t355/t355_r1440987_dbcursor_debug_sql.diff
 #t115/t115_r1437383_inherit_product_config.diff
 #t333/t333_r1427886_schema_autoinc.diff
 #t355/t355_r1434677_trac_test_attachments.diff
 #t355/t355_r1437383_pkgresources_discovery.diff
 #t355/t355_r1437383_trac_test_perm.diff
-t355/t355_r1437383_trac_test_ticket_api.diff
+#t355/t355_r1437383_trac_test_ticket_api.diff
 t355/t355_r1442601_trac_test_ticket_conversion.diff
-t355/t355_r1442601_trac_test_ticket_batch.diff
+t355/t355_r1442601_trac_test_ticket_model.diff
+#t355/t355_r1442601_trac_test_ticket_batch.diff

File t355/t355_r1442601_trac_test_ticket_model.diff

View file
  • Ignore whitespace
+# HG changeset patch
+# Parent 9aa39edce348e3bbf23a595bcdafee5fd8be18a6
+BH Multiproduct #355 : Rewrite Trac test cases for ticket models so as to run them against product environments
+
+diff -r 9aa39edce348 bloodhound_multiproduct/multiproduct/env.py
+--- a/bloodhound_multiproduct/multiproduct/env.py	Thu Feb 07 00:58:37 2013 -0500
++++ b/bloodhound_multiproduct/multiproduct/env.py	Thu Feb 07 01:38:57 2013 -0500
+@@ -105,7 +105,7 @@
+         self.parent = None
+         self.product = None
+         self.mpsystem = None
+-        super(EnvironmentStub, self).__init__(default_data=default_data,
++        super(EnvironmentStub, self).__init__(default_data=False,
+                                               enable=enable, disable=disable,
+                                               path=path, destroying=destroying)
+         # Apply multi product upgrades. This is required as the database proxy (translator)
+@@ -117,6 +117,9 @@
+         except OperationalError:
+             pass
+ 
++        if default_data:
++            self.reset_db(default_data)
++
+     def reset_db(self, default_data=None):
+         from multiproduct.api import DB_VERSION
+         schema_version = -1
+@@ -127,36 +130,6 @@
+             with self.db_direct_transaction as db:
+                 self.mpsystem._update_db_version(db, DB_VERSION)
+ 
+-    def enable_component(self, clsdef):
+-        r"""Enable a plugin temporarily at testing time.
+-        """
+-        self.config.set('components', clsdef, 'enabled')
+-        self.enabled.clear()
+-        try:
+-            del self._rules
+-        except AttributeError:
+-            pass
+-
+-    def disable_component(self, clsdef):
+-        r"""Disable a plugin temporarily at testing time.
+-        """
+-        self.config.set('components', clsdef, 'disabled')
+-        self.enabled.clear()
+-        try:
+-            del self._rules
+-        except AttributeError:
+-            pass
+-
+-    def rip_component(self, cls):
+-        r"""Disable a plugin forever and RIP it using the super-laser beam.
+-        """
+-        self.disable_component(cls)
+-        for reg in ComponentMeta._registry.itervalues():
+-            try:
+-                reg.remove(cls)
+-            except ValueError :
+-                pass
+-
+ 
+ # replace trac.test.EnvironmentStub
+ trac.test.EnvironmentStub = EnvironmentStub
+diff -r 9aa39edce348 bloodhound_multiproduct/tests/env.py
+--- a/bloodhound_multiproduct/tests/env.py	Thu Feb 07 00:58:37 2013 -0500
++++ b/bloodhound_multiproduct/tests/env.py	Thu Feb 07 01:38:57 2013 -0500
+@@ -116,13 +116,14 @@
+ 
+     # Test setup
+ 
+-    def _setup_test_env(self, create_folder=True, path=None):
++    def _setup_test_env(self, create_folder=True, path=None, **kwargs):
+         r"""Prepare a new test environment . 
+ 
+         Optionally set its path to a meaningful location (temp folder
+         if `path` is `None`).
+         """
+-        self.env = env = EnvironmentStub(enable=['trac.*', 'multiproduct.*'])
++        kwargs.setdefault('enable', ['trac.*', 'multiproduct.*'])
++        self.env = env = EnvironmentStub(**kwargs)
+         if create_folder:
+             if path is None:
+                 env.path = tempfile.mkdtemp('bh-product-tempenv')
+@@ -160,7 +161,7 @@
+     def _upgrade_mp(self, env):
+         r"""Apply multi product upgrades
+         """
+-        env.disable_component(env._component_name(TicketModule))
++        env.disable_component(TicketModule)
+         self.mpsystem = MultiProductSystem(env)
+         try:
+             self.mpsystem.upgrade_environment(env.db_transaction)
+@@ -342,6 +343,7 @@
+ 
+         # C enabled in global env but not in product env
+         global_env.enable_component(C)
++        product_env.disable_component(C)
+         self.assertTrue(global_env.is_component_enabled(C))
+         self.assertFalse(product_env.is_component_enabled_local(C))
+         self.assertIsNot(global_env[C], None)
+diff -r 9aa39edce348 bloodhound_multiproduct/tests/ticket/model.py
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/bloodhound_multiproduct/tests/ticket/model.py	Thu Feb 07 01:38:57 2013 -0500
+@@ -0,0 +1,61 @@
++
++#  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 model in product environments"""
++
++import unittest
++
++from trac.ticket.tests.model import TicketTestCase, TicketCommentTestCase, \
++        TicketCommentEditTestCase, TicketCommentDeleteTestCase, EnumTestCase, \
++        MilestoneTestCase, ComponentTestCase, VersionTestCase
++
++from multiproduct.env import ProductEnvironment
++from tests.env import MultiproductTestCase
++
++class ProductTicketTestCase(TicketTestCase, MultiproductTestCase):
++
++    def setUp(self):
++        self.global_env = self._setup_test_env(create_folder=False, 
++                default_data=True)
++        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.env.config.set('ticket-custom', 'foo', 'text')
++        self.env.config.set('ticket-custom', 'cbon', 'checkbox')
++        self.env.config.set('ticket-custom', 'cboff', 'checkbox')
++
++    def tearDown(self):
++        self.global_env.reset_db()
++
++
++def test_suite():
++    suite = unittest.TestSuite()
++    suite.addTest(unittest.makeSuite(ProductTicketTestCase, 'test'))
++#    suite.addTest(unittest.makeSuite(ProductTicketCommentEditTestCase, 'test'))
++#    suite.addTest(unittest.makeSuite(ProductTicketCommentDeleteTestCase, 'test'))
++#    suite.addTest(unittest.makeSuite(ProductEnumTestCase, 'test'))
++#    suite.addTest(unittest.makeSuite(ProductMilestoneTestCase, 'test'))
++#    suite.addTest(unittest.makeSuite(ProductComponentTestCase, 'test'))
++#    suite.addTest(unittest.makeSuite(ProductVersionTestCase, 'test'))
++    return suite
++
++if __name__ == '__main__':
++    unittest.main(defaultTest='test_suite')
++