コード例 #1
0
ファイル: testBugzilla.py プロジェクト: AlinT/socorro
 def verify_tables(self, correct):
   global me
   # bug_status
   count = 0
   for expected, actual in zip(psy.execute(me.cur, "select id, status, resolution, short_desc from bugs order by 1"), correct["bugs"]):
     count += 1
     assert expected == actual, "expected %s, got %s" % (str(expected), str(actual))
   assert len(correct["bugs"]) == count, "expected %d entries in bugs but found %d" % (len(correct["bugs"]), count)
   #bug_associations
   count = 0
   for expected, actual in zip(psy.execute(me.cur, "select signature, bug_id from bug_associations order by 1, 2"), correct["bug_associations"]):
     count += 1
     assert expected == actual, "expected %s, got %s" % (str(expected), str(actual))
   assert len(correct["bug_associations"]) == count, "expected %d entries in bug_associations but found %d" % (len(correct["bug_associations"]), count)
コード例 #2
0
ファイル: testPsycopghelper.py プロジェクト: AlinT/socorro
 def testExecute(self):
   aCursor = TestMultiCursor(numCols=1,numRows=3)
   f = ppghelper.execute(aCursor,"")
   vals = [x for x in f]
   assert 3 == len(vals)
   assert 'Row 0, Column 0' == vals[0][0]
   assert 'Row 2, Column 0' == vals[-1][0]
   aCursor = TestMultiCursor(numCols=1,numRows=1)
コード例 #3
0
 def testExecute(self):
   aCursor = TestMultiCursor(numCols=1,numRows=3)
   f = ppghelper.execute(aCursor,"")
   vals = [x for x in f]
   assert 3 == len(vals)
   assert 'Row 0, Column 0' == vals[0][0]
   assert 'Row 2, Column 0' == vals[-1][0]
   aCursor = TestMultiCursor(numCols=1,numRows=1)
コード例 #4
0
ファイル: bugzilla.py プロジェクト: AlinT/socorro
def insert_or_update_bug_in_database(bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureSetFromBugzilla,
                                     databaseCursor, signatureFoundInReportsFunction=signature_is_found):
  try:
    if len(signatureSetFromBugzilla) == 0:
      databaseCursor.execute("delete from bugs where id = %s", (bugId,))
      databaseCursor.connection.commit()
      logger.info("rejecting bug (no signatures): %s - %s, %s", bugId, statusFromBugzilla, resolutionFromBugzilla)
    else:
      useful = False
      insertMade = False
      try:
        statusFromDatabase, resolutionFromDatabase, shortDescFromDatabase = psy.singleRowSql(databaseCursor, "select status, resolution, short_desc from bugs where id = %s", (bugId,))
        if statusFromDatabase != statusFromBugzilla or resolutionFromDatabase != resolutionFromBugzilla or shortDescFromDatabase != shortDescFromBugzilla:
          databaseCursor.execute("update bugs set status = %s, resolution = %s, short_desc = %s where id = %s", (statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, bugId))
          logger.info("bug status updated: %s - %s, %s", bugId, statusFromBugzilla, resolutionFromBugzilla)
          useful = True
        listOfSignaturesFromDatabase = [x[0] for x in psy.execute(databaseCursor, "select signature from bug_associations where bug_id = %s", (bugId,))]
        for aSignature in listOfSignaturesFromDatabase:
          if aSignature not in signatureSetFromBugzilla:
            databaseCursor.execute("delete from bug_associations where signature = %s and bug_id = %s", (aSignature, bugId))
            logger.info ('association removed: %s - "%s"', bugId, aSignature)
            useful = True
      except psy.SQLDidNotReturnSingleRow:
        databaseCursor.execute("insert into bugs (id, status, resolution, short_desc) values (%s, %s, %s, %s)", (bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla))
        insertMade = True
        listOfSignaturesFromDatabase = []
      for aSignature in signatureSetFromBugzilla:
        if aSignature not in listOfSignaturesFromDatabase:
          if signatureFoundInReportsFunction(aSignature, databaseCursor):
            databaseCursor.execute("insert into bug_associations (signature, bug_id) values (%s, %s)", (aSignature, bugId))
            logger.info ('new association: %s - "%s"', bugId, aSignature)
            useful = True
          else:
            logger.info ('rejecting association (no reports with this signature): %s - "%s"', bugId, aSignature)
      if useful:
        databaseCursor.connection.commit()
        if insertMade:
          logger.info('new bug: %s - %s, %s, "%s"', bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla)
      else:
        databaseCursor.connection.rollback()
        if insertMade:
          logger.info('rejecting bug (no useful information): %s - %s, %s, "%s"', bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla)
        else:
          logger.info('skipping bug (no new information): %s - %s, %s, "%s"', bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla)
  except Exception, x:
    databaseCursor.connection.rollback()
    raise
