示例#1
0
def SavedQueryIDToCond(cnxn, features_service, query_id):
    """Convert a can/query ID to a user query condition string."""
    built_in = tracker_bizobj.GetBuiltInQuery(query_id)
    if built_in:
        return built_in

    saved_query = features_service.GetSavedQuery(cnxn, query_id)
    return SavedQueryToCond(saved_query)
示例#2
0
def SavedQueryToCond(saved_query):
    """Convert a SavedQuery PB to a user query condition string."""
    if saved_query is None:
        return ''

    base_cond = tracker_bizobj.GetBuiltInQuery(saved_query.base_query_id)
    cond = '%s %s' % (base_cond, saved_query.query)
    return cond.strip()
    def testSavedQueryIDToCond(self):
        self.mox.StubOutWithMock(savedqueries_helpers, 'SavedQueryToCond')
        savedqueries_helpers.SavedQueryToCond(mox.IgnoreArg()).AndReturn('ret')
        self.mox.ReplayAll()
        query_cond = savedqueries_helpers.SavedQueryIDToCond(
            self.cnxn, self.features, 1)
        self.assertEquals('ret', query_cond)
        self.mox.VerifyAll()

        self.mox.StubOutWithMock(tracker_bizobj, 'GetBuiltInQuery')
        tracker_bizobj.GetBuiltInQuery(1).AndReturn('built_in_query')
        self.mox.ReplayAll()
        query_cond = savedqueries_helpers.SavedQueryIDToCond(
            self.cnxn, self.features, 1)
        self.assertEquals('built_in_query', query_cond)
        self.mox.VerifyAll()
    def testSavedQueryToCond(self):
        class MockSavedQuery:
            def __init__(self):
                self.base_query_id = 1
                self.query = 'query'

        saved_query = MockSavedQuery()

        cond_for_missing_query = savedqueries_helpers.SavedQueryToCond(None)
        self.assertEquals('', cond_for_missing_query)

        cond_with_no_base = savedqueries_helpers.SavedQueryToCond(saved_query)
        self.assertEquals('query', cond_with_no_base)

        self.mox.StubOutWithMock(tracker_bizobj, 'GetBuiltInQuery')
        tracker_bizobj.GetBuiltInQuery(1).AndReturn('base')
        self.mox.ReplayAll()
        cond_with_base = savedqueries_helpers.SavedQueryToCond(saved_query)
        self.assertEquals('base query', cond_with_base)
        self.mox.VerifyAll()
 def testGetBuiltInQuery(self):
   self.assertEqual(
       'is:open', tracker_bizobj.GetBuiltInQuery(2))
   self.assertEqual(
       '', tracker_bizobj.GetBuiltInQuery(101))