Author: dammina
Date: Sun Aug 17 15:03:28 2014
New Revision: 1618477

URL: http://svn.apache.org/r1618477
Log:
Fixed some errors in documentation. Initial work on adding unit tests.

Added:
    
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/
    
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/__init__.py
   (with props)
    
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/theme.py
   (with props)
Modified:
    
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py

Added: 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/__init__.py
URL: 
http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/__init__.py?rev=1618477&view=auto
==============================================================================
--- 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/__init__.py
 (added)
+++ 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/__init__.py
 Sun Aug 17 15:03:28 2014
@@ -0,0 +1,35 @@
+# -*- coding: UTF-8 -*-
+
+#  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.
+
+try:
+    import unittest2 as unittest
+except ImportError:
+    import unittest
+
+from bhtheme.tests import theme
+
+
+def suite():
+    test_suite = unittest.TestSuite()
+    test_suite.addTest(theme.suite())
+    return test_suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')

Propchange: 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/__init__.py
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/theme.py
URL: 
http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/theme.py?rev=1618477&view=auto
==============================================================================
--- 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/theme.py
 (added)
+++ 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/theme.py
 Sun Aug 17 15:03:28 2014
@@ -0,0 +1,115 @@
+# -*- coding: UTF-8 -*-
+
+#  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.
+
+from trac.test import EnvironmentStub, Mock, MockPerm
+from trac.util.datefmt import utc
+from trac.web.chrome import Chrome
+from trac.wiki.model import WikiPage
+
+from bhdashboard.web_ui import DashboardModule
+from bhtheme.theme import BloodhoundTheme, BatchCreateTicketsMacro, 
CreatedTicketsMacro
+from bhtheme.tests import unittest
+
+
+try:
+    from babel import Locale
+
+    locale_en = Locale.parse('en_US')
+except ImportError:
+    locale_en = None
+
+
+class ThemeTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.env = EnvironmentStub(enable=('trac.*', 'bhtheme.*'),
+                                   default_data=True)
+        self.bhtheme = BloodhoundTheme(self.env)
+
+        self.BatchCreateTicketsMacro = BatchCreateTicketsMacro(self.env)
+        self.CreatedTicketsMacro = CreatedTicketsMacro(self.env)
+
+        self.req = Mock(href=self.env.href, authname='anonymous', tz=utc,
+                        method='POST',
+                        args=dict(action='dummy'),
+                        locale=locale_en, lc_time=locale_en,
+                        chrome={'warnings': []})
+        self.req.perm = MockPerm()
+
+    def tearDown(self):
+        self.env.reset_db()
+
+    def test_templates_dirs(self):
+        chrome = Chrome(self.env)
+        self.assertFalse(self.env.is_component_enabled(DashboardModule))
+        for dir in self.bhtheme.get_templates_dirs():
+            self.assertIn(dir, chrome.get_all_templates_dirs())
+
+    def test_batch_create(self):
+        with self.env.db_transaction as db:
+            db("CREATE TABLE bloodhound_product (prefix text,name 
text,description text,owner text,UNIQUE (prefix,name))")
+            db("INSERT INTO bloodhound_product VALUES ('my','product001','test 
product 001','anonymous')")
+        attr = {
+            'summary0': u's1',
+            'summary1': u's2',
+            'summary2': u's3',
+            'summary3': u's4',
+            'summary4': u's5',
+            'priority1': u'critical',
+            'priority0': u'blocker',
+            'priority3': u'minor',
+            'priority2': u'major',
+            'priority4': u'trivial',
+            'milestone0': u'milestone1',
+            'milestone1': u'milestone2',
+            'milestone2': u'milestone3',
+            'milestone3': u'milestone4',
+            'milestone4': u'milestone1',
+            'component4': u'component1',
+            'product4': u'my',
+            'product3': u'my',
+            'product2': u'my',
+            'product1': u'my',
+            'product0': u'my',
+            'component1': u'component2',
+            'component0': u'component1',
+            'component3': u'component2',
+            'component2': u'component1',
+            'description4': u'd5',
+            'description2': u'd3',
+            'description3': u'd4',
+            'description0': u'd1',
+            'description1': u'd2'}
+
+    def test_update_wiki_content(self):
+
+        w = WikiPage(self.env)
+        w.name = 'temp_page'
+        w.text = 'test the wiki replace function. ie: 
[[BatchCreateTickets(5)]] replaces with Created Tickets macro.'
+        WikiPage.save(w, 'anonymous', 'comment 01', '127.0.0.1')
+
+
+def suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(ThemeTestCase))
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')

