def test_fetch_from_date(self): """Test fetch method with from date""" mock_check_ouput.side_effect = mock_check_ouput gerrit = Gerrit(GERRIT_REPO, user=GERRIT_USER, port=29418, max_reviews=2) from_date = datetime.datetime(2018, 3, 5) reviews = [review for review in gerrit.fetch(from_date=from_date)] self.assertIsNotNone(gerrit.client) self.assertEqual(len(reviews), 4) review = reviews[0] self.assertEqual(review['category'], CATEGORY_REVIEW) self.assertEqual(len(review['data']['comments']), 5) self.assertEqual(review['data']['owner']['username'], 'gehel') self.assertEqual(len(review['data']['patchSets']), 2) review = reviews[1] self.assertEqual(review['category'], CATEGORY_REVIEW) self.assertEqual(len(review['data']['comments']), 26) self.assertEqual(review['data']['owner']['username'], "lucaswerkmeister-wmde") self.assertEqual(len(review['data']['patchSets']), 1) review = reviews[2] self.assertEqual(review['category'], CATEGORY_REVIEW) self.assertEqual(len(review['data']['comments']), 13) self.assertEqual(review['data']['owner']['username'], "jayprakash12345") self.assertEqual(len(review['data']['patchSets']), 3) review = reviews[3] self.assertEqual(review['category'], CATEGORY_REVIEW) self.assertEqual(len(review['data']['comments']), 8) self.assertEqual(review['data']['owner']['username'], "elukey") self.assertEqual(len(review['data']['patchSets']), 2)
def test_initialization(self): """Test whether attributes are initializated""" gerrit = Gerrit(GERRIT_REPO, tag='test') self.assertEqual(gerrit.hostname, GERRIT_REPO) self.assertEqual(gerrit.port, PORT) self.assertEqual(gerrit.max_reviews, MAX_REVIEWS) self.assertIsNone(gerrit.user) self.assertEqual(gerrit.tag, 'test') self.assertIsNone(gerrit.client) self.assertIsNone(gerrit.blacklist_ids) gerrit = Gerrit(GERRIT_REPO, GERRIT_USER, port=1000, max_reviews=100) self.assertEqual(gerrit.hostname, GERRIT_REPO) self.assertEqual(gerrit.port, 1000) self.assertEqual(gerrit.max_reviews, 100) self.assertEqual(gerrit.tag, GERRIT_REPO) self.assertEqual(gerrit.user, GERRIT_USER) self.assertIsNone(gerrit.client) self.assertIsNone(gerrit.blacklist_ids) gerrit = Gerrit(GERRIT_REPO, tag='test', blacklist_ids=['willy']) self.assertEqual(gerrit.hostname, GERRIT_REPO) self.assertEqual(gerrit.port, PORT) self.assertEqual(gerrit.max_reviews, MAX_REVIEWS) self.assertIsNone(gerrit.user) self.assertEqual(gerrit.tag, 'test') self.assertListEqual(gerrit.blacklist_ids, ['willy'])
def setUp(self): super().setUp() self.backend_write_archive = Gerrit(GERRIT_REPO, user=GERRIT_USER, port=29418, max_reviews=2, archive=self.archive) self.backend_read_archive = Gerrit(GERRIT_REPO, user="******", port=29418, max_reviews=2, archive=self.archive)
def test_fetch_from_archive(self): """Test whether a list of reviews is returned from the archive""" mock_check_ouput.side_effect = mock_check_ouput self.backend = Gerrit(GERRIT_REPO, user=GERRIT_USER, port=29418, max_reviews=2, archive=self.archive) self._test_fetch_from_archive(from_date=None)
def test_fetch_from_empty_archive(self): """Test whether no reviews are returned when the archive is empty""" mock_check_ouput.side_effect = mock_check_ouput self.backend = Gerrit(GERRIT_REPO, user=GERRIT_USER, max_reviews=2, archive=self.archive) from_date = datetime.datetime(2100, 3, 5) self._test_fetch_from_archive(from_date=from_date)
def test_fetch_from_date_from_archive(self): """Test whether a list of reviews is returned from archive after a given date""" mock_check_ouput.side_effect = mock_check_ouput self.backend = Gerrit(GERRIT_REPO, user=GERRIT_USER, max_reviews=2, archive=self.archive) from_date = datetime.datetime(2018, 3, 5) self._test_fetch_from_archive(from_date=from_date)
def test_initialization(self): """Test whether attributes are initializated""" gerrit = Gerrit(GERRIT_REPO, tag='test') self.assertEqual(gerrit.url, GERRIT_REPO) self.assertEqual(gerrit.port, PORT) self.assertEqual(gerrit.max_reviews, MAX_REVIEWS) self.assertIsNone(gerrit.user) self.assertEqual(gerrit.tag, 'test') self.assertIsNone(gerrit.client) gerrit = Gerrit(GERRIT_REPO, GERRIT_USER, port=1000, max_reviews=100) self.assertEqual(gerrit.url, GERRIT_REPO) self.assertEqual(gerrit.port, 1000) self.assertEqual(gerrit.max_reviews, 100) self.assertEqual(gerrit.tag, GERRIT_REPO) self.assertEqual(gerrit.user, GERRIT_USER) self.assertIsNone(gerrit.client)
def test_serch_fields(self): """Test whether the search_fields is properly set""" mock_check_ouput.side_effect = mock_check_ouput gerrit = Gerrit(GERRIT_REPO, user=GERRIT_USER, port=29418, max_reviews=2) reviews = [review for review in gerrit.fetch(from_date=None)] self.assertIsNotNone(gerrit.client) self.assertEqual(len(reviews), 5) review = reviews[0] self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id']) self.assertEqual(review['data']['project'], 'operations/puppet') self.assertEqual(review['data']['project'], review['search_fields']['project_name']) self.assertEqual(review['data']['id'], 'I99a07b8e55560db3ddc00e0c8c30c62b65136556') self.assertEqual(review['data']['id'], review['search_fields']['review_hash']) review = reviews[1] self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id']) self.assertEqual(review['data']['project'], 'mediawiki/extensions/Wikibase') self.assertEqual(review['data']['project'], review['search_fields']['project_name']) self.assertEqual(review['data']['id'], 'I9ad743250f37c3be369888b1b9be80d8d332f62f') self.assertEqual(review['data']['id'], review['search_fields']['review_hash']) review = reviews[2] self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id']) self.assertEqual(review['data']['project'], 'operations/mediawiki-config') self.assertEqual(review['data']['project'], review['search_fields']['project_name']) self.assertEqual(review['data']['id'], 'I9992907ef53f122b54ef2c64146da513477db025') self.assertEqual(review['data']['id'], review['search_fields']['review_hash']) review = reviews[3] self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id']) self.assertEqual(review['data']['project'], 'operations/puppet') self.assertEqual(review['data']['project'], review['search_fields']['project_name']) self.assertEqual(review['data']['id'], 'I3d8e4685095da4b6a53e826c8a73ec13e4d562d2') self.assertEqual(review['data']['id'], review['search_fields']['review_hash']) review = reviews[4] self.assertEqual(gerrit.metadata_id(review['data']), review['search_fields']['item_id']) self.assertEqual(review['data']['project'], 'operations/mediawiki-config') self.assertEqual(review['data']['project'], review['search_fields']['project_name']) self.assertEqual(review['data']['id'], 'I9992907ef53f122b54ef2c64146da513477db025') self.assertEqual(review['data']['id'], review['search_fields']['review_hash'])
def test_parse_reviews(self): """Test parse reviews method""" raw_reviews = read_file('data/gerrit/gerrit_reviews_page_1') reviews = Gerrit.parse_reviews(raw_reviews) self.assertEqual(len(reviews), 2) review = reviews[0] self.assertEqual(len(review['comments']), 5) self.assertEqual(review['owner']['username'], 'gehel') self.assertEqual(len(review['patchSets']), 2) review = reviews[1] self.assertEqual(len(review['comments']), 26) self.assertEqual(review['owner']['username'], "lucaswerkmeister-wmde") self.assertEqual(len(review['patchSets']), 1)
def test_has_resuming(self): """Test if it returns False when has_resuming is called""" self.assertEqual(Gerrit.has_resuming(), False)
def test_has_archiving(self): """Test if it returns True when has_archiving is called""" self.assertEqual(Gerrit.has_archiving(), True)
file4 = open( "D:\\Ak_work2019-2020\\HigherDimensions\\jdtData\\CommentRevNames2020.txt", "w") file5 = open( "D:\\Ak_work2019-2020\\HigherDimensions\\jdtData\\ApproverNames2020.txt", "w") file6 = open( "D:\\Ak_work2019-2020\\HigherDimensions\\jdtData\\AuthorNames2020.txt", "w") file8 = open( "D:\\Ak_work2019-2020\\HigherDimensions\\jdtData\\ReviewFilesFromComments.txt", "w") reviewData = open( "D:\\Ak_work2019-2020\\HigherDimensions\\jdtData\\ReviewData.txt", "w") repo = Gerrit(hostname=hostname, user=user) uploaderNames = {} authorNames = {} ownerNames = {} reviewerNames = {} approverNames = {} uploaderIdx = 0 authorIdx = 0 ownerIdx = 0 reviewerIdx = 0 approverIdx = 0 dateN = datetime.datetime(2019, 12, 18, 0, 0) dateLast = datetime.datetime(2020, 6, 23, 0, 0).timestamp() def Str(elem):
#! /usr/bin/env python3 import datetime from perceval.backends.core.gerrit import Gerrit # hostname of the Gerrit instance hostname = 'gerrit.opnfv.org' # user for sshing to the Gerrit instance user = '******' # retrieve only reviews changed since this date from_date = datetime.datetime.now() - datetime.timedelta(days=1) # create a Gerrit object, pointing to hostname, using user for ssh access repo = Gerrit(url=hostname, user=user) # fetch all reviews as an iterator, and iterate it printing each review id for review in repo.fetch(from_date=from_date): print("Review:", review['data']['number'], review['data']['url'], end='') print(review['data']['status'], review['data']['open']) print(" Patchsets:") for patch in review['data']['patchSets']: print(" ", patch['number'], "Draft:", patch['isDraft'], patch['kind']) print(" Comments:") for comment in review['data']['comments']: print(" Comment:") for line in comment['message'].splitlines(): print(" ", line)