def test_GitHub_fetch_issues(m): expected = _issues() m.get(drafts_api.git_url('issues'), json=expected, status_code=200, headers={'Content-Type': 'application/json'}) actual = drafts_api.fetch_issues() assert expected == list(actual)
def fetch(cls, since): issues = drafts_api.fetch_issues(since=since) for issue_data in issues: issue = cls.from_gh_data(issue_data) milestones = drafts_api.fetch_milestone(issue.number) for milestone_data in milestones: issue.milestones.append(Milestone.from_gh_data(milestone_data)) events = drafts_api.fetch_issue_events(issue.number) for event_data in events: issue.events.append(Event.from_gh_data(event_data)) GithubQueryLog.log('issues') db.session.commit()
def test_GitHub_fetch_assembles_multiple_pages(m): def _register_get(since, content): url = '{0}?sort=updated&per_page=10&direction=asc&since={1}'.format( drafts_api.git_url('issues'), since) app.logger.info('registering mock for {0}'.format(url)) m.get(url, json=content, complete_qs=False, status_code=200, headers={'Content-Type': 'application/json'}) expected = [] last_since = datetime.datetime(2015, 1, 1).strftime(GH_DATE_FORMAT) for offset in (0, 10, 20): issue_group = _issues(n_issues=10, offset=offset) _register_get(last_since, issue_group) expected.extend(issue_group) last_since = issue_group[-1]['updated_at'] _register_get(last_since, []) actual = drafts_api.fetch_issues(since=expected[0]['updated_at'], per_page=10) assert expected == list(actual)