Propchange: 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/tests/theme.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py
URL: 
http://svn.apache.org/viewvc/bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py?rev=1618477&r1=1618476&r2=1618477&view=diff
==============================================================================
--- 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py
 (original)
+++ 
bloodhound/branches/bep_0011_batch_create_tickets/bloodhound_theme/bhtheme/theme.py
 Sun Aug 17 15:03:28 2014
@@ -709,7 +709,7 @@ class BatchCreateTicketsMacro(WikiMacroB
 
        Example:
        {{{
-               BatchCreateTickets[[5]]    # This will create an empty table 
with 5 rows. 
+               [[BatchCreateTickets(5)]]    # This will create an empty table 
with 5 rows.
        }}}
 
        The empty table which will be created will contain the following 
tickets fields.
@@ -938,28 +938,34 @@ class BatchCreateTicketsMacro(WikiMacroB
 
             tkt_dict["tickets"] = tkt_list
 
-            """Editing the wiki content
+            self._update_wiki_content(num_of_tkts)
+
+            # send the HTTP POST request
+            req.send(to_json(tkt_dict), 'application/json')
+
+    # Public API
+    def _update_wiki_content(self, num_of_tkts):
+        """Editing the wiki content
             After creating the tickets successfully the feature requires to 
display the details of the created tickets
             within the wiki.
             To do that at this point the wiki content will be updated.
             ie. [[BatchCreateTickets(x)]] to [[CreatedTickets(start id,end 
id)]]
             """
-            max_uid = self.env.db_query("SELECT MAX(uid) FROM ticket")
-            max_time = self.env.db_query("SELECT MAX(time) FROM wiki")
-            wiki_content = self.env.db_query(
-                "SELECT * FROM wiki WHERE time==%s", (max_time[0][0],))
-            wiki_string = wiki_content[0][5]
-            # regex pattern of the macro declaration.
-            pattern = '\[\[BatchCreateTickets\([0-9]+\)\]\]'
-            l = re.search(pattern, wiki_string)
-            l1 = str(wiki_string[l.regs[0][0]:l.regs[0][1]])
-            updated_wiki_content = wiki_string.replace(
-                l1, "[[CreatedTickets(" + str(max_uid[0][0] - num_of_tkts) + 
"," + str(max_uid[0][0]) + ")]]")
-            with self.env.db_transaction as db:
-                db("UPDATE wiki SET text=%s WHERE time=%s",
-                   (updated_wiki_content, max_time[0][0]))
-            # send the HTTP POST request
-            req.send(to_json(tkt_dict), 'application/json')
+        max_uid = self.env.db_query("SELECT MAX(uid) FROM ticket")
+        max_time = self.env.db_query("SELECT MAX(time) FROM wiki")
+        wiki_content = self.env.db_query(
+            "SELECT * FROM wiki WHERE time==%s", (max_time[0][0],))
+        wiki_string = wiki_content[0][5]
+        # regex pattern of the macro declaration.
+        pattern = '\[\[BatchCreateTickets\([0-9]+\)\]\]'
+        l = re.search(pattern, wiki_string)
+        l1 = str(wiki_string[l.regs[0][0]:l.regs[0][1]])
+        updated_wiki_content = wiki_string.replace(
+            l1, "[[CreatedTickets(" + str(max_uid[0][0] - num_of_tkts) + "," + 
str(max_uid[0][0]) + ")]]")
+        with self.env.db_transaction as db:
+            db("UPDATE wiki SET text=%s WHERE time=%s",
+               (updated_wiki_content, max_time[0][0]))
+        return None
 
     def _get_ticket_module(self):
         ptm = None
@@ -1056,7 +1062,7 @@ class CreatedTicketsMacro(WikiMacroBase)
 
        Example:
        {{{
-           CreatedTickets[[10,15]]    # This will create a ticket table with 
tickets which has id's between 10 and 15. 
+           [[CreatedTickets(10,15)]]    # This will create a ticket table with 
tickets which has id's between 10 and 15.
        }}}
     """)
 


Reply via email to