Source

bloodhound-mq / t355 / t355_r1442601_trac_test_ticket_model.diff

# HG changeset patch
# Parent ffa449d01a4d589e2212fdab839ae364e9c83c6c
BH Multiproduct #355 : Rewrite Trac test cases for ticket models so as to run them against product environments

diff -r ffa449d01a4d bloodhound_multiproduct/multiproduct/env.py
--- a/bloodhound_multiproduct/multiproduct/env.py	Thu Feb 07 03:23:00 2013 -0500
+++ b/bloodhound_multiproduct/multiproduct/env.py	Thu Feb 07 03:31:22 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
diff -r ffa449d01a4d bloodhound_multiproduct/tests/env.py
--- a/bloodhound_multiproduct/tests/env.py	Thu Feb 07 03:23:00 2013 -0500
+++ b/bloodhound_multiproduct/tests/env.py	Thu Feb 07 03:31:22 2013 -0500
@@ -117,13 +117,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')
diff -r ffa449d01a4d 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 03:31:22 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')
+