Source

bloodhound-mq / t355 / t355_r1434677_trac_test_attachments.diff

Full commit
# HG changeset patch
# Parent 281eab2731c5875af420bd81bb59196478d9c301
BH Multiproduct #355 : Rewrite attachment test cases for product environments

diff -r 281eab2731c5 bloodhound_multiproduct/multiproduct/env.py
--- a/bloodhound_multiproduct/multiproduct/env.py	Thu Jan 17 14:14:01 2013 +0000
+++ b/bloodhound_multiproduct/multiproduct/env.py	Fri Jan 18 01:08:28 2013 -0500
@@ -137,6 +137,14 @@
             raise AttributeError("'%s' object has no attribute '%s'" %
                     (self.__class__.__name__, attrnm))
 
+    @lazy
+    def path(self):
+        """The subfolder `./products/<product prefix>` relative to the 
+        top-level directory of the global environment will be the root of 
+        product file system area.
+        """
+        return os.path.join(self.parent.path, 'products', self.product.prefix)
+
     @property
     def setup_participants(self):
         """Setup participants list for product environments will always
@@ -267,7 +275,6 @@
 
         self.parent = env
         self.product = product
-        self.path = self.parent.path
         self.systeminfo = []
         self._href = self._abs_href = None
 
diff -r 281eab2731c5 bloodhound_multiproduct/tests/attachment.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bloodhound_multiproduct/tests/attachment.py	Fri Jan 18 01:08:28 2013 -0500
@@ -0,0 +1,72 @@
+
+#  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 attachments in product environments"""
+
+import shutil
+import os.path
+import unittest
+
+from trac.attachment import Attachment
+from trac.test import EnvironmentStub
+from trac.tests.attachment import AttachmentTestCase
+
+from multiproduct.env import ProductEnvironment
+from tests.env import MultiproductTestCase
+
+class ProductAttachmentTestCase(AttachmentTestCase, MultiproductTestCase):
+
+    def setUp(self):
+        try:
+            AttachmentTestCase.setUp(self)
+        except:
+            self.global_env = self.env
+            self.tearDown()
+            raise
+        else:
+            self.global_env = global_env = self.env
+            self._upgrade_mp(global_env)
+            self._setup_test_log(global_env)
+            self._load_product_from_data(global_env, self.default_product)
+            self.env = ProductEnvironment(global_env, self.default_product)
+            os.makedirs(self.env.path)
+
+            # Root folder for default product environment
+            self.attachments_dir = os.path.join(self.global_env.path,
+                    'products', self.default_product, 'files', 'attachments')
+
+    def tearDown(self):
+        if os.path.exists(self.global_env.path):
+            shutil.rmtree(self.global_env.path)
+        self.env.reset_db()
+
+    def test_product_path_isolation(self):
+        product_attachment = Attachment(self.env, 'ticket', '42')
+        global_attachment = Attachment(self.global_env, 'ticket', '42')
+        global_attachment.filename = product_attachment.filename = 'foo.txt'
+
+        self.assertNotEqual(product_attachment.path, global_attachment.path)
+
+def test_suite():
+    return unittest.TestSuite([
+            unittest.makeSuite(ProductAttachmentTestCase,'test'),
+        ])
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+
diff -r 281eab2731c5 bloodhound_multiproduct/tests/env.py
--- a/bloodhound_multiproduct/tests/env.py	Thu Jan 17 14:14:01 2013 +0000
+++ b/bloodhound_multiproduct/tests/env.py	Fri Jan 18 01:08:28 2013 -0500
@@ -209,6 +209,11 @@
         self._mp_setup()
         self.product_env = ProductEnvironment(self.env, self.default_product)
 
+    def tearDown(self):
+        # Release reference to transient environment mock object
+        self.env = None
+        self.product_env = None
+
     def test_attr_forward_parent(self):
         """Testing env.__getattr__"""
         class EnvironmentAttrSandbox(EnvironmentStub):
@@ -336,10 +341,10 @@
         self.assertIsNot(global_env[C], None)
         self.assertIs(product_env[C], None)
 
-    def tearDown(self):
-        # Release reference to transient environment mock object
-        self.env = None
-        self.product_env = None
+    def test_path(self):
+        """Testing env.path"""
+        self.assertEqual(self.product_env.path, 
+                os.path.join(self.env.path, 'products', self.default_product))
 
 def test_suite():
     return unittest.TestSuite([