예제 #1
0
 def test_delete(self):
     created_at = datetime.now()
     node1 = TicketNode.add(
         TICKET_NODE_TYPE_CLOSE, 0, 'user1', 1, created_at)
     node2 = TicketNode.add(
         TICKET_NODE_TYPE_MERGE, 0, 'user1', 1, created_at)
     node3 = TicketNode.add(
         TICKET_NODE_TYPE_MERGE, 0, 'user1', 2, created_at)
     node = TicketNode.get(id=node2.id)
     assert node != None
     node2.delete()
     node = TicketNode.get(id=node2.id)
     assert node == None
예제 #2
0
 def test_delete(self):
     created_at = datetime.now()
     node1 = TicketNode.add(TICKET_NODE_TYPE_CLOSE, 0, 'user1', 1,
                            created_at)
     node2 = TicketNode.add(TICKET_NODE_TYPE_MERGE, 0, 'user1', 1,
                            created_at)
     node3 = TicketNode.add(TICKET_NODE_TYPE_MERGE, 0, 'user1', 2,
                            created_at)
     node = TicketNode.get(id=node2.id)
     assert node is not None
     node2.delete()
     node = TicketNode.get(id=node2.id)
     assert node is None
예제 #3
0
파일: npull.py 프로젝트: 000fan000/code
 def _save_merged(self, operator, from_sha, to_sha, merge_commit_sha):
     self.merged = "%s..%s" % (from_sha, to_sha)
     self.save()
     merged_time = datetime.now()
     self.merge_by = operator
     self.merge_time = merged_time.strftime('%Y-%m-%d %H:%M:%S')
     # FIXME: pullreq without ticket_id?
     if self.ticket_id:
         ticket = Ticket.get_by_projectid_and_ticketnumber(
             self.to_proj.id, self.ticket_id)
         if ticket:
             # add commits to ticket
             ticket.add_commits(merge_commit_sha, operator)
             TicketNode.add_merge(ticket.id, operator, merged_time)
예제 #4
0
 def _save_merged(self, operator, from_sha, to_sha, merge_commit_sha):
     self.merged = "%s..%s" % (from_sha, to_sha)
     self.save()
     merged_time = datetime.now()
     self.merge_by = operator
     self.merge_time = merged_time.strftime('%Y-%m-%d %H:%M:%S')
     # FIXME: pullreq without ticket_id?
     if self.ticket_id:
         ticket = Ticket.get_by_projectid_and_ticketnumber(
             self.to_proj.id, self.ticket_id)
         if ticket:
             # add commits to ticket
             ticket.add_commits(merge_commit_sha, operator)
             TicketNode.add_merge(ticket.id, operator, merged_time)
예제 #5
0
 def test_get_last_created_time(self):
     node1 = TicketNode.add(
         TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1, datetime.now())
     node2 = TicketNode.add(
         TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1, datetime.now())
     node3 = TicketNode.add(
         TICKET_NODE_TYPE_COMMENT, 0, 'user1', 2, datetime.now())
     node4 = TicketNode.add(
         TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 2, datetime.now())
     created_at = datetime.now()
     node5 = TicketNode.add(
         TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 1, created_at)
     testtime = TicketRank.get_last_created_time(1)
     assert node5.created_at.timetuple() == testtime.timetuple()
예제 #6
0
 def test_get_line_comment_count(self):
     created_at = datetime.now()
     node1 = TicketNode.add(
         TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1, created_at)
     node2 = TicketNode.add(
         TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1, created_at)
     node3 = TicketNode.add(
         TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 1, created_at)
     node4 = TicketNode.add(
         TICKET_NODE_TYPE_COMMENT, 0, 'user1', 2, created_at)
     node5 = TicketNode.add(
         TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 2, created_at)
     test_count = TicketRank.get_line_comment_count(1)
     assert test_count == 1
예제 #7
0
 def test_get_comment_count(self):
     clean_up()
     created_at = datetime.now()
     node1 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1,
                            created_at)
     node2 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1,
                            created_at)
     node3 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 1,
                            created_at)
     node4 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', 2,
                            created_at)
     node5 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 2,
                            created_at)
     test_count = TicketRank.get_comment_count(1)
     assert test_count == 2
