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
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()
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
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()
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
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
def update_ticket_rankscore_closed(): TicketRank.count_ticket_rank(True)
def update_ticket_rankscore_null(): TicketRank.count_ticket_rank(False)