def test_fetch_since_date(self): """Test whether commits are fetched from a Git repository since the given date""" new_path = os.path.join(self.tmp_path, 'newgit') from_date = datetime.datetime(2014, 2, 11, 22, 7, 49) git = Git(self.git_path, new_path) commits = [commit for commit in git.fetch(from_date=from_date)] expected = [('ce8e0b86a1e9877f42fe9453ede418519115f367', 1392185269.0), ('51a3b654f252210572297f47597b31527c475fb8', 1392185366.0), ('456a68ee1407a77f3e804a30dff245bb6c6b872f', 1392185439.0)] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x][0]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x][0]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['updated_on'], expected[x][1]) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) # Test it using a datetime that includes the timezone from_date = datetime.datetime(2012, 8, 14, 14, 30, 00, tzinfo=dateutil.tz.tzoffset( None, -36000)) git = Git(self.git_path, new_path) commits = [commit for commit in git.fetch(from_date=from_date)] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x][0]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x][0]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['updated_on'], expected[x][1]) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) shutil.rmtree(new_path)
def test_fetch(self): """Test whether commits are fetched from a Git repository""" new_path = os.path.join(self.tmp_path, 'newgit') git = Git(self.git_path, new_path) commits = [commit for commit in git.fetch()] expected = [('bc57a9209f096a130dcc5ba7089a8663f758a703', 1344965413.0), ('87783129c3f00d2c81a3a8e585eb86a47e39891a', 1344965535.0), ('7debcf8a2f57f86663809c58b5c07a398be7674c', 1344965607.0), ('c0d66f92a95e31c77be08dc9d0f11a16715d1885', 1344965702.0), ('c6ba8f7a1058db3e6b4bc6f1090e932b107605fb', 1344966351.0), ('589bb080f059834829a2a5955bebfd7c2baa110a', 1344967441.0), ('ce8e0b86a1e9877f42fe9453ede418519115f367', 1392185269.0), ('51a3b654f252210572297f47597b31527c475fb8', 1392185366.0), ('456a68ee1407a77f3e804a30dff245bb6c6b872f', 1392185439.0)] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x][0]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x][0]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['updated_on'], expected[x][1]) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) shutil.rmtree(new_path)
def test_fetch(self): """Test whether a list of commits is returned""" git = Git("data/git_log.txt") commits = [commit for commit in git.fetch()] # Commits are returned in reverse order expected = [('bc57a9209f096a130dcc5ba7089a8663f758a703', 'Tue Aug 14 14:30:13 2012 -0300'), ('87783129c3f00d2c81a3a8e585eb86a47e39891a', 'Tue Aug 14 14:32:15 2012 -0300'), ('7debcf8a2f57f86663809c58b5c07a398be7674c', 'Tue Aug 14 14:33:27 2012 -0300'), ('c0d66f92a95e31c77be08dc9d0f11a16715d1885', 'Tue Aug 14 14:35:02 2012 -0300'), ('c6ba8f7a1058db3e6b4bc6f1090e932b107605fb', 'Tue Aug 14 14:45:51 2012 -0300'), ('589bb080f059834829a2a5955bebfd7c2baa110a', 'Tue Aug 14 15:04:01 2012 -0300'), ('ce8e0b86a1e9877f42fe9453ede418519115f367', 'Tue Feb 11 22:07:49 2014 -0800'), ('51a3b654f252210572297f47597b31527c475fb8', 'Tue Feb 11 22:09:26 2014 -0800'), ('456a68ee1407a77f3e804a30dff245bb6c6b872f', 'Tue Feb 11 22:10:39 2014 -0800')] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): commit = commits[x] self.assertEqual(commit['commit'], expected[x][0]) self.assertEqual(commit['__metadata__']['origin'], 'data/git_log.txt') self.assertEqual(commit['__metadata__']['updated_on'], expected[x][1])
def test_initialization(self): """Test whether attributes are initializated""" git = Git('http://example.com', self.git_path, tag='test') self.assertEqual(git.uri, 'http://example.com') self.assertEqual(git.gitpath, self.git_path) self.assertEqual(git.origin, 'http://example.com') self.assertEqual(git.tag, 'test') # When tag is empty or None it will be set to # the value in uri git = Git('http://example.com', self.git_path) self.assertEqual(git.origin, 'http://example.com') self.assertEqual(git.tag, 'http://example.com') git = Git('http://example.com', self.git_path, tag='') self.assertEqual(git.origin, 'http://example.com') self.assertEqual(git.tag, 'http://example.com')
def test_fetch_empty_log(self): """Test whether it parsers an empty log""" new_path = os.path.join(self.tmp_path, 'newgit') from_date = datetime.datetime(2020, 1, 1, 1, 1, 1) git = Git(self.git_path, new_path) commits = [commit for commit in git.fetch(from_date=from_date)] self.assertListEqual(commits, [])
def test_fetch_branch(self): """Test whether commits are fetched from a Git repository for a given branch""" new_path = os.path.join(self.tmp_path, 'newgit') from_date = datetime.datetime(2014, 2, 11, 22, 7, 49) git = Git(self.git_path, new_path) # Let's fetch master commits = [commit for commit in git.fetch(branches=['master'])] expected = ['bc57a9209f096a130dcc5ba7089a8663f758a703', '87783129c3f00d2c81a3a8e585eb86a47e39891a', '7debcf8a2f57f86663809c58b5c07a398be7674c', 'c0d66f92a95e31c77be08dc9d0f11a16715d1885', 'c6ba8f7a1058db3e6b4bc6f1090e932b107605fb', '589bb080f059834829a2a5955bebfd7c2baa110a', 'ce8e0b86a1e9877f42fe9453ede418519115f367', '51a3b654f252210572297f47597b31527c475fb8', '456a68ee1407a77f3e804a30dff245bb6c6b872f'] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) # Now let's fetch lzp commits = [commit for commit in git.fetch(branches=['lzp'])] expected = ['bc57a9209f096a130dcc5ba7089a8663f758a703', '87783129c3f00d2c81a3a8e585eb86a47e39891a', '7debcf8a2f57f86663809c58b5c07a398be7674c', 'c0d66f92a95e31c77be08dc9d0f11a16715d1885', 'c6ba8f7a1058db3e6b4bc6f1090e932b107605fb', '589bb080f059834829a2a5955bebfd7c2baa110a', '51a3b654f252210572297f47597b31527c475fb8'] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) # Now, let's fech master and lzp commits = [commit for commit in git.fetch(branches=['master', 'lzp'])] expected = ['bc57a9209f096a130dcc5ba7089a8663f758a703', '87783129c3f00d2c81a3a8e585eb86a47e39891a', '7debcf8a2f57f86663809c58b5c07a398be7674c', 'c0d66f92a95e31c77be08dc9d0f11a16715d1885', 'c6ba8f7a1058db3e6b4bc6f1090e932b107605fb', '589bb080f059834829a2a5955bebfd7c2baa110a', 'ce8e0b86a1e9877f42fe9453ede418519115f367', '51a3b654f252210572297f47597b31527c475fb8', '456a68ee1407a77f3e804a30dff245bb6c6b872f'] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) # Now, let's fetch None, which means "all commits" commits = [commit for commit in git.fetch(branches=None)] expected = ['bc57a9209f096a130dcc5ba7089a8663f758a703', '87783129c3f00d2c81a3a8e585eb86a47e39891a', '7debcf8a2f57f86663809c58b5c07a398be7674c', 'c0d66f92a95e31c77be08dc9d0f11a16715d1885', 'c6ba8f7a1058db3e6b4bc6f1090e932b107605fb', '589bb080f059834829a2a5955bebfd7c2baa110a', 'ce8e0b86a1e9877f42fe9453ede418519115f367', '51a3b654f252210572297f47597b31527c475fb8', '456a68ee1407a77f3e804a30dff245bb6c6b872f'] self.assertEqual(len(commits), len(expected)) for x in range(len(commits)): expected_uuid = uuid(self.git_path, expected[x]) commit = commits[x] self.assertEqual(commit['data']['commit'], expected[x]) self.assertEqual(commit['origin'], self.git_path) self.assertEqual(commit['uuid'], expected_uuid) self.assertEqual(commit['category'], 'commit') self.assertEqual(commit['tag'], self.git_path) # Now, let's fetch [], which means "no commits" commits = [commit for commit in git.fetch(branches=[])] expected = [] self.assertEqual(len(commits), len(expected)) shutil.rmtree(new_path)