예제 #8
0
def migrate_pull_linecomments():
    print '## run migrate_pull_linecomments'
    rs = store.execute("select id "
                       "from codedouban_ticket_codereview")
    for r in rs:
        id, = r
        c = TicketCodereview.get(id)
        print '>>>', c.id, c.ticket_id, c.from_ref, c.content
        PATH = c.path if c.path else ''
        new_c = PullLineComment.add_raw(c.ticket_id,
                                        c.from_ref,
                                        EMPTY_TO_SHA,
                                        PATH,
                                        c.new_path if c.new_path else PATH,
                                        EMPTY_OIDS,
                                        EMPTY_OIDS,
                                        c.old,
                                        c.new,
                                        c.author,
                                        c.content,
                                        c.position,
                                        c.time,
                                        c.time)
        tn = TicketNode.add_codereview(new_c)
        print '>>> INSERT TicketNode', tn.id, tn.type_id, tn.author, tn.ticket_id
    print "migrate_pull_linecomments: %s records" % len(rs)
예제 #9
0
 def test_get_last_created_time(self):
     clean_up()
     node1 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1,
                            datetime.now())
     node2 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', 1,
                            datetime.now())
     node3 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', 2,
                            datetime.now())
     node4 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 2,
                            datetime.now())
     created_at = datetime.now()
     node5 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', 1,
                            created_at)
     testtime = TicketRank.get_last_created_time(1)
     assert node5.created_at.timetuple() == testtime.timetuple()
     clean_up()
예제 #10
0
 def test_add(self):
     type = TICKET_NODE_TYPE_OPEN
     type_id = 1
     author = "user1"
     ticket_id = 1
     created_at = datetime.now()
     node = TicketNode.add(type, type_id, author, ticket_id, created_at)
     assert node.type == type
     assert node.type_id == type_id
     assert node.author == author
     assert node.ticket_id == ticket_id
     assert node.created_at.timetuple() == created_at.timetuple()
예제 #11
0
 def test_add(self):
     type = TICKET_NODE_TYPE_OPEN
     type_id = 1
     author = "user1"
     ticket_id = 1
     created_at = datetime.now()
     node = TicketNode.add(type, type_id, author, ticket_id, created_at)
     assert node.type == type
     assert node.type_id == type_id
     assert node.author == author
     assert node.ticket_id == ticket_id
     assert node.created_at.timetuple() == created_at.timetuple()
예제 #12
0
    def test_count_ticket_rank(self):
        clean_up()
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        tick1 = Ticket.add(1, title, desc, author)
        tick2 = Ticket.add(2, title, desc, author)
        created_at = datetime.now()
        aDay = timedelta(days=-1)
        yesterday = created_at + aDay
        node1 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', tick1.id,
                               created_at)
        node2 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', tick1.id,
                               created_at)
        node3 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1',
                               tick1.id, created_at)
        node4 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 0, 'user1', tick2.id,
                               yesterday)
        node5 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1',
                               tick2.id, yesterday)

        # 验证 已经关闭的 ticket
        store.execute(
            "update codedouban_ticket set time=%s, closed=%s "
            "where id=%s", (yesterday, created_at, tick2.id))
        store.commit()
        TicketRank.count_ticket_rank(True)
        rank_score2 = TicketRank.get_rank_by_ticket_id(tick2.id)
        rank_s2 = rank_score2[0][0]
        rank2 = 32.07
        assert rank_s2 == rank2

        # 验证 没有关闭的 ticket
        TicketRank.count_ticket_rank(False)
        rank_score1 = TicketRank.get_rank_by_ticket_id(tick1.id)
        rank_s1 = rank_score1[0][0]
        rank1 = 37.97
        assert rank_s1 == rank1
