1. Odd Simon Simonsen
  2. trac-011

Commits

cboos  committed c97d20d

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

  • Participants
  • Parent commits 23ec75f
  • Branches 0.11-stable

Comments (0)

Files changed (2)

File trac/ticket/roadmap.py

View file
         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):

File trac/ticket/tests/__init__.py

View file
     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__':