|
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
|
|
Clement Verna |
469e2c |
import tempfile
|
|
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 |
bda7f1 |
from pagure.lib.repo import PagureRepo
|
|
Pierre-Yves Chibon |
bda7f1 |
|
|
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(
|
|
Jeremy Cline |
20109f |
self.path, 'repos')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'tickets')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'docs')
|
|
Pierre-Yves Chibon |
fd747d |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, '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',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
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 |
|
|
Jeremy Cline |
20109f |
outputconf = os.path.join(self.path, '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 |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = foo
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
a6701e |
repo requests/test
|
|
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 |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
a6701e |
repo requests/test2
|
|
Pierre-Yves Chibon |
a6701e |
RW+ = pingou
|
|
Pierre-Yves Chibon |
a6701e |
|
|
clime |
afed57 |
repo somenamespace/test3
|
|
clime |
afed57 |
R = @all
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
clime |
afed57 |
repo docs/somenamespace/test3
|
|
clime |
afed57 |
R = @all
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
clime |
afed57 |
repo tickets/somenamespace/test3
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
clime |
afed57 |
repo requests/somenamespace/test3
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
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 |
59a1eb |
repo docs/forks/pingou/test3
|
|
Pierre-Yves Chibon |
ead0df |
R = @all
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
59a1eb |
repo tickets/forks/pingou/test3
|
|
Pierre-Yves Chibon |
a6701e |
RW+ = pingou
|
|
Pierre-Yves Chibon |
a6701e |
|
|
Pierre-Yves Chibon |
59a1eb |
repo requests/forks/pingou/test3
|
|
Pierre-Yves Chibon |
ead0df |
RW+ = pingou
|
|
Pierre-Yves Chibon |
ead0df |
|
|
Pierre-Yves Chibon |
ead0df |
"""
|
|
Pierre-Yves Chibon |
59a1eb |
#print data
|
|
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 |
ce6666 |
display_name='sysadmin group',
|
|
Pierre-Yves Chibon |
ce6666 |
description=None,
|
|
Pierre-Yves Chibon |
4fc47a |
group_type='user',
|
|
Pierre-Yves Chibon |
4fc47a |
user='pingou',
|
|
Pierre-Yves Chibon |
4fc47a |
is_admin=False,
|
|
Pierre-Yves Chibon |
d4d101 |
blacklist=[],
|
|
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 |
ce6666 |
display_name='devs group',
|
|
Pierre-Yves Chibon |
ce6666 |
description=None,
|
|
Pierre-Yves Chibon |
6f5851 |
group_type='user',
|
|
Pierre-Yves Chibon |
6f5851 |
user='pingou',
|
|
Pierre-Yves Chibon |
6f5851 |
is_admin=False,
|
|
Pierre-Yves Chibon |
d4d101 |
blacklist=[],
|
|
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',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
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 |
|
|
Jeremy Cline |
20109f |
outputconf = os.path.join(self.path, '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 |
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 |
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 |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
repo requests/test2
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
clime |
afed57 |
repo somenamespace/test3
|
|
clime |
afed57 |
R = @all
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
clime |
afed57 |
repo docs/somenamespace/test3
|
|
clime |
afed57 |
R = @all
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
clime |
afed57 |
repo tickets/somenamespace/test3
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
clime |
afed57 |
repo requests/somenamespace/test3
|
|
clime |
afed57 |
RW+ = pingou
|
|
clime |
afed57 |
|
|
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 |
59a1eb |
repo docs/forks/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
R = @all
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
59a1eb |
repo tickets/forks/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
59a1eb |
repo requests/forks/pingou/test2
|
|
Pierre-Yves Chibon |
4fc47a |
RW+ = pingou
|
|
Pierre-Yves Chibon |
4fc47a |
|
|
Pierre-Yves Chibon |
4fc47a |
"""
|
|
Pierre-Yves Chibon |
59a1eb |
#print data
|
|
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
|
|
Jeremy Cline |
20109f |
self.gitrepo = os.path.join(self.path, '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
|
|
Jeremy Cline |
20109f |
self.gitrepo = os.path.join(self.path, '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',
|
|
Jeremy Cline |
20109f |
ticketfolder=self.path
|
|
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)
|
|
Jeremy Cline |
20109f |
pagure.lib.git.update_git(issue, repo, self.path)
|
|
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 |
e64141 |
Subject: Updated issue <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
|
|
Mark Reynolds |
23b4d2 |
@@ -0,0 +1,28 @@
|
|
Pierre-Yves Chibon |
2e900f |
+{
|
|
Pierre-Yves Chibon |
2e900f |
+ "assignee": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "blocks": [],
|
|
Pierre-Yves Chibon |
a71f76 |
+ "close_status": null,
|
|
Vivek Anand |
d7285b |
+ "closed_at": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "comments": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "content": "We should work on this",
|
|
Pierre-Yves Chibon |
022564 |
+ "custom_fields": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "date_created": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "depends": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "id": 1,
|
|
Mark Reynolds |
23b4d2 |
+ "last_updated": null,
|
|
Pierre-Yves Chibon |
725fca |
+ "milestone": null,
|
|
Pierre-Yves Chibon |
b5c8b4 |
+ "priority": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "private": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "status": "Open",
|
|
Pierre-Yves Chibon |
2e900f |
+ "tags": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "title": "Test issue",
|
|
Pierre-Yves Chibon |
2e900f |
+ "user": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "default_email": "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "emails": [
|
|
Pierre-Yves Chibon |
2e900f |
+ "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "foo@pingou.com"
|
|
Pierre-Yves Chibon |
2e900f |
+ ],
|
|
Pierre-Yves Chibon |
2e900f |
+ "fullname": "PY C",
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "pingou"
|
|
Pierre-Yves Chibon |
2e900f |
+ }
|
|
Pierre-Yves Chibon |
2e900f |
+}
|
|
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 |
e64141 |
elif 'Updated issue' 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 |
2e900f |
t = row.split(': ')[0]
|
|
Pierre-Yves Chibon |
2e900f |
row = '%s: null,' % t
|
|
Mark Reynolds |
23b4d2 |
elif 'last_updated' in row:
|
|
Mark Reynolds |
23b4d2 |
t = row.split(': ')[0]
|
|
Mark Reynolds |
23b4d2 |
row = '%s: null,' % t
|
|
Vivek Anand |
d7285b |
elif 'closed_at' in row:
|
|
Vivek Anand |
d7285b |
t = row.split(': ')[0]
|
|
Vivek Anand |
d7285b |
row = '%s: null,' % t
|
|
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',
|
|
Jeremy Cline |
20109f |
ticketfolder=self.path
|
|
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 |
e64141 |
Subject: Updated issue <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 |
a71f76 |
@@ -3,7 +3,25 @@
|
|
Pierre-Yves Chibon |
2e900f |
"blocks": [],
|
|
Pierre-Yves Chibon |
a71f76 |
"close_status": null,
|
|
Vivek Anand |
d7285b |
"closed_at": null,
|
|
Pierre-Yves Chibon |
2e900f |
- "comments": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "comments": [
|
|
Pierre-Yves Chibon |
2e900f |
+ {
|
|
Pierre-Yves Chibon |
2e900f |
+ "comment": "Hey look a comment!",
|
|
Pierre-Yves Chibon |
2e900f |
+ "date_created": null,
|
|
Pierre-Yves Chibon |
e64141 |
+ "edited_on": null,
|
|
Pierre-Yves Chibon |
e64141 |
+ "editor": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "id": 1,
|
|
Pierre-Yves Chibon |
bda7f1 |
+ "notification": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "parent": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "user": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "default_email": "foo@bar.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "emails": [
|
|
Pierre-Yves Chibon |
2e900f |
+ "foo@bar.com"
|
|
Pierre-Yves Chibon |
2e900f |
+ ],
|
|
Pierre-Yves Chibon |
2e900f |
+ "fullname": "foo bar",
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "foo"
|
|
Pierre-Yves Chibon |
2e900f |
+ }
|
|
Pierre-Yves Chibon |
2e900f |
+ }
|
|
Pierre-Yves Chibon |
2e900f |
+ ],
|
|
Pierre-Yves Chibon |
2e900f |
"content": "We should work on this",
|
|
Pierre-Yves Chibon |
e5e9eb |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
2e900f |
"date_created": null,
|
|
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 |
e64141 |
elif 'Updated issue' 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:
|
|
Vivek Anand |
d7285b |
t = row.split(': ')[0]
|
|
Vivek Anand |
d7285b |
row = '%s: null,' % t
|
|
Vivek Anand |
d7285b |
elif 'closed_at' in row:
|
|
Pierre-Yves Chibon |
2e900f |
t = row.split(': ')[0]
|
|
Pierre-Yves Chibon |
2e900f |
row = '%s: null,' % t
|
|
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 |
3fe986 |
#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 |
|
|
Jeremy Cline |
20109f |
gitpath = os.path.join(self.path, '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)
|
|
Jeremy Cline |
20109f |
pagure.lib.git.clean_git(issue, repo, self.path)
|
|
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
|
|
Jeremy Cline |
20109f |
self.gitrepo = os.path.join(self.path, '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',
|
|
Jeremy Cline |
20109f |
requestfolder=self.path,
|
|
Pierre-Yves Chibon |
c070b4 |
requestuid='foobar',
|
|
Pierre-Yves Chibon |
c070b4 |
requestid=None,
|
|
Pierre-Yves Chibon |
ff2972 |
status='Open',
|
|
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')
|
|
Jeremy Cline |
20109f |
pagure.lib.git.update_git(request, request.project, self.path)
|
|
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 |
e64141 |
Subject: Updated pull-request <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
|
|
Mark Reynolds |
23b4d2 |
@@ -0,0 +1,96 @@
|
|
Pierre-Yves Chibon |
2e900f |
+{
|
|
Pierre-Yves Chibon |
2e900f |
+ "assignee": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "branch": "master",
|
|
Pierre-Yves Chibon |
2e900f |
+ "branch_from": "feature",
|
|
Pierre-Yves Chibon |
bf72a2 |
+ "closed_at": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "closed_by": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "comments": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "commit_start": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "commit_stop": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "date_created": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "id": 1,
|
|
Pierre-Yves Chibon |
10ca8a |
+ "initial_comment": null,
|
|
Mark Reynolds |
23b4d2 |
+ "last_updated": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "project": {
|
|
Pierre-Yves Chibon |
f254bf |
+ "close_status": [],
|
|
Pierre-Yves Chibon |
022564 |
+ "custom_keys": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "date_created": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "description": "test project for ticket",
|
|
Pierre-Yves Chibon |
2e900f |
+ "id": 1,
|
|
Pierre-Yves Chibon |
f254bf |
+ "milestones": {},
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "test_ticket_repo",
|
|
Pierre-Yves Chibon |
733a9d |
+ "namespace": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "parent": null,
|
|
Pierre-Yves Chibon |
14bde2 |
+ "priorities": {},
|
|
Pierre-Yves Chibon |
2e900f |
+ "settings": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "Enforce_signed-off_commits_in_pull-request": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "Minimum_score_to_merge_pull-request": -1,
|
|
Pierre-Yves Chibon |
2e900f |
+ "Only_assignee_can_merge_pull-request": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "Web-hooks": null,
|
|
Pierre-Yves Chibon |
1709b9 |
+ "always_merge": false,
|
|
Pierre-Yves Chibon |
9d1556 |
+ "fedmsg_notifications": true,
|
|
Pierre-Yves Chibon |
2e900f |
+ "issue_tracker": true,
|
|
Pierre-Yves Chibon |
d0e87d |
+ "issues_default_to_private": false,
|
|
Pierre-Yves Chibon |
e994c4 |
+ "project_documentation": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "pull_requests": true
|
|
Pierre-Yves Chibon |
2e900f |
+ },
|
|
Pierre-Yves Chibon |
a30916 |
+ "tags": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "user": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "default_email": "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "emails": [
|
|
Pierre-Yves Chibon |
2e900f |
+ "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "foo@pingou.com"
|
|
Pierre-Yves Chibon |
2e900f |
+ ],
|
|
Pierre-Yves Chibon |
2e900f |
+ "fullname": "PY C",
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "pingou"
|
|
Pierre-Yves Chibon |
2e900f |
+ }
|
|
Pierre-Yves Chibon |
2e900f |
+ },
|
|
Pierre-Yves Chibon |
ee5445 |
+ "remote_git": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "repo_from": {
|
|
Pierre-Yves Chibon |
f254bf |
+ "close_status": [],
|
|
Pierre-Yves Chibon |
022564 |
+ "custom_keys": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "date_created": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "description": "test project for ticket",
|
|
Pierre-Yves Chibon |
2e900f |
+ "id": 1,
|
|
Pierre-Yves Chibon |
f254bf |
+ "milestones": {},
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "test_ticket_repo",
|
|
Pierre-Yves Chibon |
733a9d |
+ "namespace": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "parent": null,
|
|
Pierre-Yves Chibon |
14bde2 |
+ "priorities": {},
|
|
Pierre-Yves Chibon |
2e900f |
+ "settings": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "Enforce_signed-off_commits_in_pull-request": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "Minimum_score_to_merge_pull-request": -1,
|
|
Pierre-Yves Chibon |
2e900f |
+ "Only_assignee_can_merge_pull-request": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "Web-hooks": null,
|
|
Pierre-Yves Chibon |
1709b9 |
+ "always_merge": false,
|
|
Pierre-Yves Chibon |
9d1556 |
+ "fedmsg_notifications": true,
|
|
Pierre-Yves Chibon |
2e900f |
+ "issue_tracker": true,
|
|
Pierre-Yves Chibon |
d0e87d |
+ "issues_default_to_private": false,
|
|
Pierre-Yves Chibon |
e994c4 |
+ "project_documentation": false,
|
|
Pierre-Yves Chibon |
2e900f |
+ "pull_requests": true
|
|
Pierre-Yves Chibon |
2e900f |
+ },
|
|
Pierre-Yves Chibon |
a30916 |
+ "tags": [],
|
|
Pierre-Yves Chibon |
2e900f |
+ "user": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "default_email": "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "emails": [
|
|
Pierre-Yves Chibon |
2e900f |
+ "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "foo@pingou.com"
|
|
Pierre-Yves Chibon |
2e900f |
+ ],
|
|
Pierre-Yves Chibon |
2e900f |
+ "fullname": "PY C",
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "pingou"
|
|
Pierre-Yves Chibon |
2e900f |
+ }
|
|
Pierre-Yves Chibon |
2e900f |
+ },
|
|
Pierre-Yves Chibon |
2e900f |
+ "status": "Open",
|
|
Pierre-Yves Chibon |
2e900f |
+ "title": "test PR",
|
|
Pierre-Yves Chibon |
2e900f |
+ "uid": "foobar",
|
|
Pierre-Yves Chibon |
44258a |
+ "updated_on": null,
|
|
Pierre-Yves Chibon |
2e900f |
+ "user": {
|
|
Pierre-Yves Chibon |
2e900f |
+ "default_email": "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "emails": [
|
|
Pierre-Yves Chibon |
2e900f |
+ "bar@pingou.com",
|
|
Pierre-Yves Chibon |
2e900f |
+ "foo@pingou.com"
|
|
Pierre-Yves Chibon |
2e900f |
+ ],
|
|
Pierre-Yves Chibon |
2e900f |
+ "fullname": "PY C",
|
|
Pierre-Yves Chibon |
2e900f |
+ "name": "pingou"
|
|
Pierre-Yves Chibon |
2e900f |
+ }
|
|
Pierre-Yves Chibon |
2e900f |
+}
|
|
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 |
e64141 |
elif 'Updated pull-request' 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 |
2e900f |
t = row.split(': ')[0]
|
|
Pierre-Yves Chibon |
2e900f |
row = '%s: null,' % t
|
|
Mark Reynolds |
23b4d2 |
elif 'last_updated' in row:
|
|
Mark Reynolds |
23b4d2 |
t = row.split(': ')[0]
|
|
Mark Reynolds |
23b4d2 |
row = '%s: null,' % t
|
|
Pierre-Yves Chibon |
44258a |
elif 'updated_on' in row:
|
|
Pierre-Yves Chibon |
44258a |
t = row.split(': ')[0]
|
|
Pierre-Yves Chibon |
44258a |
row = '%s: null,' % t
|
|
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"]},
|
|
Clement Verna |
b30f33 |
"milestone": "Next Release",
|
|
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 |
5abfd2 |
namespace=None,
|
|
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 |
5abfd2 |
self.session, reponame='test', namespace=None, 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, [])
|
|
Clement Verna |
b30f33 |
self.assertEqual(repo.issues[0].milestone, 'Next Release')
|
|
Clement Verna |
b30f33 |
self.assertEqual(repo.milestones, {'Next Release': None})
|
|
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 |
5abfd2 |
self.session, reponame='test', namespace=None, 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",
|
|
Clement Verna |
b30f33 |
"milestone": "Future",
|
|
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 |
5abfd2 |
self.session, reponame='test', namespace=None, 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])
|
|
Clement Verna |
b30f33 |
self.assertEqual(repo.issues[1].milestone, 'Future')
|
|
Clement Verna |
b30f33 |
self.assertEqual(repo.milestones, {'Future': None, 'Next Release': None})
|
|
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)
|
|
Jeremy Cline |
20109f |
tests.create_projects_git(os.path.join(self.path, 'repos'))
|
|
Pierre-Yves Chibon |
f692f5 |
|
|
Pierre-Yves Chibon |
fe5017 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
clime |
afed57 |
namespaced_repo = pagure.lib.get_project(
|
|
clime |
afed57 |
self.session, 'test3', namespace='somenamespace')
|
|
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, [])
|
|
clime |
afed57 |
self.assertEqual(len(namespaced_repo.requests), 0)
|
|
clime |
afed57 |
self.assertEqual(namespaced_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 |
022564 |
"custom_keys": [],
|
|
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 |
a30916 |
"tags": [],
|
|
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 |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
f692f5 |
"parent": None,
|
|
Pierre-Yves Chibon |
f692f5 |
"name": "test",
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
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 |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
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 |
5abfd2 |
namespace=None,
|
|
Pierre-Yves Chibon |
f692f5 |
username=None,
|
|
Pierre-Yves Chibon |
f692f5 |
request_uid='d4182a2ac2d541d884742d3037c26e56',
|
|
Pierre-Yves Chibon |
f692f5 |
json_data=data,
|
|
Jeremy Cline |
20109f |
gitfolder=self.path,
|
|
Jeremy Cline |
20109f |
docfolder=os.path.join(self.path, 'docs'),
|
|
Jeremy Cline |
20109f |
ticketfolder=os.path.join(self.path, 'tickets'),
|
|
Jeremy Cline |
20109f |
requestfolder=os.path.join(self.path, '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 |
5abfd2 |
namespace=None,
|
|
Pierre-Yves Chibon |
f692f5 |
username=None,
|
|
Pierre-Yves Chibon |
f692f5 |
request_uid='d4182a2ac2d541d884742d3037c26e56',
|
|
Pierre-Yves Chibon |
f692f5 |
json_data=data,
|
|
Jeremy Cline |
20109f |
gitfolder=self.path,
|
|
Jeremy Cline |
20109f |
docfolder=os.path.join(self.path, 'docs'),
|
|
Jeremy Cline |
20109f |
ticketfolder=os.path.join(self.path, 'tickets'),
|
|
Jeremy Cline |
20109f |
requestfolder=os.path.join(self.path, '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 |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
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 |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
f692f5 |
"date_created": "1426500194",
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
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 |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
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 |
5abfd2 |
namespace=None,
|
|
Pierre-Yves Chibon |
f692f5 |
username=None,
|
|
Pierre-Yves Chibon |
f692f5 |
request_uid='d4182a2ac2d541d884742d3037c26e57',
|
|
Pierre-Yves Chibon |
f692f5 |
json_data=data,
|
|
Jeremy Cline |
20109f |
gitfolder=self.path,
|
|
Jeremy Cline |
20109f |
docfolder=os.path.join(self.path, 'docs'),
|
|
Jeremy Cline |
20109f |
ticketfolder=os.path.join(self.path, 'tickets'),
|
|
Jeremy Cline |
20109f |
requestfolder=os.path.join(self.path, '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 |
|
|
clime |
afed57 |
data = {
|
|
clime |
afed57 |
"status": True,
|
|
clime |
afed57 |
"uid": "d4182a2ac2d541d884742d3037c26e58",
|
|
clime |
afed57 |
"project": {
|
|
clime |
afed57 |
"parent": None,
|
|
clime |
afed57 |
"name": "test3",
|
|
clime |
afed57 |
"custom_keys": [],
|
|
clime |
afed57 |
"namespace": "somenamespace",
|
|
clime |
afed57 |
"date_created": "1426500194",
|
|
clime |
afed57 |
"tags": [],
|
|
clime |
afed57 |
"user": {
|
|
clime |
afed57 |
"fullname": "Pierre-YvesChibon",
|
|
clime |
afed57 |
"name": "pingou",
|
|
clime |
afed57 |
"default_email": "pingou@fedoraproject.org",
|
|
clime |
afed57 |
"emails": [
|
|
clime |
afed57 |
"pingou@fedoraproject.org"
|
|
clime |
afed57 |
]
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"settings": {
|
|
clime |
afed57 |
"issue_tracker": True,
|
|
clime |
afed57 |
"project_documentation": True,
|
|
clime |
afed57 |
"pull_requests": True,
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"id": 3,
|
|
clime |
afed57 |
"description": "namespaced test project"
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"commit_stop": "eface8e13bc2a08a3fb22af9a72a8c90e36b8b89",
|
|
clime |
afed57 |
"user": {
|
|
clime |
afed57 |
"fullname": "Pierre-YvesChibon",
|
|
clime |
afed57 |
"name": "pingou",
|
|
clime |
afed57 |
"default_email": "pingou@fedoraproject.org",
|
|
clime |
afed57 |
"emails": ["pingou@fedoraproject.org"]
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"id": 5,
|
|
clime |
afed57 |
"comments": [],
|
|
clime |
afed57 |
"branch_from": "master",
|
|
clime |
afed57 |
"title": "test request to namespaced repo",
|
|
clime |
afed57 |
"commit_start": "788efeaaf86bde8618f594a8181abb402e1dd904",
|
|
clime |
afed57 |
"repo_from": {
|
|
clime |
afed57 |
"parent": {
|
|
clime |
afed57 |
"parent": None,
|
|
clime |
afed57 |
"name": "test",
|
|
clime |
afed57 |
"custom_keys": [],
|
|
clime |
afed57 |
"date_created": "1426500194",
|
|
clime |
afed57 |
"tags": [],
|
|
clime |
afed57 |
"user": {
|
|
clime |
afed57 |
"fullname": "Pierre-YvesChibon",
|
|
clime |
afed57 |
"name": "pingou",
|
|
clime |
afed57 |
"default_email": "pingou@fedoraproject.org",
|
|
clime |
afed57 |
"emails": [
|
|
clime |
afed57 |
"pingou@fedoraproject.org"
|
|
clime |
afed57 |
]
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"settings": {
|
|
clime |
afed57 |
"issue_tracker": True,
|
|
clime |
afed57 |
"project_documentation": True,
|
|
clime |
afed57 |
"pull_requests": True,
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"id": 1,
|
|
clime |
afed57 |
"description": "test project"
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"settings": {
|
|
clime |
afed57 |
"issue_tracker": True,
|
|
clime |
afed57 |
"project_documentation": True,
|
|
clime |
afed57 |
"pull_requests": True,
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"name": "test",
|
|
clime |
afed57 |
"date_created": "1426843440",
|
|
clime |
afed57 |
"custom_keys": [],
|
|
clime |
afed57 |
"tags": [],
|
|
clime |
afed57 |
"user": {
|
|
clime |
afed57 |
"fullname": "fake user",
|
|
clime |
afed57 |
"name": "fake",
|
|
clime |
afed57 |
"default_email": "fake@fedoraproject.org",
|
|
clime |
afed57 |
"emails": [
|
|
clime |
afed57 |
"fake@fedoraproject.org"
|
|
clime |
afed57 |
]
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"project_docs": True,
|
|
clime |
afed57 |
"id": 6,
|
|
clime |
afed57 |
"description": "test project"
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
"branch": "master",
|
|
clime |
afed57 |
"date_created": "1426843745"
|
|
clime |
afed57 |
}
|
|
clime |
afed57 |
pagure.lib.git.update_request_from_git(
|
|
clime |
afed57 |
self.session,
|
|
clime |
afed57 |
reponame='test3',
|
|
clime |
afed57 |
namespace='somenamespace',
|
|
clime |
afed57 |
username=None,
|
|
clime |
afed57 |
request_uid='d4182a2ac2d541d884742d3037c26e58',
|
|
clime |
afed57 |
json_data=data,
|
|
clime |
afed57 |
gitfolder=self.path,
|
|
clime |
afed57 |
docfolder=os.path.join(self.path, 'docs'),
|
|
clime |
afed57 |
ticketfolder=os.path.join(self.path, 'tickets'),
|
|
clime |
afed57 |
requestfolder=os.path.join(self.path, 'requests')
|
|
clime |
afed57 |
)
|
|
clime |
afed57 |
self.session.commit()
|
|
clime |
afed57 |
|
|
clime |
afed57 |
self.assertEqual(len(namespaced_repo.requests), 1)
|
|
clime |
afed57 |
self.assertEqual(namespaced_repo.requests[0].id, 5)
|
|
clime |
afed57 |
self.assertEqual(
|
|
clime |
afed57 |
namespaced_repo.requests[0].uid,
|
|
clime |
afed57 |
'd4182a2ac2d541d884742d3037c26e58'
|
|
clime |
afed57 |
)
|
|
clime |
afed57 |
self.assertEqual(
|
|
clime |
afed57 |
namespaced_repo.requests[0].title,
|
|
clime |
afed57 |
'test request to namespaced repo'
|
|
clime |
afed57 |
)
|
|
clime |
afed57 |
|
|
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 |
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, '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 |
e64141 |
output[0].startswith("'Updated issue ")
|
|
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 |
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, '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 |
from_hash = output[1].replace("'", '')
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Clement Verna |
1901d5 |
# Case 1, repo BASE is null and HEAD is equal to from_hash
|
|
Clement Verna |
1901d5 |
to_hash = '0'
|
|
Pierre-Yves Chibon |
32fce0 |
output1 = pagure.lib.git.get_revs_between(
|
|
Clement Verna |
f202e4 |
to_hash, from_hash, gitrepo, 'refs/heads/master')
|
|
Clement Verna |
990b72 |
self.assertEqual(output1, [from_hash])
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Clement Verna |
1901d5 |
# Case 2, get revs between two commits (to_hash, from_hash)
|
|
Clement Verna |
1901d5 |
to_hash = output[0].replace("'", '')
|
|
Pierre-Yves Chibon |
32fce0 |
output2 = pagure.lib.git.get_revs_between(
|
|
Clement Verna |
f202e4 |
to_hash, from_hash, gitrepo, 'refs/heads/master')
|
|
Pierre-Yves Chibon |
32fce0 |
self.assertEqual(output2, [to_hash])
|
|
Pierre-Yves Chibon |
32fce0 |
|
|
Clement Verna |
1901d5 |
# Case 3, get revs between two commits (from_hash, to_hash)
|
|
Clement Verna |
1901d5 |
output3 = pagure.lib.git.get_revs_between(
|
|
Clement Verna |
f202e4 |
from_hash, to_hash, gitrepo, 'refs/heads/master')
|
|
Clement Verna |
1901d5 |
self.assertEqual(output3, [to_hash])
|
|
Clement Verna |
1901d5 |
|
|
Clement Verna |
469e2c |
# Case 4, get revs between two commits on two different branches
|
|
Clement Verna |
469e2c |
newgitrepo = tempfile.mkdtemp(prefix='pagure-')
|
|
Clement Verna |
469e2c |
newrepo = pygit2.clone_repository(gitrepo, newgitrepo)
|
|
Clement Verna |
469e2c |
newrepo.create_branch('feature', newrepo.head.get_object())
|
|
Clement Verna |
469e2c |
|
|
Clement Verna |
469e2c |
with open(os.path.join(newgitrepo, 'sources'), 'w') as stream:
|
|
Clement Verna |
469e2c |
stream.write('foo\n bar')
|
|
Clement Verna |
469e2c |
newrepo.index.add('sources')
|
|
Clement Verna |
469e2c |
newrepo.index.write()
|
|
Clement Verna |
469e2c |
|
|
Clement Verna |
469e2c |
# Commits the files added
|
|
Clement Verna |
469e2c |
tree = newrepo.index.write_tree()
|
|
Clement Verna |
469e2c |
author = pygit2.Signature(
|
|
Clement Verna |
469e2c |
'Alice Author', 'alice@authors.tld')
|
|
Clement Verna |
469e2c |
committer = pygit2.Signature(
|
|
Clement Verna |
469e2c |
'Cecil Committer', 'cecil@committers.tld')
|
|
Clement Verna |
469e2c |
newrepo.create_commit(
|
|
Clement Verna |
469e2c |
'refs/heads/feature', # the name of the reference to update
|
|
Clement Verna |
469e2c |
author,
|
|
Clement Verna |
469e2c |
committer,
|
|
Clement Verna |
469e2c |
'Add sources file for testing',
|
|
Clement Verna |
469e2c |
# binary string representing the tree object ID
|
|
Clement Verna |
469e2c |
tree,
|
|
Clement Verna |
469e2c |
# list of binary strings representing parents of the new commit
|
|
Clement Verna |
469e2c |
[to_hash]
|
|
Clement Verna |
469e2c |
)
|
|
Clement Verna |
469e2c |
branch_commit = newrepo.revparse_single('refs/heads/feature')
|
|
Clement Verna |
469e2c |
|
|
Clement Verna |
469e2c |
# Push to origin
|
|
Clement Verna |
469e2c |
ori_remote = newrepo.remotes[0]
|
|
Clement Verna |
469e2c |
PagureRepo.push(ori_remote, 'refs/heads/feature')
|
|
Clement Verna |
469e2c |
|
|
Clement Verna |
469e2c |
# Remove the clone
|
|
Clement Verna |
469e2c |
shutil.rmtree(newgitrepo)
|
|
Clement Verna |
469e2c |
|
|
Clement Verna |
469e2c |
output4 = pagure.lib.git.get_revs_between(
|
|
Clement Verna |
f202e4 |
'0', branch_commit.oid.hex, gitrepo, 'refs/heads/feature')
|
|
Clement Verna |
469e2c |
self.assertEqual(output4, [branch_commit.oid.hex])
|
|
Clement Verna |
469e2c |
|
|
Pierre-Yves Chibon |
ad3d68 |
def test_get_author(self):
|
|
Pierre-Yves Chibon |
ad3d68 |
""" Test the get_author method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
84cd98 |
|
|
Pierre-Yves Chibon |
84cd98 |
self.test_update_git()
|
|
Pierre-Yves Chibon |
84cd98 |
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, '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 |
ad3d68 |
output = pagure.lib.git.get_author(githash, gitrepo)
|
|
Pierre-Yves Chibon |
84cd98 |
self.assertEqual(output, 'pagure')
|
|
Pierre-Yves Chibon |
84cd98 |
|
|
Pierre-Yves Chibon |
ad3d68 |
def get_author_email(self):
|
|
Pierre-Yves Chibon |
ad3d68 |
""" Test the get_author_email method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
f69b11 |
|
|
Pierre-Yves Chibon |
f69b11 |
self.test_update_git()
|
|
Pierre-Yves Chibon |
f69b11 |
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, '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 |
ad3d68 |
output = pagure.lib.git.get_author_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. """
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, '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. """
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, '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(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'forks', 'pingou', 'foo.test.git'))
|
|
Pierre-Yves Chibon |
a7c15a |
self.assertEqual(repo_name, 'pingou')
|
|
Pierre-Yves Chibon |
a7c15a |
|
|
Pierre-Yves Chibon |
826fb9 |
repo_name = pagure.lib.git.get_username(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'forks', 'pingou', 'bar/foo.test.git'))
|
|
Pierre-Yves Chibon |
826fb9 |
self.assertEqual(repo_name, 'pingou')
|
|
Pierre-Yves Chibon |
826fb9 |
|
|
Pierre-Yves Chibon |
826fb9 |
repo_name = pagure.lib.git.get_username(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'forks', 'pingou', 'fooo/bar/foo.test.git'))
|
|
Pierre-Yves Chibon |
826fb9 |
self.assertEqual(repo_name, 'pingou')
|
|
Pierre-Yves Chibon |
826fb9 |
|
|
Pierre-Yves Chibon |
0eb3ee |
def test_get_repo_namespace(self):
|
|
Pierre-Yves Chibon |
0eb3ee |
""" Test the get_repo_namespace method of pagure.lib.git. """
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'test_ticket_repo.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, None)
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'foo/bar/baz/test.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, 'foo/bar/baz')
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'foo.test.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, None)
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'user', 'foo.test.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, None)
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'user', 'bar/foo.test.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, 'bar')
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'user', 'ns/bar/foo.test.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, 'ns/bar')
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Pierre-Yves Chibon |
0eb3ee |
repo_name = pagure.lib.git.get_repo_namespace(os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'user', '/bar/foo.test.git'))
|
|
Pierre-Yves Chibon |
0eb3ee |
self.assertEqual(repo_name, 'bar')
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
Vivek Anand |
763ae5 |
def test_update_custom_fields_from_json(self):
|
|
Vivek Anand |
763ae5 |
""" Test the update_custom_fields_from_json method of lib.git """
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
tests.create_projects(self.session)
|
|
Vivek Anand |
763ae5 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
# Create issues to play with
|
|
Vivek Anand |
763ae5 |
pagure.lib.new_issue(
|
|
Vivek Anand |
763ae5 |
session=self.session,
|
|
Vivek Anand |
763ae5 |
repo=repo,
|
|
Vivek Anand |
763ae5 |
title='Test issue',
|
|
Vivek Anand |
763ae5 |
content='We should work on this',
|
|
Vivek Anand |
763ae5 |
user='pingou',
|
|
Vivek Anand |
763ae5 |
ticketfolder=None,
|
|
Vivek Anand |
763ae5 |
issue_uid='someuid'
|
|
Vivek Anand |
763ae5 |
)
|
|
Vivek Anand |
763ae5 |
self.session.commit()
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
issue = pagure.lib.get_issue_by_uid(self.session, 'someuid')
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
# Fake json data, currently without custom_fields
|
|
Vivek Anand |
763ae5 |
# This should bring no new custom_fields to the issue
|
|
Vivek Anand |
763ae5 |
json_data = {
|
|
Vivek Anand |
763ae5 |
"status": "Open",
|
|
Vivek Anand |
763ae5 |
"title": "Test issue",
|
|
Vivek Anand |
763ae5 |
"private": False,
|
|
Vivek Anand |
763ae5 |
"content": "We should work on this",
|
|
Vivek Anand |
763ae5 |
"user": {
|
|
Vivek Anand |
763ae5 |
"fullname": "PY C",
|
|
Vivek Anand |
763ae5 |
"name": "pingou",
|
|
Vivek Anand |
763ae5 |
"default_email": "bar@pingou.com",
|
|
Vivek Anand |
763ae5 |
"emails": ["bar@pingou.com"]
|
|
Vivek Anand |
763ae5 |
},
|
|
Vivek Anand |
763ae5 |
"id": 1,
|
|
Vivek Anand |
763ae5 |
"blocks": [],
|
|
Vivek Anand |
763ae5 |
"depends": [],
|
|
Vivek Anand |
763ae5 |
"date_created": "1234567",
|
|
Vivek Anand |
763ae5 |
"comments": [],
|
|
Vivek Anand |
763ae5 |
}
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
pagure.lib.git.update_custom_field_from_json(
|
|
Vivek Anand |
763ae5 |
self.session, repo, issue, json_data)
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
updated_issue = pagure.lib.get_issue_by_uid(self.session, 'someuid')
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
self.assertEqual(updated_issue.to_json().get('custom_fields'), [])
|
|
Vivek Anand |
763ae5 |
custom_fields = [
|
|
Vivek Anand |
763ae5 |
{
|
|
Vivek Anand |
763ae5 |
"name": "custom1",
|
|
Vivek Anand |
763ae5 |
"key_type": "text",
|
|
Vivek Anand |
763ae5 |
"value": "value1",
|
|
Vivek Anand |
763ae5 |
},
|
|
Vivek Anand |
763ae5 |
{
|
|
Vivek Anand |
763ae5 |
"name": "custom2",
|
|
Vivek Anand |
763ae5 |
"key_type": "text",
|
|
Vivek Anand |
763ae5 |
"value": "value2",
|
|
Vivek Anand |
763ae5 |
}
|
|
Vivek Anand |
763ae5 |
]
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
# Again, Fake the json data but, with custom_fields in it
|
|
Vivek Anand |
763ae5 |
# The updated issue should have the custom_fields as
|
|
Vivek Anand |
763ae5 |
# was in the json_data
|
|
Vivek Anand |
763ae5 |
json_data = {
|
|
Vivek Anand |
763ae5 |
"status": "Open",
|
|
Vivek Anand |
763ae5 |
"title": "Test issue",
|
|
Vivek Anand |
763ae5 |
"private": False,
|
|
Vivek Anand |
763ae5 |
"content": "We should work on this",
|
|
Vivek Anand |
763ae5 |
"user": {
|
|
Vivek Anand |
763ae5 |
"fullname": "PY C",
|
|
Vivek Anand |
763ae5 |
"name": "pingou",
|
|
Vivek Anand |
763ae5 |
"default_email": "bar@pingou.com",
|
|
Vivek Anand |
763ae5 |
"emails": ["bar@pingou.com"]
|
|
Vivek Anand |
763ae5 |
},
|
|
Vivek Anand |
763ae5 |
"id": 1,
|
|
Vivek Anand |
763ae5 |
"blocks": [],
|
|
Vivek Anand |
763ae5 |
"depends": [],
|
|
Vivek Anand |
763ae5 |
"date_created": "1234567",
|
|
Vivek Anand |
763ae5 |
"comments": [],
|
|
Vivek Anand |
763ae5 |
"custom_fields": custom_fields,
|
|
Vivek Anand |
763ae5 |
}
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
pagure.lib.git.update_custom_field_from_json(
|
|
Vivek Anand |
763ae5 |
self.session, repo, issue, json_data)
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
updated_issue = pagure.lib.get_issue_by_uid(self.session, 'someuid')
|
|
Vivek Anand |
763ae5 |
|
|
Vivek Anand |
763ae5 |
custom_fields_of_issue = updated_issue.to_json().get('custom_fields')
|
|
Vivek Anand |
763ae5 |
self.assertEqual(custom_fields_of_issue, custom_fields)
|
|
Pierre-Yves Chibon |
0eb3ee |
|
|
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)
|