Commits

Anonymous committed c97d20d

[svn r9907] 0.11.7.1: backported r9723 (`resource_exists` for milestone)

Comments (0)

Files changed (2)

trac/ticket/roadmap.py

         else:
             return desc
 
+    def resource_exists(self, resource):
+        """
+        >>> from trac.test import EnvironmentStub
+        >>> env = EnvironmentStub()
+        
+        >>> m1 = Milestone(env)
+        >>> m1.name = 'M1'
+        >>> m1.insert()
+        
+        >>> MilestoneModule(env).resource_exists(Resource('milestone', 'M1'))
+        True
+        >>> MilestoneModule(env).resource_exists(Resource('milestone', 'M2'))
+        False
+        """
+        db = self.env.get_db_cnx()
+        cursor = db.cursor()
+        cursor.execute("SELECT name FROM milestone WHERE name=%s",
+                       (resource.id,))
+        return bool(cursor.fetchall())
+
     # ISearchSource methods
 
     def get_search_filters(self, req):

trac/ticket/tests/__init__.py

     suite.addTest(roadmap.suite())
     suite.addTest(doctest.DocTestSuite(trac.ticket.api))
     suite.addTest(doctest.DocTestSuite(trac.ticket.report))
+    suite.addTest(doctest.DocTestSuite(trac.ticket.roadmap))
     return suite
 
 if __name__ == '__main__':