コード例 #5
0
ファイル: testBugzilla.py プロジェクト: AlinT/socorro
  def test_insert_or_update_bug_in_database(self):
    #bugId, statusFromBugzilla, resolutionFromBugzilla, signatureListFromBugzilla
    #new    *                   *                       empty
    #new    *                   *                       1 new
    #new    *                   *                       2 new
    #old    *                   *                       empty
    #old    new                 new
    global me

    def true(x, y):
      return True

    def hasYES(x, y):
      return "YES" in x

    me.cur = me.conn.cursor()
    #me.cur = me.conn.cursor(cursor_factory=psy.LoggingCursor)
    #me.cur.setLogger(me.fileLogger)

    psy.execute(me.cur, "delete from bug_status")
    me.cur.connection.commit()

    # test intial insert
    sample1 = [ (2,"CLOSED","WONTFIX","a short desc",set(["aaaa"])),
                (3,"NEW","","a short desc",set([])),
                (343324,"ASSIGNED","","a short desc",set(["bbbb","cccc"])),
                (343325,"CLOSED","RESOLVED","a short desc",set(["dddd"])),
              ]
    correct1 = { "bugs": [(2,     "CLOSED",  "WONTFIX", "a short desc"),
                          (343324,"ASSIGNED","",        "a short desc"),
                          (343325,"CLOSED",  "RESOLVED","a short desc")],
                 "bug_associations": [("aaaa", 2),
                                      ("bbbb", 343324),
                                      ("cccc", 343324),
                                      ("dddd", 343325)]
               }
    for bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureListFromBugzilla in sample1:
      bug.insert_or_update_bug_in_database(bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureListFromBugzilla, me.cur, true)
    self.verify_tables(correct1)

    #test removing existing associations
    sample2 = [ (2,"CLOSED","WONTFIX","a short desc",set([])),
                (343324,"ASSIGNED","","a short desc",set(["bbbb"])),
              ]
    correct2 = { "bugs": [(343324,"ASSIGNED","","a short desc"),
                          (343325,"CLOSED",  "RESOLVED","a short desc")],
                 "bug_associations": [("bbbb", 343324),
                                      ("dddd", 343325)]
               }
    for bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureListFromBugzilla in sample2:
      bug.insert_or_update_bug_in_database(bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureListFromBugzilla, me.cur, true)
    self.verify_tables(correct2)

    #test updating existing associations
    sample2 = [(343324,"CLOSED","RESOLVED","a short desc",set(["bbbb"])),
              ]
    correct2 = { "bugs": [(343324,"CLOSED","RESOLVED","a short desc"),
                          (343325,"CLOSED",  "RESOLVED","a short desc")],
                 "bug_associations": [("bbbb", 343324),
                                      ("dddd", 343325)]
               }
    for bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureListFromBugzilla in sample2:
      bug.insert_or_update_bug_in_database(bugId, statusFromBugzilla, resolutionFromBugzilla, shortDescFromBugzilla, signatureListFromBugzilla, me.cur, true)
    self.verify_tables(correct2)
