Пример #1
0
def EvaluateSubscriptions(
    cnxn, issue, users_to_queries, services, config):
  """Determine subscribers who have subs that match the given issue."""
  # Note: unlike filter rule, subscriptions see explicit & derived values.
  lower_labels = [lab.lower() for lab in tracker_bizobj.GetLabels(issue)]
  label_set = set(lower_labels)

  subscribers_to_notify = []
  for uid, saved_queries in users_to_queries.items():
    for sq in saved_queries:
      if sq.subscription_mode != 'immediate':
        continue
      if issue.project_id not in sq.executes_in_project_ids:
        continue
      cond = savedqueries_helpers.SavedQueryToCond(sq)
      # TODO(jrobbins): Support linked accounts me_user_ids.
      cond, _warnings = searchpipeline.ReplaceKeywordsWithUserIDs([uid], cond)
      cond_ast = query2ast.ParseUserQuery(
        cond, '', query2ast.BUILTIN_ISSUE_FIELDS, config)

      if filterrules_helpers.EvalPredicate(
          cnxn, services, cond_ast, issue, label_set, config,
          tracker_bizobj.GetOwnerId(issue), tracker_bizobj.GetCcIds(issue),
          tracker_bizobj.GetStatus(issue)):
        subscribers_to_notify.append(uid)
        break  # Don't bother looking at the user's other saved quereies.

  return subscribers_to_notify
Пример #2
0
    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()
Пример #3
0
    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()