def test_fetch_pulls_with_empty_commits_and_comments(self): setup_gitee_pull_request_services_with_empty_commits_and_comments() from_date = datetime.datetime(2019, 1, 1) gitee = Gitee("gitee_example", "repo", "[aaa]") pulls = [ pr for pr in gitee.fetch(category=CATEGORY_PULL_REQUEST, from_date=from_date) ] self.assertEqual(len(pulls), 2) pull = pulls[0] self.assertEqual(len(pull['data']['review_comments_data']), 0) # check if the testers_data there self.assertTrue('tester_data' not in pull['data']) self.assertEqual(pull['data']['commits_data'], []) self.assertEqual(pull['data']['merged_by'], "willemjiang") self.assertEqual(pull['data']['merged_by_data']['login'], "willemjiang") pull = pulls[1] self.assertEqual(len(pull['data']['review_comments_data']), 0) self.assertEqual(len(pull['data']['review_comments_data']), 0) # check if the testers_data there self.assertTrue('tester_data' not in pull['data']) self.assertEqual(pull['data']['commits_data'], []) self.assertEqual(pull['data']['merged_by'], None) self.assertEqual(pull['data']['merged_by_data'], [])
def test_fetch_pulls(self): setup_gitee_pull_request_services() from_date = datetime.datetime(2019, 1, 1) gitee = Gitee("gitee_example", "repo", "[aaa]") pulls = [ pr for pr in gitee.fetch(category=CATEGORY_PULL_REQUEST, from_date=from_date) ] self.assertEqual(len(pulls), 2) pull = pulls[0] self.assertEqual(pull['updated_on'], 1586078981.0) self.assertEqual(pull['uuid'], '497fa28f2109f702a7a88b1a4fbfbfb279a2266e') self.assertEqual(pull['data']['head']['repo']['path'], "camel-on-cloud") self.assertEqual(pull['data']['base']['repo']['path'], "camel-on-cloud") self.assertEqual(pull['data']['number'], 1) self.assertEqual(len(pull['data']['review_comments_data']), 1) self.assertEqual(pull['data']['review_comments_data'][0]['body'], "Add some comments here.") self.assertEqual(len(pull['data']['assignees_data']), 1) self.assertEqual(pull['data']['assignees_data'][0]['login'], "willemjiang") # check if the testers_data there self.assertTrue('tester_data' not in pull['data']) self.assertEqual(pull['data']['commits_data'], ['8cd1bca4f2989ac2e2753a152c8c4c8e065b22f5']) self.assertEqual(pull['data']['merged_by'], "willemjiang") self.assertEqual(pull['data']['merged_by_data']['login'], "willemjiang") pull = pulls[1] self.assertEqual(pull['updated_on'], 1585976439.0) self.assertEqual(pull['uuid'], '46df79e68e92005db5c1897844e3a0c3acf1aa4f') self.assertEqual(pull['data']['head']['repo']['path'], "camel-on-cloud") self.assertEqual(pull['data']['base']['repo']['path'], "camel-on-cloud") self.assertEqual(pull['data']['number'], 2) self.assertEqual(len(pull['data']['review_comments_data']), 1) self.assertEqual(pull['data']['review_comments_data'][0]['body'], "Added comment here.") self.assertEqual(len(pull['data']['assignees_data']), 1) self.assertEqual(pull['data']['assignees_data'][0]['login'], "willemjiang") # check if the testers_data there self.assertTrue('tester_data' not in pull['data']) self.assertEqual(pull['data']['commits_data'], ['586cc8e511097f5c5b7a4ce803a5efcaed99b9c2']) self.assertEqual(pull['data']['merged_by'], None) self.assertEqual(pull['data']['merged_by_data'], [])
def test_fetch_repo(self): setup_gitee_basic_services() gitee = Gitee("gitee_example", "repo", "[aaa]") repos = [repo for repo in gitee.fetch(category=CATEGORY_REPO)] self.assertEqual(len(repos), 1) repo = repos[0] self.assertEqual(repo['category'], 'repository') self.assertEqual(repo['data']['name'], "camel-on-cloud") self.assertEqual(repo['data']['forks_count'], 1) self.assertEqual(repo['data']['stargazers_count'], 2) self.assertEqual(repo['data']['watchers_count'], 3) self.assertEqual(repo['data']['open_issues_count'], 4)
def test_fetch_issues(self): setup_gitee_issue_services() from_date = datetime.datetime(2019, 1, 1) gitee = Gitee("gitee_example", "repo", ["aaa"]) issues = [issues for issues in gitee.fetch(from_date=from_date)] self.assertEqual(len(issues), 2) issue1 = issues[0] self.assertEqual(issue1['origin'], 'https://gitee.com/gitee_example/repo') self.assertEqual(issue1['uuid'], 'e954a17216b20e5b11c7eef99df06aefa8b8b974') self.assertEqual(issue1['updated_on'], 1577842375.0) self.assertEqual(issue1['tag'], 'https://gitee.com/gitee_example/repo') self.assertEqual(issue1['data']['assignee_data']['login'], 'willemjiang') self.assertEqual(issue1['data']['title'], 'First example issue') # TODO to add collaborators information # self.assertEqual(issue['data']['collaborators_data'][0]['login'], 'willemjiang') self.assertEqual(len(issue1['data']['comments_data']), 1) self.assertEqual( issue1['data']['comments_data'][0]['user_data']['login'], 'willemjiang') issue2 = issues[1] self.assertEqual(issue2['origin'], 'https://gitee.com/gitee_example/repo') self.assertEqual(issue2['uuid'], '3e5e90b1f0862c1b8a1adb52bc961e8a77ec2431') self.assertEqual(issue2['updated_on'], 1585710411.0) self.assertEqual(issue2['tag'], 'https://gitee.com/gitee_example/repo') self.assertEqual(issue2['data']['assignee_data']['login'], 'willemjiang') self.assertEqual(issue2['data']['title'], 'Second example issue') # TODO to add collaborators information # self.assertEqual(issue['data']['collaborators_data'][0]['login'], 'willemjiang') self.assertEqual(len(issue2['data']['comments_data']), 1) self.assertEqual( issue2['data']['comments_data'][0]['user_data']['login'], 'willemjiang') self.assertEqual( issue2['data']['comments_data'][0]['target']['issue']['number'], 'I1DAQF')
def test_fetch_empty(self): """ Test when get a empty issues API call """ setup_gitee_issue_services() empty_issue = '[]' httpretty.register_uri(httpretty.GET, GITEE_ISSUES_URL, body=empty_issue, status=200, forcing_headers={ "total_count": "0", "total_page": "0" }) from_date = datetime.datetime(2019, 1, 1) gitee = Gitee("gitee_example", "repo", ["aaa"]) issues = [ issues for issues in gitee.fetch(from_date=from_date, to_date=None) ] self.assertEqual(len(issues), 0)
def test_fetch_issues_with_to_data(self): setup_gitee_issue_services() to_date = datetime.datetime(2020, 2, 1) gitee = Gitee("gitee_example", "repo", ["aaa"]) issues = [issues for issues in gitee.fetch(to_date=to_date)] self.assertEqual(len(issues), 1) issue = issues[0] self.assertEqual(issue['origin'], 'https://gitee.com/gitee_example/repo') self.assertEqual(issue['uuid'], 'e954a17216b20e5b11c7eef99df06aefa8b8b974') self.assertEqual(issue['updated_on'], 1577842375.0) self.assertEqual(issue['tag'], 'https://gitee.com/gitee_example/repo') self.assertEqual(issue['data']['assignee_data']['login'], 'willemjiang') self.assertEqual(issue['data']['title'], 'First example issue') # TODO to add collaborators information # self.assertEqual(issue['data']['collaborators_data'][0]['login'], 'willemjiang') self.assertEqual(len(issue['data']['comments_data']), 1) self.assertEqual( issue['data']['comments_data'][0]['user_data']['login'], 'willemjiang')