コード例 #6
0
ファイル: bugzilla.py プロジェクト: zenmind101/socorro
def insert_or_update_bug_in_database(
        bugId,
        statusFromBugzilla,
        resolutionFromBugzilla,
        shortDescFromBugzilla,
        signatureSetFromBugzilla,
        databaseCursor,
        signatureFoundInReportsFunction=signature_is_found):
    try:
        if len(signatureSetFromBugzilla) == 0:
            databaseCursor.execute("delete from bugs where id = %s", (bugId, ))
            databaseCursor.connection.commit()
            logger.info("rejecting bug (no signatures): %s - %s, %s", bugId,
                        statusFromBugzilla, resolutionFromBugzilla)
        else:
            useful = False
            insertMade = False
            try:
                statusFromDatabase, resolutionFromDatabase, shortDescFromDatabase = psy.singleRowSql(
                    databaseCursor,
                    "select status, resolution, short_desc from bugs where id = %s",
                    (bugId, ))
                if statusFromDatabase != statusFromBugzilla or resolutionFromDatabase != resolutionFromBugzilla or shortDescFromDatabase != shortDescFromBugzilla:
                    databaseCursor.execute(
                        "update bugs set status = %s, resolution = %s, short_desc = %s where id = %s",
                        (statusFromBugzilla, resolutionFromBugzilla,
                         shortDescFromBugzilla, bugId))
                    logger.info("bug status updated: %s - %s, %s", bugId,
                                statusFromBugzilla, resolutionFromBugzilla)
                    useful = True
                listOfSignaturesFromDatabase = [
                    x[0] for x in psy.execute(
                        databaseCursor,
                        "select signature from bug_associations where bug_id = %s",
                        (bugId, ))
                ]
                for aSignature in listOfSignaturesFromDatabase:
                    if aSignature not in signatureSetFromBugzilla:
                        databaseCursor.execute(
                            "delete from bug_associations where signature = %s and bug_id = %s",
                            (aSignature, bugId))
                        logger.info('association removed: %s - "%s"', bugId,
                                    aSignature)
                        useful = True
            except psy.SQLDidNotReturnSingleRow:
                databaseCursor.execute(
                    "insert into bugs (id, status, resolution, short_desc) values (%s, %s, %s, %s)",
                    (bugId, statusFromBugzilla, resolutionFromBugzilla,
                     shortDescFromBugzilla))
                insertMade = True
                listOfSignaturesFromDatabase = []
            for aSignature in signatureSetFromBugzilla:
                if aSignature not in listOfSignaturesFromDatabase:
                    if signatureFoundInReportsFunction(aSignature,
                                                       databaseCursor):
                        databaseCursor.execute(
                            "insert into bug_associations (signature, bug_id) values (%s, %s)",
                            (aSignature, bugId))
                        logger.info('new association: %s - "%s"', bugId,
                                    aSignature)
                        useful = True
                    else:
                        logger.info(
                            'rejecting association (no reports with this signature): %s - "%s"',
                            bugId, aSignature)
            if useful:
                databaseCursor.connection.commit()
                if insertMade:
                    logger.info('new bug: %s - %s, %s, "%s"', bugId,
                                statusFromBugzilla, resolutionFromBugzilla,
                                shortDescFromBugzilla)
            else:
                databaseCursor.connection.rollback()
                if insertMade:
                    logger.info(
                        'rejecting bug (no useful information): %s - %s, %s, "%s"',
                        bugId, statusFromBugzilla, resolutionFromBugzilla,
                        shortDescFromBugzilla)
                else:
                    logger.info(
                        'skipping bug (no new information): %s - %s, %s, "%s"',
                        bugId, statusFromBugzilla, resolutionFromBugzilla,
                        shortDescFromBugzilla)
    except Exception, x:
        databaseCursor.connection.rollback()
        raise