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 get_timeline_events(self, req, start, stop, filters): """ Return a list of events in the time range given by the `start` and `stop` parameters. The `filters` parameters is a list of the enabled filters, each item being the name of the tuples returned by `get_timeline_filters`. Since 0.11, the events are `(kind, date, author, data)` tuples, where `kind` is a string used for categorizing the event, `date` is a `datetime` object, `author` is a string and `data` is some private data that the component will reuse when rendering the event. When the event has been created indirectly by another module, like this happens when calling `AttachmentModule.get_timeline_events()` the tuple can also specify explicitly the provider by returning tuples of the following form: `(kind, date, author, data, provider)`. """ if 'main_git_repository' in filters or \ 'cloned_git_repository' in filters: for event in GitHubEvent.get_commit_by_date( self.env, to_timestamp(start), to_timestamp(stop), git_url=self.github_url): if event.is_clone() and 'cloned_git_repository' in filters: yield ('cloned_git_repository', datetime.fromtimestamp(event.time, utc), event.author, event) elif not event.is_clone() and 'main_git_repository' in filters: yield ('main_git_repository', datetime.fromtimestamp(event.time, utc), event.author, event) # TODO: only sent needed data