|
Pierre-Yves Chibon |
a945ba |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
"""
|
|
Pierre-Yves Chibon |
a945ba |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
Authors:
|
|
Pierre-Yves Chibon |
a945ba |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
"""
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
a945ba |
import pkg_resources
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
c009bb |
import json
|
|
Pierre-Yves Chibon |
a945ba |
import unittest
|
|
Pierre-Yves Chibon |
a945ba |
import shutil
|
|
Pierre-Yves Chibon |
a945ba |
import sys
|
|
Pierre-Yves Chibon |
a945ba |
import os
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
024459 |
import pygit2
|
|
Pierre-Yves Chibon |
a945ba |
from mock import patch
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
a945ba |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
fe5017 |
import pagure.lib.git
|
|
Pierre-Yves Chibon |
a945ba |
import tests
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
fe5017 |
class PagureLibGittests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Tests for pagure.lib.git """
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a7c15a |
def setUp(self):
|
|
Pierre-Yves Chibon |
a7c15a |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
a7c15a |
super(PagureLibGittests, self).setUp()
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
fd747d |
pagure.lib.git.SESSION = self.session
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['GIT_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
fd747d |
tests.HERE, 'repos')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['FORK_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
fd747d |
tests.HERE, 'forks')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
fd747d |
tests.HERE, 'tickets')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
fd747d |
tests.HERE, 'docs')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Pierre-Yves Chibon |
fd747d |
tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
a945ba |
def test_write_gitolite_acls(self):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the write_gitolite_acls function of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
a945ba |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
ead0df |
# Add an user to a project
|
|
Pierre-Yves Chibon |
fe5017 |
msg = pagure.lib.add_user_to_project(
|
|
Pierre-Yves Chibon |
ead0df |
session=self.session,
|
|
Pierre-Yves Chibon |
ead0df |
project=repo,
|
|
Pierre-Yves Chibon |
a5a9ad |
new_user='foo',
|
|
Pierre-Yves Chibon |
a5a9ad |
user='pingou',
|
|
Pierre-Yves Chibon |
ead0df |
)
|
|
Pierre-Yves Chibon |
ead0df |
self.session.commit()
|
|
Pierre-Yves Chibon |
ead0df |
self.assertEqual(msg, 'User added')
|
|
Pierre-Yves Chibon |
ead0df |
# Add a forked project
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
ead0df |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
ead0df |
name='test3',
|
|
Pierre-Yves Chibon |
ead0df |
description='test project #2',
|
|
Pierre-Yves Chibon |
e2259d |
parent_id=1,
|
|
Pierre-Yves Chibon |
e2259d |
hook_token='aaabbbvvv',
|
|
Pierre-Yves Chibon |
ead0df |
)
|
|
Pierre-Yves Chibon |
ead0df |
self.session.add(item)
|
|
Pierre-Yves Chibon |
ead0df |
self.session.commit()
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
6e1ebb |
outputconf = os.path.join(tests.HERE, 'test_gitolite.conf')
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.write_gitolite_acls(self.session, outputconf)
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
self.assertTrue(os.path.exists(outputconf))
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
with open(outputconf) as stream:
|
|
Pierre-Yves Chibon |
a945ba |
data = stream.read()
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
0c1d74 |
exp = """
|
|
Pierre-Yves Chibon |
0c1d74 |
repo test
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = foo
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
repo docs/test
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = foo
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
repo tickets/test
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = foo
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
a6701e |
repo requests/test
|
|
Pierre-Yves Chibon |
a6701e |
R = @all
|
|
Pierre-Yves Chibon |
a6701e |
RW+ = pingou
|
|
Pierre-Yves Chibon |
a6701e |
RW+ = foo
|
|
Pierre-Yves Chibon |
a6701e |
|
|
Pierre-Yves Chibon |
ead0df |
repo test2
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
repo docs/test2
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
repo tickets/test2
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
a6701e |
repo requests/test2
|
|
Pierre-Yves Chibon |
a6701e |
R = @all
|
|
Pierre-Yves Chibon |
a6701e |
RW+ = pingou
|
|
Pierre-Yves Chibon |
a6701e |
|
|
Pierre-Yves Chibon |
ead0df |
repo forks/pingou/test3
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
repo docs/pingou/test3
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
repo tickets/pingou/test3
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
a6701e |
RW+ = pingou
|
|
Pierre-Yves Chibon |
a6701e |
|
|
Pierre-Yves Chibon |
a6701e |
repo requests/pingou/test3
|
|
Pierre-Yves Chibon |
a6701e |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
"""
|
|
Pierre-Yves Chibon |
ead0df |
self.assertEqual(data, exp)
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
22e4bd |
os.unlink(outputconf)
|
|
Pierre-Yves Chibon |
22e4bd |
self.assertFalse(os.path.exists(outputconf))
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
4fc47a |
def test_write_gitolite_acls_groups(self):
|
|
Pierre-Yves Chibon |
4fc47a |
""" Test the write_gitolite_acls function of pagure.lib.git with
|
|
Pierre-Yves Chibon |
4fc47a |
groups.
|
|
Pierre-Yves Chibon |
4fc47a |
"""
|
|
Pierre-Yves Chibon |
4fc47a |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
6f5851 |
# Add a couple of groups
|
|
Pierre-Yves Chibon |
4fc47a |
msg = pagure.lib.add_group(
|
|
Pierre-Yves Chibon |
4fc47a |
self.session,
|
|
Pierre-Yves Chibon |
4fc47a |
group_name='sysadmin',
|
|
Pierre-Yves Chibon |
4fc47a |
group_type='user',
|
|
Pierre-Yves Chibon |
4fc47a |
user='pingou',
|
|
Pierre-Yves Chibon |
4fc47a |
is_admin=False,
|
|
Pierre-Yves Chibon |
4fc47a |
)
|
|
Pierre-Yves Chibon |
4fc47a |
self.session.commit()
|
|
Pierre-Yves Chibon |
4fc47a |
self.assertEqual(msg, 'User `pingou` added to the group `sysadmin`.')
|
|
Pierre-Yves Chibon |
6f5851 |
msg = pagure.lib.add_group(
|
|
Pierre-Yves Chibon |
6f5851 |
self.session,
|
|
Pierre-Yves Chibon |
6f5851 |
group_name='devs',
|
|
Pierre-Yves Chibon |
6f5851 |
group_type='user',
|
|
Pierre-Yves Chibon |
6f5851 |
user='pingou',
|
|
Pierre-Yves Chibon |
6f5851 |
is_admin=False,
|
|
Pierre-Yves Chibon |
6f5851 |
)
|
|
Pierre-Yves Chibon |
6f5851 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6f5851 |
self.assertEqual(msg, 'User `pingou` added to the group `devs`.')
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
6f5851 |
# Associate these groups to a project
|
|
Pierre-Yves Chibon |
4fc47a |
msg = pagure.lib.add_group_to_project(
|
|
Pierre-Yves Chibon |
4fc47a |
session=self.session,
|
|
Pierre-Yves Chibon |
4fc47a |
project=repo,
|
|
Pierre-Yves Chibon |
4fc47a |
new_group='sysadmin',
|
|
Pierre-Yves Chibon |
4fc47a |
user='pingou',
|
|
Pierre-Yves Chibon |
4fc47a |
)
|
|
Pierre-Yves Chibon |
4fc47a |
self.session.commit()
|
|
Pierre-Yves Chibon |
4fc47a |
self.assertEqual(msg, 'Group added')
|
|
Pierre-Yves Chibon |
6f5851 |
msg = pagure.lib.add_group_to_project(
|
|
Pierre-Yves Chibon |
6f5851 |
session=self.session,
|
|
Pierre-Yves Chibon |
6f5851 |
project=repo,
|
|
Pierre-Yves Chibon |
6f5851 |
new_group='devs',
|
|
Pierre-Yves Chibon |
6f5851 |
user='pingou',
|
|
Pierre-Yves Chibon |
6f5851 |
)
|
|
Pierre-Yves Chibon |
6f5851 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6f5851 |
self.assertEqual(msg, 'Group added')
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
# Add an user to a project
|
|
Pierre-Yves Chibon |
4fc47a |
msg = pagure.lib.add_user_to_project(
|
|
Pierre-Yves Chibon |
4fc47a |
session=self.session,
|
|
Pierre-Yves Chibon |
4fc47a |
project=repo,
|
|
Pierre-Yves Chibon |
4fc47a |
new_user='foo',
|
|
Pierre-Yves Chibon |
4fc47a |
user='pingou',
|
|
Pierre-Yves Chibon |
4fc47a |
)
|
|
Pierre-Yves Chibon |
4fc47a |
self.session.commit()
|
|
Pierre-Yves Chibon |
4fc47a |
self.assertEqual(msg, 'User added')
|
|
Pierre-Yves Chibon |
4fc47a |
# Add a forked project
|
|
Pierre-Yves Chibon |
4fc47a |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
4fc47a |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
4fc47a |
name='test2',
|
|
Pierre-Yves Chibon |
4fc47a |
description='test project #2',
|
|
Pierre-Yves Chibon |
4fc47a |
parent_id=1,
|
|
Pierre-Yves Chibon |
4fc47a |
hook_token='aaabbbvvv',
|
|
Pierre-Yves Chibon |
4fc47a |
)
|
|
Pierre-Yves Chibon |
4fc47a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
4fc47a |
self.session.commit()
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
outputconf = os.path.join(tests.HERE, 'test_gitolite.conf')
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
pagure.lib.git.write_gitolite_acls(self.session, outputconf)
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
self.assertTrue(os.path.exists(outputconf))
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
with open(outputconf) as stream:
|
|
Pierre-Yves Chibon |
4fc47a |
data = stream.read()
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
exp = """@sysadmin = pingou
|
|
Pierre-Yves Chibon |
6f5851 |
@devs = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo test
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
6f5851 |
RW+ = @sysadmin @devs
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = foo
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo docs/test
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
6f5851 |
RW+ = @sysadmin @devs
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = foo
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo tickets/test
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
6f5851 |
RW+ = @sysadmin @devs
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = foo
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo requests/test
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
6f5851 |
RW+ = @sysadmin @devs
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = foo
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo docs/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo tickets/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo requests/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo forks/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo docs/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo tickets/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo requests/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
"""
|
|
Pierre-Yves Chibon |
4fc47a |
self.assertEqual(data.split('\n'), exp.split('\n'))
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
os.unlink(outputconf)
|
|
Pierre-Yves Chibon |
4fc47a |
self.assertFalse(os.path.exists(outputconf))
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
024459 |
def test_commit_to_patch(self):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the commit_to_patch function of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
024459 |
# Create a git repo to play with
|
|
Pierre-Yves Chibon |
6e1ebb |
self.gitrepo = os.path.join(tests.HERE, 'test_repo.git')
|
|
Pierre-Yves Chibon |
024459 |
os.makedirs(self.gitrepo)
|
|
Pierre-Yves Chibon |
024459 |
repo = pygit2.init_repository(self.gitrepo)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
# Create a file in that git repo
|
|
Pierre-Yves Chibon |
024459 |
with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
024459 |
stream.write('foo\n bar')
|
|
Pierre-Yves Chibon |
024459 |
repo.index.add('sources')
|
|
Pierre-Yves Chibon |
024459 |
repo.index.write()
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
# Commits the files added
|
|
Pierre-Yves Chibon |
024459 |
tree = repo.index.write_tree()
|
|
Pierre-Yves Chibon |
024459 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
024459 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
024459 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
024459 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
024459 |
repo.create_commit(
|
|
Pierre-Yves Chibon |
024459 |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
024459 |
author,
|
|
Pierre-Yves Chibon |
024459 |
committer,
|
|
Pierre-Yves Chibon |
024459 |
'Add sources file for testing',
|
|
Pierre-Yves Chibon |
024459 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
024459 |
tree,
|
|
Pierre-Yves Chibon |
024459 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
024459 |
[]
|
|
Pierre-Yves Chibon |
024459 |
)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
first_commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
# Edit the sources file again
|
|
Pierre-Yves Chibon |
024459 |
with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
024459 |
stream.write('foo\n bar\nbaz\n boose')
|
|
Pierre-Yves Chibon |
024459 |
repo.index.add('sources')
|
|
Pierre-Yves Chibon |
024459 |
repo.index.write()
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
# Commits the files added
|
|
Pierre-Yves Chibon |
024459 |
tree = repo.index.write_tree()
|
|
Pierre-Yves Chibon |
024459 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
024459 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
024459 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
024459 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
024459 |
repo.create_commit(
|
|
Pierre-Yves Chibon |
024459 |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
024459 |
author,
|
|
Pierre-Yves Chibon |
024459 |
committer,
|
|
Pierre-Yves Chibon |
024459 |
'Add baz and boose to the sources\n\n There are more objects to '
|
|
Pierre-Yves Chibon |
024459 |
'consider',
|
|
Pierre-Yves Chibon |
024459 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
024459 |
tree,
|
|
Pierre-Yves Chibon |
024459 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
024459 |
[first_commit.oid.hex]
|
|
Pierre-Yves Chibon |
024459 |
)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
second_commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
# Generate a patch for 2 commits
|
|
Pierre-Yves Chibon |
fe5017 |
patch = pagure.lib.git.commit_to_patch(
|
|
Pierre-Yves Chibon |
024459 |
repo, [first_commit, second_commit])
|
|
Pierre-Yves Chibon |
024459 |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
024459 |
From: Alice Author <alice@authors.tld></alice@authors.tld>
|
|
Pierre-Yves Chibon |
024459 |
Subject: [PATCH 1/2] Add sources file for testing
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
---
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
024459 |
new file mode 100644
|
|
Pierre-Yves Chibon |
024459 |
index 0000000..9f44358
|
|
Pierre-Yves Chibon |
024459 |
--- /dev/null
|
|
Pierre-Yves Chibon |
024459 |
+++ b/sources
|
|
Pierre-Yves Chibon |
024459 |
@@ -0,0 +1,2 @@
|
|
Pierre-Yves Chibon |
024459 |
+foo
|
|
Pierre-Yves Chibon |
024459 |
+ bar
|
|
Pierre-Yves Chibon |
024459 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
024459 |
From: Alice Author <alice@authors.tld></alice@authors.tld>
|
|
Pierre-Yves Chibon |
024459 |
Subject: [PATCH 2/2] Add baz and boose to the sources
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
There are more objects to consider
|
|
Pierre-Yves Chibon |
024459 |
---
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
024459 |
index 9f44358..2a552bb 100644
|
|
Pierre-Yves Chibon |
024459 |
--- a/sources
|
|
Pierre-Yves Chibon |
024459 |
+++ b/sources
|
|
Pierre-Yves Chibon |
024459 |
@@ -1,2 +1,4 @@
|
|
Pierre-Yves Chibon |
024459 |
foo
|
|
Pierre-Yves Chibon |
024459 |
- bar
|
|
Pierre-Yves Chibon |
024459 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
024459 |
+ bar
|
|
Pierre-Yves Chibon |
024459 |
+baz
|
|
Pierre-Yves Chibon |
024459 |
+ boose
|
|
Pierre-Yves Chibon |
024459 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
"""
|
|
Pierre-Yves Chibon |
024459 |
npatch = []
|
|
Pierre-Yves Chibon |
024459 |
for row in patch.split('\n'):
|
|
Pierre-Yves Chibon |
024459 |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
024459 |
continue
|
|
Pierre-Yves Chibon |
024459 |
if row.startswith('From '):
|
|
Pierre-Yves Chibon |
024459 |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
024459 |
npatch.append(row)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
024459 |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
# Generate a patch for a single commit
|
|
Pierre-Yves Chibon |
fe5017 |
patch = pagure.lib.git.commit_to_patch(repo, second_commit)
|
|
Pierre-Yves Chibon |
024459 |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
024459 |
From: Alice Author <alice@authors.tld></alice@authors.tld>
|
|
Pierre-Yves Chibon |
024459 |
Subject: Add baz and boose to the sources
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
There are more objects to consider
|
|
Pierre-Yves Chibon |
024459 |
---
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
024459 |
index 9f44358..2a552bb 100644
|
|
Pierre-Yves Chibon |
024459 |
--- a/sources
|
|
Pierre-Yves Chibon |
024459 |
+++ b/sources
|
|
Pierre-Yves Chibon |
024459 |
@@ -1,2 +1,4 @@
|
|
Pierre-Yves Chibon |
024459 |
foo
|
|
Pierre-Yves Chibon |
024459 |
- bar
|
|
Pierre-Yves Chibon |
024459 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
024459 |
+ bar
|
|
Pierre-Yves Chibon |
024459 |
+baz
|
|
Pierre-Yves Chibon |
024459 |
+ boose
|
|
Pierre-Yves Chibon |
024459 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
"""
|
|
Pierre-Yves Chibon |
024459 |
npatch = []
|
|
Pierre-Yves Chibon |
024459 |
for row in patch.split('\n'):
|
|
Pierre-Yves Chibon |
024459 |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
024459 |
continue
|
|
Pierre-Yves Chibon |
024459 |
if row.startswith('From '):
|
|
Pierre-Yves Chibon |
024459 |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
024459 |
npatch.append(row)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
024459 |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
024459 |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
024459 |
|
|
Pierre-Yves Chibon |
fe5017 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
d2faf2 |
def test_update_git(self, email_f):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the update_git of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
c009bb |
email_f.return_value = True
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
# Create project
|
|
Pierre-Yves Chibon |
fe5017 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
c009bb |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
c009bb |
name='test_ticket_repo',
|
|
Pierre-Yves Chibon |
c009bb |
description='test project for ticket',
|
|
Pierre-Yves Chibon |
e2259d |
hook_token='aaabbbwww',
|
|
Pierre-Yves Chibon |
c009bb |
)
|
|
Pierre-Yves Chibon |
c009bb |
self.session.add(item)
|
|
Pierre-Yves Chibon |
c009bb |
self.session.commit()
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
# Create repo
|
|
Pierre-Yves Chibon |
6e1ebb |
self.gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
c009bb |
os.makedirs(self.gitrepo)
|
|
Pierre-Yves Chibon |
c009bb |
repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
|
|
Pierre-Yves Chibon |
c009bb |
# Create an issue to play with
|
|
Pierre-Yves Chibon |
fe5017 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
c009bb |
session=self.session,
|
|
Pierre-Yves Chibon |
c009bb |
repo=repo,
|
|
Pierre-Yves Chibon |
c009bb |
title='Test issue',
|
|
Pierre-Yves Chibon |
c009bb |
content='We should work on this',
|
|
Pierre-Yves Chibon |
c009bb |
user='pingou',
|
|
Pierre-Yves Chibon |
6e1ebb |
ticketfolder=tests.HERE
|
|
Pierre-Yves Chibon |
c009bb |
)
|
|
Pierre-Yves Chibon |
11d78c |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
fe5017 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_git(issue, repo, tests.HERE)
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
repo = pygit2.Repository(self.gitrepo)
|
|
Pierre-Yves Chibon |
c009bb |
commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
# Use patch to validate the repo
|
|
Pierre-Yves Chibon |
fe5017 |
patch = pagure.lib.git.commit_to_patch(repo, commit)
|
|
Pierre-Yves Chibon |
c009bb |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
fe5017 |
From: pagure <pagure></pagure>
|
|
Pierre-Yves Chibon |
c009bb |
Subject: Updated ticket <hash>: Test issue</hash>
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
---
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
diff --git a/123 b/456
|
|
Pierre-Yves Chibon |
c009bb |
new file mode 100644
|
|
Pierre-Yves Chibon |
c009bb |
index 0000000..60f7480
|
|
Pierre-Yves Chibon |
c009bb |
--- /dev/null
|
|
Pierre-Yves Chibon |
c009bb |
+++ b/456
|
|
Pierre-Yves Chibon |
c009bb |
@@ -0,0 +1 @@
|
|
Pierre-Yves Chibon |
ec853d |
+{"status": "Open", "blocks": [], "tags": [], "title": "Test issue", "private": false, "content": "We should work on this", "assignee": null, "depends": [], "user": {"fullname": "PY C", "default_email": "bar@pingou.com", "name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "id": 1, "comments": []}
|
|
Pierre-Yves Chibon |
c009bb |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
"""
|
|
Pierre-Yves Chibon |
c009bb |
npatch = []
|
|
Pierre-Yves Chibon |
c009bb |
for row in patch.split('\n'):
|
|
Pierre-Yves Chibon |
c009bb |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
c009bb |
continue
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('From '):
|
|
Pierre-Yves Chibon |
c009bb |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('diff --git '):
|
|
Pierre-Yves Chibon |
c009bb |
row = row.split(' ')
|
|
Pierre-Yves Chibon |
c009bb |
row[2] = 'a/123'
|
|
Pierre-Yves Chibon |
c009bb |
row[3] = 'b/456'
|
|
Pierre-Yves Chibon |
c009bb |
row = ' '.join(row)
|
|
Pierre-Yves Chibon |
c009bb |
elif 'Updated ticket' in row:
|
|
Pierre-Yves Chibon |
c009bb |
row = row.split()
|
|
Pierre-Yves Chibon |
c009bb |
row[3] = '<hash>:'</hash>
|
|
Pierre-Yves Chibon |
c009bb |
row = ' '.join(row)
|
|
Pierre-Yves Chibon |
c009bb |
elif 'date_created' in row:
|
|
Pierre-Yves Chibon |
c009bb |
data = json.loads(row[1:])
|
|
Pierre-Yves Chibon |
c009bb |
data['date_created'] = None
|
|
Pierre-Yves Chibon |
c009bb |
row = '+' + json.dumps(data)
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('index 00'):
|
|
Pierre-Yves Chibon |
c009bb |
row = 'index 0000000..60f7480'
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('+++ b/'):
|
|
Pierre-Yves Chibon |
c009bb |
row = '+++ b/456'
|
|
Pierre-Yves Chibon |
c009bb |
npatch.append(row)
|
|
Pierre-Yves Chibon |
c009bb |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
df35d8 |
#print patch
|
|
Pierre-Yves Chibon |
c009bb |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
# Test again after adding a comment
|
|
Pierre-Yves Chibon |
fe5017 |
msg = pagure.lib.add_issue_comment(
|
|
Pierre-Yves Chibon |
c009bb |
session=self.session,
|
|
Pierre-Yves Chibon |
c009bb |
issue=issue,
|
|
Pierre-Yves Chibon |
c009bb |
comment='Hey look a comment!',
|
|
Pierre-Yves Chibon |
c009bb |
user='foo',
|
|
Pierre-Yves Chibon |
6e1ebb |
ticketfolder=tests.HERE
|
|
Pierre-Yves Chibon |
c009bb |
)
|
|
Pierre-Yves Chibon |
c009bb |
self.session.commit()
|
|
Pierre-Yves Chibon |
c009bb |
self.assertEqual(msg, 'Comment added')
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
# Use patch to validate the repo
|
|
Pierre-Yves Chibon |
c009bb |
repo = pygit2.Repository(self.gitrepo)
|
|
Pierre-Yves Chibon |
c009bb |
commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
fe5017 |
patch = pagure.lib.git.commit_to_patch(repo, commit)
|
|
Pierre-Yves Chibon |
c009bb |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
fe5017 |
From: pagure <pagure></pagure>
|
|
Pierre-Yves Chibon |
c009bb |
Subject: Updated ticket <hash>: Test issue</hash>
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
---
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
diff --git a/123 b/456
|
|
Pierre-Yves Chibon |
c009bb |
index 458821a..77674a8
|
|
Pierre-Yves Chibon |
c009bb |
--- a/123
|
|
Pierre-Yves Chibon |
c009bb |
+++ b/456
|
|
Pierre-Yves Chibon |
c009bb |
@@ -1 +1 @@
|
|
Pierre-Yves Chibon |
ec853d |
-{"status": "Open", "blocks": [], "tags": [], "title": "Test issue", "private": false, "content": "We should work on this", "assignee": null, "depends": [], "user": {"fullname": "PY C", "default_email": "bar@pingou.com", "name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "id": 1, "comments": []}
|
|
Pierre-Yves Chibon |
c009bb |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
ec853d |
+{"status": "Open", "blocks": [], "tags": [], "title": "Test issue", "private": false, "content": "We should work on this", "assignee": null, "depends": [], "user": {"fullname": "PY C", "default_email": "bar@pingou.com", "name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "id": 1, "comments": [{"comment": "Hey look a comment!", "date_created": null, "id": 1, "parent": null, "user": {"fullname": "foo bar", "default_email": "foo@bar.com", "name": "foo", "emails": ["foo@bar.com"]}}]}
|
|
Pierre-Yves Chibon |
c009bb |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
c009bb |
"""
|
|
Pierre-Yves Chibon |
c009bb |
npatch = []
|
|
Pierre-Yves Chibon |
c009bb |
for row in patch.split('\n'):
|
|
Pierre-Yves Chibon |
c009bb |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
c009bb |
continue
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('From '):
|
|
Pierre-Yves Chibon |
c009bb |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('diff --git '):
|
|
Pierre-Yves Chibon |
c009bb |
row = row.split(' ')
|
|
Pierre-Yves Chibon |
c009bb |
row[2] = 'a/123'
|
|
Pierre-Yves Chibon |
c009bb |
row[3] = 'b/456'
|
|
Pierre-Yves Chibon |
c009bb |
row = ' '.join(row)
|
|
Pierre-Yves Chibon |
c009bb |
elif 'Updated ticket' in row:
|
|
Pierre-Yves Chibon |
c009bb |
row = row.split()
|
|
Pierre-Yves Chibon |
c009bb |
row[3] = '<hash>:'</hash>
|
|
Pierre-Yves Chibon |
c009bb |
row = ' '.join(row)
|
|
Pierre-Yves Chibon |
c009bb |
elif 'date_created' in row:
|
|
Pierre-Yves Chibon |
c009bb |
data = json.loads(row[1:])
|
|
Pierre-Yves Chibon |
c009bb |
data['date_created'] = None
|
|
Pierre-Yves Chibon |
c009bb |
comments = []
|
|
Pierre-Yves Chibon |
c009bb |
for comment in data['comments']:
|
|
Pierre-Yves Chibon |
c009bb |
comment['date_created'] = None
|
|
Pierre-Yves Chibon |
c009bb |
comments.append(comment)
|
|
Pierre-Yves Chibon |
c009bb |
data['comments'] = comments
|
|
Pierre-Yves Chibon |
c009bb |
row = row[0] + json.dumps(data)
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('index'):
|
|
Pierre-Yves Chibon |
c009bb |
row = 'index 458821a..77674a8'
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('--- a/'):
|
|
Pierre-Yves Chibon |
c009bb |
row = '--- a/123'
|
|
Pierre-Yves Chibon |
c009bb |
elif row.startswith('+++ b/'):
|
|
Pierre-Yves Chibon |
c009bb |
row = '+++ b/456'
|
|
Pierre-Yves Chibon |
c009bb |
npatch.append(row)
|
|
Pierre-Yves Chibon |
c009bb |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
df35d8 |
#print patch
|
|
Pierre-Yves Chibon |
c009bb |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
c009bb |
|
|
Pierre-Yves Chibon |
e88bd7 |
def test_clean_git(self):
|
|
Pierre-Yves Chibon |
e88bd7 |
""" Test the clean_git method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
be8028 |
pagure.lib.git.clean_git(None, None, None)
|
|
Pierre-Yves Chibon |
be8028 |
|
|
Pierre-Yves Chibon |
e88bd7 |
self.test_update_git()
|
|
Pierre-Yves Chibon |
e88bd7 |
|
|
Pierre-Yves Chibon |
e88bd7 |
gitpath = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
e88bd7 |
gitrepo = pygit2.init_repository(gitpath, bare=True)
|
|
Pierre-Yves Chibon |
e88bd7 |
|
|
Pierre-Yves Chibon |
e88bd7 |
# Get the uid of the ticket created
|
|
Pierre-Yves Chibon |
e88bd7 |
commit = gitrepo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
e88bd7 |
patch = pagure.lib.git.commit_to_patch(gitrepo, commit)
|
|
Pierre-Yves Chibon |
e88bd7 |
hash_file = None
|
|
Pierre-Yves Chibon |
e88bd7 |
for row in patch.split('\n'):
|
|
Pierre-Yves Chibon |
e88bd7 |
if row.startswith('+++ b/'):
|
|
Pierre-Yves Chibon |
e88bd7 |
hash_file = row.split('+++ b/')[-1]
|
|
Pierre-Yves Chibon |
e88bd7 |
break
|
|
Pierre-Yves Chibon |
e88bd7 |
|
|
Pierre-Yves Chibon |
e88bd7 |
# The only file in git is the one of that ticket
|
|
Pierre-Yves Chibon |
e88bd7 |
files = [entry.name for entry in commit.tree]
|
|
Pierre-Yves Chibon |
e88bd7 |
self.assertEqual(files, [hash_file])
|
|
Pierre-Yves Chibon |
e88bd7 |
|
|
Pierre-Yves Chibon |
e88bd7 |
repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
|
|
Pierre-Yves Chibon |
e88bd7 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
e88bd7 |
pagure.lib.git.clean_git(issue, repo, tests.HERE, objtype='ticket')
|
|
Pierre-Yves Chibon |
e88bd7 |
|
|
Pierre-Yves Chibon |
e88bd7 |
# No more files in the git repo
|
|
Pierre-Yves Chibon |
e88bd7 |
commit = gitrepo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
e88bd7 |
files = [entry.name for entry in commit.tree]
|
|
Pierre-Yves Chibon |
e88bd7 |
self.assertEqual(files, [])
|
|
Pierre-Yves Chibon |
e88bd7 |
|
|
Pierre-Yves Chibon |
c070b4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
c070b4 |
def test_update_git_requests(self, email_f):
|
|
Pierre-Yves Chibon |
c070b4 |
""" Test the update_git of pagure.lib.git for pull-requests. """
|
|
Pierre-Yves Chibon |
c070b4 |
email_f.return_value = True
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
# Create project
|
|
Pierre-Yves Chibon |
c070b4 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
c070b4 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
c070b4 |
name='test_ticket_repo',
|
|
Pierre-Yves Chibon |
c070b4 |
description='test project for ticket',
|
|
Pierre-Yves Chibon |
e2259d |
hook_token='aaabbbxxx',
|
|
Pierre-Yves Chibon |
c070b4 |
)
|
|
Pierre-Yves Chibon |
c070b4 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
c070b4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
# Create repo
|
|
Pierre-Yves Chibon |
c070b4 |
self.gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
c070b4 |
os.makedirs(self.gitrepo)
|
|
Pierre-Yves Chibon |
c070b4 |
repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
repo = pagure.lib.get_project(self.session, 'test_ticket_repo')
|
|
Pierre-Yves Chibon |
c070b4 |
# Create an issue to play with
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
c070b4 |
session=self.session,
|
|
Pierre-Yves Chibon |
c070b4 |
repo_from=repo,
|
|
Pierre-Yves Chibon |
c070b4 |
branch_from='feature',
|
|
Pierre-Yves Chibon |
c070b4 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
c070b4 |
branch_to='master',
|
|
Pierre-Yves Chibon |
c070b4 |
title='test PR',
|
|
Pierre-Yves Chibon |
c070b4 |
user='pingou',
|
|
Pierre-Yves Chibon |
c070b4 |
requestfolder=tests.HERE,
|
|
Pierre-Yves Chibon |
c070b4 |
requestuid='foobar',
|
|
Pierre-Yves Chibon |
c070b4 |
requestid=None,
|
|
Pierre-Yves Chibon |
c070b4 |
status=True,
|
|
Pierre-Yves Chibon |
c070b4 |
notify=True
|
|
Pierre-Yves Chibon |
c070b4 |
)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test PR')
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
request = repo.requests[0]
|
|
Pierre-Yves Chibon |
c070b4 |
self.assertEqual(request.title, 'test PR')
|
|
Pierre-Yves Chibon |
a482cb |
pagure.lib.git.update_git(request, request.project, tests.HERE)
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
repo = pygit2.Repository(self.gitrepo)
|
|
Pierre-Yves Chibon |
c070b4 |
commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
# Use patch to validate the repo
|
|
Pierre-Yves Chibon |
c070b4 |
patch = pagure.lib.git.commit_to_patch(repo, commit)
|
|
Pierre-Yves Chibon |
c070b4 |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
c070b4 |
From: pagure <pagure></pagure>
|
|
Pierre-Yves Chibon |
c070b4 |
Subject: Updated ticket <hash>: test PR</hash>
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
---
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
diff --git a/123 b/456
|
|
Pierre-Yves Chibon |
c070b4 |
new file mode 100644
|
|
Pierre-Yves Chibon |
c070b4 |
index 0000000..60f7480
|
|
Pierre-Yves Chibon |
c070b4 |
--- /dev/null
|
|
Pierre-Yves Chibon |
c070b4 |
+++ b/456
|
|
Pierre-Yves Chibon |
c070b4 |
@@ -0,0 +1 @@
|
|
Pierre-Yves Chibon |
3d4c92 |
+{"status": true, "branch_from": "feature", "uid": "foobar", "commit_stop": null, "title": "test PR", "comments": [], "project": {"description": "test project for ticket", "parent": null, "settings": {"Minimum_score_to_merge_pull-request": -1, "Web-hooks": null, "project_documentation": true, "pull_requests": true, "Only_assignee_can_merge_pull-request": false, "issue_tracker": true}, "user": {"fullname": "PY C", "default_email": "bar@pingou.com", "name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "id": 1, "name": "test_ticket_repo"}, "assignee": null, "repo_from": {"description": "test project for ticket", "parent": null, "settings": {"Minimum_score_to_merge_pull-request": -1, "Web-hooks": null, "project_documentation": true, "pull_requests": true, "Only_assignee_can_merge_pull-request": false, "issue_tracker": true}, "user": {"fullname": "PY C", "default_email": "bar@pingou.com", "name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "id": 1, "name": "test_ticket_repo"}, "user": {"fullname": "PY C", "default_email": "bar@pingou.com", "name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "branch": "master", "date_created": null, "commit_start": null, "id": 1}
|
|
Pierre-Yves Chibon |
c070b4 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
c070b4 |
"""
|
|
Pierre-Yves Chibon |
c070b4 |
npatch = []
|
|
Pierre-Yves Chibon |
c070b4 |
for row in patch.split('\n'):
|
|
Pierre-Yves Chibon |
c070b4 |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
c070b4 |
continue
|
|
Pierre-Yves Chibon |
c070b4 |
elif row.startswith('From '):
|
|
Pierre-Yves Chibon |
c070b4 |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
c070b4 |
elif row.startswith('diff --git '):
|
|
Pierre-Yves Chibon |
c070b4 |
row = row.split(' ')
|
|
Pierre-Yves Chibon |
c070b4 |
row[2] = 'a/123'
|
|
Pierre-Yves Chibon |
c070b4 |
row[3] = 'b/456'
|
|
Pierre-Yves Chibon |
c070b4 |
row = ' '.join(row)
|
|
Pierre-Yves Chibon |
c070b4 |
elif 'Updated ticket' in row:
|
|
Pierre-Yves Chibon |
c070b4 |
row = row.split()
|
|
Pierre-Yves Chibon |
c070b4 |
row[3] = '<hash>:'</hash>
|
|
Pierre-Yves Chibon |
c070b4 |
row = ' '.join(row)
|
|
Pierre-Yves Chibon |
c070b4 |
elif 'date_created' in row:
|
|
Pierre-Yves Chibon |
c070b4 |
data = json.loads(row[1:])
|
|
Pierre-Yves Chibon |
c070b4 |
data['project']['date_created'] = None
|
|
Pierre-Yves Chibon |
c070b4 |
data['repo_from']['date_created'] = None
|
|
Pierre-Yves Chibon |
c070b4 |
data['date_created'] = None
|
|
Pierre-Yves Chibon |
c070b4 |
row = '+' + json.dumps(data)
|
|
Pierre-Yves Chibon |
c070b4 |
elif row.startswith('index 00'):
|
|
Pierre-Yves Chibon |
c070b4 |
row = 'index 0000000..60f7480'
|
|
Pierre-Yves Chibon |
c070b4 |
elif row.startswith('+++ b/'):
|
|
Pierre-Yves Chibon |
c070b4 |
row = '+++ b/456'
|
|
Pierre-Yves Chibon |
c070b4 |
npatch.append(row)
|
|
Pierre-Yves Chibon |
c070b4 |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
c070b4 |
#print patch
|
|
Pierre-Yves Chibon |
c070b4 |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
c070b4 |
|
|
Pierre-Yves Chibon |
2bf847 |
def test_update_ticket_from_git(self):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the update_ticket_from_git method from pagure.lib.git. """
|
|
Pierre-Yves Chibon |
2bf847 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
# Before
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(len(repo.issues), 0)
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues, [])
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
data = {
|
|
Pierre-Yves Chibon |
2bf847 |
"status": "Open", "title": "foo", "comments": [],
|
|
Pierre-Yves Chibon |
2bf847 |
"content": "bar", "date_created": "1426500263",
|
|
Pierre-Yves Chibon |
2bf847 |
"user": {
|
|
Pierre-Yves Chibon |
2bf847 |
"name": "pingou", "emails": ["pingou@fedoraproject.org"]},
|
|
Pierre-Yves Chibon |
2bf847 |
}
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertRaises(
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_ticket_from_git,
|
|
Pierre-Yves Chibon |
2bf847 |
self.session,
|
|
Pierre-Yves Chibon |
2bf847 |
reponame='foobar',
|
|
Pierre-Yves Chibon |
2bf847 |
username=None,
|
|
Pierre-Yves Chibon |
2bf847 |
issue_uid='foobar',
|
|
Pierre-Yves Chibon |
2bf847 |
json_data=data
|
|
Pierre-Yves Chibon |
2bf847 |
)
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_ticket_from_git(
|
|
Pierre-Yves Chibon |
2bf847 |
self.session, reponame='test', username=None,
|
|
Pierre-Yves Chibon |
2bf847 |
issue_uid='foobar', json_data=data
|
|
Pierre-Yves Chibon |
2bf847 |
)
|
|
Pierre-Yves Chibon |
2bf847 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
# After 1 insertion
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(len(repo.issues), 1)
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].id, 1)
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].uid, 'foobar')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].title, 'foo')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].depends_text, [])
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].blocks_text, [])
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
data["title"] = "fake issue for tests"
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_ticket_from_git(
|
|
Pierre-Yves Chibon |
2bf847 |
self.session, reponame='test', username=None,
|
|
Pierre-Yves Chibon |
2bf847 |
issue_uid='foobar', json_data=data
|
|
Pierre-Yves Chibon |
2bf847 |
)
|
|
Pierre-Yves Chibon |
2bf847 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
# After edit
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(len(repo.issues), 1)
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].id, 1)
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].uid, 'foobar')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].title, 'fake issue for tests')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].depends_text, [])
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].blocks_text, [])
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
data = {
|
|
Pierre-Yves Chibon |
fe5017 |
"status": "Open", "title": "Rename pagure", "private": False,
|
|
Pierre-Yves Chibon |
2bf847 |
"content": "This is too much of a conflict with the book",
|
|
Pierre-Yves Chibon |
2bf847 |
"user": {
|
|
Pierre-Yves Chibon |
ec853d |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
ec853d |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
2bf847 |
"emails": ["pingou@fedoraproject.org"]
|
|
Pierre-Yves Chibon |
2bf847 |
},
|
|
Pierre-Yves Chibon |
2bf847 |
"id": 20,
|
|
Pierre-Yves Chibon |
2bf847 |
"blocks": [1],
|
|
Pierre-Yves Chibon |
2bf847 |
"depends": [3, 4],
|
|
Pierre-Yves Chibon |
2bf847 |
"date_created": "1426595224",
|
|
Pierre-Yves Chibon |
2bf847 |
"comments": [
|
|
Pierre-Yves Chibon |
2bf847 |
{
|
|
Pierre-Yves Chibon |
2bf847 |
"comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"COLLABORATRON5000\r\n- git-sm\u00f6rg\u00e5sbord\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"gitsundheit",
|
|
Pierre-Yves Chibon |
2bf847 |
"date_created": "1426595224", "id": 250, "parent": None,
|
|
Pierre-Yves Chibon |
2bf847 |
"user": {
|
|
Pierre-Yves Chibon |
2bf847 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
2bf847 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
2bf847 |
"emails": ["pingou@fedoraproject.org"]
|
|
Pierre-Yves Chibon |
2bf847 |
}
|
|
Pierre-Yves Chibon |
2bf847 |
},
|
|
Pierre-Yves Chibon |
2bf847 |
{
|
|
Pierre-Yves Chibon |
2bf847 |
"comment": "Nirik:\r\n\r\n- sourceforge++ \r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"gitmaker\r\n- mastergit \r\n- hostomatic\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"gitcorp\r\n- git-keiretsu \r\n- gitbuffet\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"cogitator\r\n- cogitate\r\n\r\nrandomuser:\r\n\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"COLLABORATRON5000\r\n- git-sm\u00f6rg\u00e5sbord\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"thislittlegittywenttomarket\r\n- git-o-rama\r\n- "
|
|
Pierre-Yves Chibon |
2bf847 |
"gitsundheit",
|
|
Pierre-Yves Chibon |
2bf847 |
"date_created": "1426595340", "id": 324, "parent": None,
|
|
Pierre-Yves Chibon |
2bf847 |
"user": {
|
|
Pierre-Yves Chibon |
2bf847 |
"fullname": "Ralph Bean",
|
|
Pierre-Yves Chibon |
2bf847 |
"name": "ralph",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "ralph@fedoraproject.org",
|
|
Pierre-Yves Chibon |
2bf847 |
"emails": ["ralph@fedoraproject.org"]
|
|
Pierre-Yves Chibon |
2bf847 |
}
|
|
Pierre-Yves Chibon |
2bf847 |
}
|
|
Pierre-Yves Chibon |
2bf847 |
]
|
|
Pierre-Yves Chibon |
2bf847 |
}
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_ticket_from_git(
|
|
Pierre-Yves Chibon |
2bf847 |
self.session, reponame='test', username=None,
|
|
Pierre-Yves Chibon |
2bf847 |
issue_uid='foobar2', json_data=data
|
|
Pierre-Yves Chibon |
2bf847 |
)
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
2bf847 |
# After second insertion
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(len(repo.issues), 2)
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].uid, 'foobar')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].title, 'fake issue for tests')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].depends_text, [20])
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[0].blocks_text, [])
|
|
Pierre-Yves Chibon |
2bf847 |
# New one
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[1].uid, 'foobar2')
|
|
Pierre-Yves Chibon |
fe5017 |
self.assertEqual(repo.issues[1].title, 'Rename pagure')
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[1].depends_text, [])
|
|
Pierre-Yves Chibon |
2bf847 |
self.assertEqual(repo.issues[1].blocks_text, [1])
|
|
Pierre-Yves Chibon |
2bf847 |
|
|
Pierre-Yves Chibon |
f692f5 |
def test_update_request_from_git(self):
|
|
Pierre-Yves Chibon |
fe5017 |
""" Test the update_request_from_git method from pagure.lib.git. """
|
|
Pierre-Yves Chibon |
f692f5 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
fd747d |
tests.create_projects_git(os.path.join(tests.HERE, 'repos'))
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
f692f5 |
# Before
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(len(repo.requests), 0)
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests, [])
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
f692f5 |
data = {
|
|
Pierre-Yves Chibon |
f692f5 |
"status": True,
|
|
Pierre-Yves Chibon |
f692f5 |
"uid": "d4182a2ac2d541d884742d3037c26e56",
|
|
Pierre-Yves Chibon |
4dd52c |
"project": {
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
719bdd |
"settings": {
|
|
Pierre-Yves Chibon |
719bdd |
"issue_tracker": True,
|
|
Pierre-Yves Chibon |
719bdd |
"project_documentation": True,
|
|
Pierre-Yves Chibon |
719bdd |
"pull_requests": True,
|
|
Pierre-Yves Chibon |
719bdd |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
700d02 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
700d02 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
700d02 |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
700d02 |
"emails": [
|
|
Pierre-Yves Chibon |
700d02 |
"pingou@fedoraproject.org"
|
|
Pierre-Yves Chibon |
700d02 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 1,
|
|
Pierre-Yves Chibon |
f692f5 |
"description": "test project"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
f692f5 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": ["pingou@fedoraproject.org"]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 7,
|
|
Pierre-Yves Chibon |
f692f5 |
"comments": [
|
|
Pierre-Yves Chibon |
f692f5 |
{
|
|
Pierre-Yves Chibon |
f692f5 |
"comment": "really?",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
f692f5 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": ["pingou@fedoraproject.org"]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426843778",
|
|
Pierre-Yves Chibon |
f692f5 |
"commit": "fa72f315373ec5f98f2b08c8ffae3645c97aaad2",
|
|
Pierre-Yves Chibon |
f692f5 |
"line": 5,
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 1,
|
|
Pierre-Yves Chibon |
f692f5 |
"filename": "test"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
{
|
|
Pierre-Yves Chibon |
f692f5 |
"comment": "Again ?",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
f692f5 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": [
|
|
Pierre-Yves Chibon |
f692f5 |
"pingou@fedoraproject.org"
|
|
Pierre-Yves Chibon |
f692f5 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426866781",
|
|
Pierre-Yves Chibon |
f692f5 |
"commit": "94ebaf900161394059478fd88aec30e59092a1d7",
|
|
Pierre-Yves Chibon |
f692f5 |
"line": 5,
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 2,
|
|
Pierre-Yves Chibon |
f692f5 |
"filename": "test2"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
{
|
|
Pierre-Yves Chibon |
f692f5 |
"comment": "Should be fine in fact",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
f692f5 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": [
|
|
Pierre-Yves Chibon |
f692f5 |
"pingou@fedoraproject.org"
|
|
Pierre-Yves Chibon |
f692f5 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426866950",
|
|
Pierre-Yves Chibon |
f692f5 |
"commit": "94ebaf900161394059478fd88aec30e59092a1d7",
|
|
Pierre-Yves Chibon |
f692f5 |
"line": 5,
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 3,
|
|
Pierre-Yves Chibon |
f692f5 |
"filename": "test2"
|
|
Pierre-Yves Chibon |
f692f5 |
}
|
|
Pierre-Yves Chibon |
f692f5 |
],
|
|
Pierre-Yves Chibon |
f692f5 |
"branch_from": "master",
|
|
Pierre-Yves Chibon |
f692f5 |
"title": "test request",
|
|
Pierre-Yves Chibon |
f692f5 |
"commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
|
|
Pierre-Yves Chibon |
f692f5 |
"repo_from": {
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": {
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
700d02 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
700d02 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
700d02 |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": [
|
|
Pierre-Yves Chibon |
700d02 |
"pingou@fedoraproject.org"
|
|
Pierre-Yves Chibon |
f692f5 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
719bdd |
"settings": {
|
|
Pierre-Yves Chibon |
719bdd |
"issue_tracker": True,
|
|
Pierre-Yves Chibon |
719bdd |
"project_documentation": True,
|
|
Pierre-Yves Chibon |
719bdd |
"pull_requests": True,
|
|
Pierre-Yves Chibon |
719bdd |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 1,
|
|
Pierre-Yves Chibon |
f692f5 |
"description": "test project"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
719bdd |
"settings": {
|
|
Pierre-Yves Chibon |
719bdd |
"issue_tracker": True,
|
|
Pierre-Yves Chibon |
719bdd |
"project_documentation": True,
|
|
Pierre-Yves Chibon |
719bdd |
"pull_requests": True,
|
|
Pierre-Yves Chibon |
719bdd |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426843440",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
700d02 |
"fullname": "fake user",
|
|
Pierre-Yves Chibon |
700d02 |
"name": "fake",
|
|
Pierre-Yves Chibon |
700d02 |
"default_email": "fake@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": [
|
|
Pierre-Yves Chibon |
700d02 |
"fake@fedoraproject.org"
|
|
Pierre-Yves Chibon |
f692f5 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 6,
|
|
Pierre-Yves Chibon |
f692f5 |
"description": "test project"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"branch": "master",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426843732"
|
|
Pierre-Yves Chibon |
f692f5 |
}
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertRaises(
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_request_from_git,
|
|
Pierre-Yves Chibon |
f692f5 |
self.session,
|
|
Pierre-Yves Chibon |
f692f5 |
reponame='foobar',
|
|
Pierre-Yves Chibon |
f692f5 |
username=None,
|
|
Pierre-Yves Chibon |
f692f5 |
request_uid='d4182a2ac2d541d884742d3037c26e56',
|
|
Pierre-Yves Chibon |
f692f5 |
json_data=data,
|
|
Pierre-Yves Chibon |
f692f5 |
gitfolder=tests.HERE,
|
|
Pierre-Yves Chibon |
d0b8c1 |
forkfolder=os.path.join(tests.HERE, 'forks'),
|
|
Pierre-Yves Chibon |
f692f5 |
docfolder=os.path.join(tests.HERE, 'docs'),
|
|
Pierre-Yves Chibon |
f692f5 |
ticketfolder=os.path.join(tests.HERE, 'tickets'),
|
|
Pierre-Yves Chibon |
f692f5 |
requestfolder=os.path.join(tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
f692f5 |
)
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_request_from_git(
|
|
Pierre-Yves Chibon |
f692f5 |
self.session,
|
|
Pierre-Yves Chibon |
f692f5 |
reponame='test',
|
|
Pierre-Yves Chibon |
f692f5 |
username=None,
|
|
Pierre-Yves Chibon |
f692f5 |
request_uid='d4182a2ac2d541d884742d3037c26e56',
|
|
Pierre-Yves Chibon |
f692f5 |
json_data=data,
|
|
Pierre-Yves Chibon |
f692f5 |
gitfolder=tests.HERE,
|
|
Pierre-Yves Chibon |
d0b8c1 |
forkfolder=os.path.join(tests.HERE, 'forks'),
|
|
Pierre-Yves Chibon |
f692f5 |
docfolder=os.path.join(tests.HERE, 'docs'),
|
|
Pierre-Yves Chibon |
f692f5 |
ticketfolder=os.path.join(tests.HERE, 'tickets'),
|
|
Pierre-Yves Chibon |
f692f5 |
requestfolder=os.path.join(tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
f692f5 |
)
|
|
Pierre-Yves Chibon |
f692f5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
f692f5 |
# After 1 st insertion
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(len(repo.requests), 1)
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests[0].id, 7)
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
f692f5 |
repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests[0].title, 'test request')
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(len(repo.requests[0].comments), 3)
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
f692f5 |
data = {
|
|
Pierre-Yves Chibon |
f692f5 |
"status": True,
|
|
Pierre-Yves Chibon |
f692f5 |
"uid": "d4182a2ac2d541d884742d3037c26e57",
|
|
Pierre-Yves Chibon |
4dd52c |
"project": {
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
700d02 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
700d02 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
700d02 |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
700d02 |
"emails": [
|
|
Pierre-Yves Chibon |
700d02 |
"pingou@fedoraproject.org"
|
|
Pierre-Yves Chibon |
700d02 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
719bdd |
"settings": {
|
|
Pierre-Yves Chibon |
719bdd |
"issue_tracker": True,
|
|
Pierre-Yves Chibon |
719bdd |
"project_documentation": True,
|
|
Pierre-Yves Chibon |
719bdd |
"pull_requests": True,
|
|
Pierre-Yves Chibon |
719bdd |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 1,
|
|
Pierre-Yves Chibon |
f692f5 |
"description": "test project"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
f692f5 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
ec853d |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": ["pingou@fedoraproject.org"]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 4,
|
|
Pierre-Yves Chibon |
f692f5 |
"comments": [],
|
|
Pierre-Yves Chibon |
f692f5 |
"branch_from": "master",
|
|
Pierre-Yves Chibon |
f692f5 |
"title": "test request #2",
|
|
Pierre-Yves Chibon |
f692f5 |
"commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
|
|
Pierre-Yves Chibon |
f692f5 |
"repo_from": {
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": {
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
700d02 |
"fullname": "Pierre-YvesChibon",
|
|
Pierre-Yves Chibon |
700d02 |
"name": "pingou",
|
|
Pierre-Yves Chibon |
700d02 |
"default_email": "pingou@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": [
|
|
Pierre-Yves Chibon |
700d02 |
"pingou@fedoraproject.org"
|
|
Pierre-Yves Chibon |
f692f5 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
719bdd |
"settings": {
|
|
Pierre-Yves Chibon |
719bdd |
"issue_tracker": True,
|
|
Pierre-Yves Chibon |
719bdd |
"project_documentation": True,
|
|
Pierre-Yves Chibon |
719bdd |
"pull_requests": True,
|
|
Pierre-Yves Chibon |
719bdd |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 1,
|
|
Pierre-Yves Chibon |
f692f5 |
"description": "test project"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
719bdd |
"settings": {
|
|
Pierre-Yves Chibon |
719bdd |
"issue_tracker": True,
|
|
Pierre-Yves Chibon |
719bdd |
"project_documentation": True,
|
|
Pierre-Yves Chibon |
719bdd |
"pull_requests": True,
|
|
Pierre-Yves Chibon |
719bdd |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426843440",
|
|
Pierre-Yves Chibon |
f692f5 |
"user": {
|
|
Pierre-Yves Chibon |
700d02 |
"fullname": "fake user",
|
|
Pierre-Yves Chibon |
700d02 |
"name": "fake",
|
|
Pierre-Yves Chibon |
700d02 |
"default_email": "fake@fedoraproject.org",
|
|
Pierre-Yves Chibon |
f692f5 |
"emails": [
|
|
Pierre-Yves Chibon |
700d02 |
"fake@fedoraproject.org"
|
|
Pierre-Yves Chibon |
f692f5 |
]
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"project_docs": True,
|
|
Pierre-Yves Chibon |
f692f5 |
"id": 6,
|
|
Pierre-Yves Chibon |
f692f5 |
"description": "test project"
|
|
Pierre-Yves Chibon |
f692f5 |
},
|
|
Pierre-Yves Chibon |
f692f5 |
"branch": "master",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426843745"
|
|
Pierre-Yves Chibon |
f692f5 |
}
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
fe5017 |
pagure.lib.git.update_request_from_git(
|
|
Pierre-Yves Chibon |
f692f5 |
self.session,
|
|
Pierre-Yves Chibon |
f692f5 |
reponame='test',
|
|
Pierre-Yves Chibon |
f692f5 |
username=None,
|
|
Pierre-Yves Chibon |
f692f5 |
request_uid='d4182a2ac2d541d884742d3037c26e57',
|
|
Pierre-Yves Chibon |
f692f5 |
json_data=data,
|
|
Pierre-Yves Chibon |
f692f5 |
gitfolder=tests.HERE,
|
|
Pierre-Yves Chibon |
d0b8c1 |
forkfolder=os.path.join(tests.HERE, 'forks'),
|
|
Pierre-Yves Chibon |
f692f5 |
docfolder=os.path.join(tests.HERE, 'docs'),
|
|
Pierre-Yves Chibon |
f692f5 |
ticketfolder=os.path.join(tests.HERE, 'tickets'),
|
|
Pierre-Yves Chibon |
f692f5 |
requestfolder=os.path.join(tests.HERE, 'requests')
|
|
Pierre-Yves Chibon |
f692f5 |
)
|
|
Pierre-Yves Chibon |
f692f5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
f692f5 |
# After 2 nd insertion
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(len(repo.requests), 2)
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests[0].id, 7)
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
f692f5 |
repo.requests[0].uid, 'd4182a2ac2d541d884742d3037c26e56')
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests[0].title, 'test request')
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(len(repo.requests[0].comments), 3)
|
|
Pierre-Yves Chibon |
f692f5 |
# 2 entry
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests[1].id, 4)
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
f692f5 |
repo.requests[1].uid, 'd4182a2ac2d541d884742d3037c26e57')
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(repo.requests[1].title, 'test request #2')
|
|
Pierre-Yves Chibon |
f692f5 |
self.assertEqual(len(repo.requests[1].comments), 0)
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
858b9d |
def test_read_git_lines(self):
|
|
Pierre-Yves Chibon |
858b9d |
""" Test the read_git_lines method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
858b9d |
self.test_update_git()
|
|
Pierre-Yves Chibon |
858b9d |
|
|
Pierre-Yves Chibon |
858b9d |
gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
858b9d |
output = pagure.lib.git.read_git_lines(
|
|
Pierre-Yves Chibon |
858b9d |
['log', '-1', "--pretty='%s'"], gitrepo)
|
|
Pierre-Yves Chibon |
858b9d |
self.assertEqual(len(output), 1)
|
|
Pierre-Yves Chibon |
858b9d |
self.assertTrue(
|
|
Pierre-Yves Chibon |
858b9d |
output[0].startswith("'Updated ticket ")
|
|
Pierre-Yves Chibon |
858b9d |
)
|
|
Pierre-Yves Chibon |
858b9d |
self.assertTrue(
|
|
Pierre-Yves Chibon |
858b9d |
output[0].endswith(": Test issue'")
|
|
Pierre-Yves Chibon |
858b9d |
)
|
|
Pierre-Yves Chibon |
858b9d |
|
|
Pierre-Yves Chibon |
858b9d |
# Keeping the new line symbol
|
|
Pierre-Yves Chibon |
858b9d |
output = pagure.lib.git.read_git_lines(
|
|
Pierre-Yves Chibon |
858b9d |
['log', '-1', "--pretty='%s'"], gitrepo, keepends=True)
|
|
Pierre-Yves Chibon |
858b9d |
self.assertEqual(len(output), 1)
|
|
Pierre-Yves Chibon |
858b9d |
self.assertTrue(
|
|
Pierre-Yves Chibon |
858b9d |
output[0].endswith(": Test issue'\n")
|
|
Pierre-Yves Chibon |
858b9d |
)
|
|
Pierre-Yves Chibon |
858b9d |
|
|
Pierre-Yves Chibon |
32fce0 |
def test_get_revs_between(self):
|
|
Pierre-Yves Chibon |
32fce0 |
""" Test the get_revs_between method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Pierre-Yves Chibon |
32fce0 |
self.test_update_git()
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Pierre-Yves Chibon |
32fce0 |
gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
32fce0 |
output = pagure.lib.git.read_git_lines(
|
|
Pierre-Yves Chibon |
32fce0 |
['log', '-3', "--pretty='%H'"], gitrepo)
|
|
Pierre-Yves Chibon |
32fce0 |
self.assertEqual(len(output), 2)
|
|
Pierre-Yves Chibon |
32fce0 |
to_hash = output[0].replace("'", '')
|
|
Pierre-Yves Chibon |
32fce0 |
from_hash = output[1].replace("'", '')
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Pierre-Yves Chibon |
32fce0 |
output1 = pagure.lib.git.get_revs_between(
|
|
Pierre-Yves Chibon |
32fce0 |
to_hash, from_hash, gitrepo)
|
|
Pierre-Yves Chibon |
32fce0 |
self.assertEqual(output1, [to_hash])
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Pierre-Yves Chibon |
32fce0 |
output2 = pagure.lib.git.get_revs_between(
|
|
Pierre-Yves Chibon |
32fce0 |
from_hash, to_hash, gitrepo)
|
|
Pierre-Yves Chibon |
32fce0 |
self.assertEqual(output2, [to_hash])
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Pierre-Yves Chibon |
84cd98 |
def test_get_pusher(self):
|
|
Pierre-Yves Chibon |
84cd98 |
""" Test the get_pusher method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
84cd98 |
|
|
Pierre-Yves Chibon |
84cd98 |
self.test_update_git()
|
|
Pierre-Yves Chibon |
84cd98 |
|
|
Pierre-Yves Chibon |
84cd98 |
gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
84cd98 |
output = pagure.lib.git.read_git_lines(
|
|
Pierre-Yves Chibon |
84cd98 |
['log', '-3', "--pretty='%H'"], gitrepo)
|
|
Pierre-Yves Chibon |
84cd98 |
self.assertEqual(len(output), 2)
|
|
Pierre-Yves Chibon |
84cd98 |
for githash in output:
|
|
Pierre-Yves Chibon |
84cd98 |
githash = githash.replace("'", '')
|
|
Pierre-Yves Chibon |
84cd98 |
output = pagure.lib.git.get_pusher(githash, gitrepo)
|
|
Pierre-Yves Chibon |
84cd98 |
self.assertEqual(output, 'pagure')
|
|
Pierre-Yves Chibon |
84cd98 |
|
|
Pierre-Yves Chibon |
f69b11 |
def test_get_pusher_email(self):
|
|
Pierre-Yves Chibon |
f69b11 |
""" Test the get_pusher_email method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
f69b11 |
|
|
Pierre-Yves Chibon |
f69b11 |
self.test_update_git()
|
|
Pierre-Yves Chibon |
f69b11 |
|
|
Pierre-Yves Chibon |
f69b11 |
gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
f69b11 |
output = pagure.lib.git.read_git_lines(
|
|
Pierre-Yves Chibon |
f69b11 |
['log', '-3', "--pretty='%H'"], gitrepo)
|
|
Pierre-Yves Chibon |
f69b11 |
self.assertEqual(len(output), 2)
|
|
Pierre-Yves Chibon |
f69b11 |
for githash in output:
|
|
Pierre-Yves Chibon |
f69b11 |
githash = githash.replace("'", '')
|
|
Pierre-Yves Chibon |
f69b11 |
output = pagure.lib.git.get_pusher_email(githash, gitrepo)
|
|
Pierre-Yves Chibon |
f69b11 |
self.assertEqual(output, 'pagure')
|
|
Pierre-Yves Chibon |
f69b11 |
|
|
Pierre-Yves Chibon |
cf28b3 |
def test_get_repo_name(self):
|
|
Pierre-Yves Chibon |
cf28b3 |
""" Test the get_repo_name method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
cf28b3 |
gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
cf28b3 |
repo_name = pagure.lib.git.get_repo_name(gitrepo)
|
|
Pierre-Yves Chibon |
cf28b3 |
self.assertEqual(repo_name, 'test_ticket_repo')
|
|
Pierre-Yves Chibon |
cf28b3 |
|
|
Pierre-Yves Chibon |
cf28b3 |
repo_name = pagure.lib.git.get_repo_name('foo/bar/baz/test.git')
|
|
Pierre-Yves Chibon |
cf28b3 |
self.assertEqual(repo_name, 'test')
|
|
Pierre-Yves Chibon |
cf28b3 |
|
|
Pierre-Yves Chibon |
cf28b3 |
repo_name = pagure.lib.git.get_repo_name('foo.test.git')
|
|
Pierre-Yves Chibon |
cf28b3 |
self.assertEqual(repo_name, 'foo.test')
|
|
Pierre-Yves Chibon |
cf28b3 |
|
|
Pierre-Yves Chibon |
a7c15a |
def test_get_username(self):
|
|
Pierre-Yves Chibon |
a7c15a |
""" Test the get_username method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
a7c15a |
gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
|
|
Pierre-Yves Chibon |
a7c15a |
repo_name = pagure.lib.git.get_username(gitrepo)
|
|
Pierre-Yves Chibon |
a7c15a |
self.assertEqual(repo_name, None)
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
a7c15a |
repo_name = pagure.lib.git.get_username('foo/bar/baz/test.git')
|
|
Pierre-Yves Chibon |
a7c15a |
self.assertEqual(repo_name, None)
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
a7c15a |
repo_name = pagure.lib.git.get_username('foo.test.git')
|
|
Pierre-Yves Chibon |
a7c15a |
self.assertEqual(repo_name, None)
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
a7c15a |
repo_name = pagure.lib.git.get_username(
|
|
Pierre-Yves Chibon |
a7c15a |
os.path.join(tests.HERE, 'forks', 'pingou', 'foo.test.git'))
|
|
Pierre-Yves Chibon |
a7c15a |
self.assertEqual(repo_name, 'pingou')
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
a945ba |
|
|
Pierre-Yves Chibon |
a945ba |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
fe5017 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureLibGittests)
|
|
Pierre-Yves Chibon |
a945ba |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|