예제 #13
0
    def test_count_ticket_rank(self):
        clean_up()
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        tick1 = Ticket.add(1, title, desc, author)
        tick2 = Ticket.add(2, title, desc, author)
        created_at = datetime.now()
        aDay = timedelta(days=-1)
        yesterday = created_at + aDay
        node1 = TicketNode.add(
            TICKET_NODE_TYPE_COMMENT, 0, 'user1', tick1.id, created_at)
        node2 = TicketNode.add(
            TICKET_NODE_TYPE_COMMENT, 0, 'user1', tick1.id, created_at)
        node3 = TicketNode.add(
            TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', tick1.id, created_at)
        node4 = TicketNode.add(
            TICKET_NODE_TYPE_COMMENT, 0, 'user1', tick2.id, yesterday)
        node5 = TicketNode.add(
            TICKET_NODE_TYPE_LINECOMMENT, 0, 'user1', tick2.id, yesterday)

        # 验证 已经关闭的 ticket
        store.execute("update codedouban_ticket set time=%s, closed=%s "
                      "where id=%s", (yesterday, created_at, tick2.id))
        store.commit()
        TicketRank.count_ticket_rank(True)
        rank_score2 = TicketRank.get_rank_by_ticket_id(tick2.id)
        rank_s2 = rank_score2[0][0]
        rank2 = 32.07
        assert rank_s2 == rank2

        # 验证 没有关闭的 ticket
        TicketRank.count_ticket_rank(False)
        rank_score1 = TicketRank.get_rank_by_ticket_id(tick1.id)
        rank_s1 = rank_score1[0][0]
        rank1 = 37.97
        assert rank_s1 == rank1
예제 #14
0
    def test_get(self):
        created_at = datetime.now()
        node1 = TicketNode.add(
            TICKET_NODE_TYPE_CLOSE, 0, 'user1', 1, created_at)
        node2 = TicketNode.add(
            TICKET_NODE_TYPE_MERGE, 0, 'user1', 1, created_at)
        node3 = TicketNode.add(
            TICKET_NODE_TYPE_MERGE, 0, 'user1', 2, created_at)
        nodes = TicketNode.gets_by_ticket_id(1)
        assert len(nodes) == 2

        node1 = TicketNode.add(
            TICKET_NODE_TYPE_LINECOMMENT, 1, 'user1', 2, created_at)
        node2 = TicketNode.add(
            TICKET_NODE_TYPE_COMMENT, 1, 'user1', 2, created_at)
        node = TicketNode.get_by_type_id(TICKET_NODE_TYPE_LINECOMMENT, 1)
        assert node.id == node1.id
        assert node.type == node1.type
        assert node.type_id == node1.type_id
        assert node.ticket_id == node1.ticket_id
        node = TicketNode.get_by_type_id(TICKET_NODE_TYPE_COMMIT, 1)
        assert node is None
예제 #15
0
    def test_get(self):
        clean_up()
        created_at = datetime.now()
        node1 = TicketNode.add(TICKET_NODE_TYPE_CLOSE, 0, 'user1', 1,
                               created_at)
        node2 = TicketNode.add(TICKET_NODE_TYPE_MERGE, 0, 'user1', 1,
                               created_at)
        node3 = TicketNode.add(TICKET_NODE_TYPE_MERGE, 0, 'user1', 2,
                               created_at)
        nodes = TicketNode.gets_by_ticket_id(1)
        assert len(nodes) == 2

        node1 = TicketNode.add(TICKET_NODE_TYPE_LINECOMMENT, 1, 'user1', 2,
                               created_at)
        node2 = TicketNode.add(TICKET_NODE_TYPE_COMMENT, 1, 'user1', 2,
                               created_at)
        node = TicketNode.get_by_type_id(TICKET_NODE_TYPE_LINECOMMENT, 1)
        assert node.id == node1.id
        assert node.type == node1.type
        assert node.type_id == node1.type_id
        assert node.ticket_id == node1.ticket_id
        node = TicketNode.get_by_type_id(TICKET_NODE_TYPE_COMMIT, 1)
        assert node is None
예제 #16
0
def clean_up():
    for node in TicketNode.gets():
        node.delete()
예제 #17
0
def clean_up():
    for node in TicketNode.gets():
        node.delete()