def test_get_commit_by_date(self): # create two commit, one 5 sec younger than the other db = self.env.get_db_cnx() now = to_timestamp(datetime.now(utc)) data1 = COMMITS[0] commit1 = GitHubCommit(self.env, git_url=GIT_URL, **data1) commit1.time = now commit1.save(db=db) data2 = COMMITS[1] commit2 = GitHubCommit(self.env, git_url=GIT_URL, **data2) commit2.time = now + 5 commit2.save(db=db) db.commit() commit_before_now = GitHubCommit.get_commit_by_date(self.env, now - 1, now, git_url=GIT_URL) commit_before_now = [x for x in commit_before_now] eq_(1, len(commit_before_now)) eq_(commit1.url, commit_before_now[0].url) commit_now = GitHubCommit.get_commit_by_date(self.env, now, now + 5, git_url=GIT_URL) commit_now = [x for x in commit_now] eq_(2, len(commit_now)) future_commit = GitHubCommit.get_commit_by_date(self.env, now + 6, now + 7, git_url=GIT_URL) future_commit = [x for x in future_commit] eq_(0, len(future_commit))
def _create_commit(self): c = GitHubCommit(self.env, git_url=GIT_URL, **COMMITS[0]) c.time = self.now c.save() c = GitHubCommit(self.env, git_url=GIT_URL, **COMMITS[1]) c.time = self.now + 5 c.url = 'http://example.com/example.git' c.save()
def test_process_commit(self): commits = [] time = self.now for data in COMMITS: c = GitHubCommit(self.env, git_url=GIT_URL, **data) c.time = time c.save() commits.append(c) time = time + 60 # parse commit for the first time (with a clone) self.ticker_updater.process_commit(commits[0]) tkt1 = Ticket(self.env, 1) change_log = tkt1.get_changelog() eq_(1, len(change_log)) eq_('Damien Lebrun <*****@*****.**>', change_log[0][1]) eq_( 'Commit %(id)s:\n\n%(message)s\n\nSource: [%(url)s]' % COMMITS[0], change_log[0][4]) # parse same commit (still clone), # should not update the ticket self.ticker_updater.process_commit(commits[1]) tkt1 = Ticket(self.env, 1) change_log = tkt1.get_changelog() eq_(1, len(change_log)) # parse the commit from the main git repository # Should update the repository self.ticker_updater.process_commit(commits[2]) tkt1 = Ticket(self.env, 1) change_log = tkt1.get_changelog() eq_(3, len(change_log)) eq_('Damien Lebrun <*****@*****.**>', change_log[1][1]) eq_( 'Commit %(id)s:\n\n%(message)s\n\nSource: [%(url)s]' % COMMITS[2], change_log[1][4]) eq_('Damien Lebrun <*****@*****.**>', change_log[2][1]) eq_('resolution',change_log[2][2]) eq_('fixed',change_log[2][4])