|
Pierre-Yves Chibon |
9347b5 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
"""
|
|
Pierre-Yves Chibon |
b130e5 |
(c) 2015-2017 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
Authors:
|
|
Pierre-Yves Chibon |
9347b5 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
"""
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Aurélien Bompard |
626417 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
626417 |
|
|
Pierre-Yves Chibon |
9347b5 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
9347b5 |
import pkg_resources
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
import json
|
|
Pierre-Yves Chibon |
9347b5 |
import unittest
|
|
Pierre-Yves Chibon |
9347b5 |
import shutil
|
|
Pierre-Yves Chibon |
9347b5 |
import sys
|
|
Pierre-Yves Chibon |
9347b5 |
import tempfile
|
|
Pierre-Yves Chibon |
8b725c |
import time
|
|
Pierre-Yves Chibon |
9347b5 |
import os
|
|
ymdatta |
9ab5d0 |
import re
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
import pygit2
|
|
Aurélien Bompard |
619e2a |
import six
|
|
Pierre-Yves Chibon |
c29244 |
from mock import patch, MagicMock
|
|
Aurélien Bompard |
f61bb3 |
from bs4 import BeautifulSoup
|
|
ymdatta |
9ab5d0 |
from datetime import datetime, timedelta
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
9347b5 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Farhaan Bukhsh |
72e9db |
import pagure
|
|
Pierre-Yves Chibon |
9347b5 |
import pagure.lib
|
|
Pierre-Yves Chibon |
9347b5 |
import tests
|
|
Pierre-Yves Chibon |
27a73d |
from pagure.lib.repo import PagureRepo
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
edfd4c |
def _get_commits(output):
|
|
Pierre-Yves Chibon |
edfd4c |
''' Returns the commits message in the output. All commits must have
|
|
Pierre-Yves Chibon |
edfd4c |
been made by `Alice Author` or `PY C` to be found.
|
|
Pierre-Yves Chibon |
edfd4c |
'''
|
|
Pierre-Yves Chibon |
edfd4c |
commits = []
|
|
Pierre-Yves Chibon |
edfd4c |
save = False
|
|
Pierre-Yves Chibon |
edfd4c |
cnt = 0
|
|
Pierre-Yves Chibon |
edfd4c |
for row in output.split('\n'):
|
|
Pierre-Yves Chibon |
7c68f8 |
if row.strip() in ['Alice Author', 'Alice Äuthòr', 'PY C']:
|
|
Pierre-Yves Chibon |
edfd4c |
save = True
|
|
Pierre-Yves Chibon |
edfd4c |
if save:
|
|
Pierre-Yves Chibon |
edfd4c |
cnt += 1
|
|
Pierre-Yves Chibon |
edfd4c |
if cnt == 7:
|
|
Pierre-Yves Chibon |
edfd4c |
commits.append(row.strip())
|
|
Pierre-Yves Chibon |
edfd4c |
save = False
|
|
Pierre-Yves Chibon |
edfd4c |
cnt = 0
|
|
Pierre-Yves Chibon |
edfd4c |
return commits
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
9347b5 |
class PagureFlaskForktests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
9347b5 |
""" Tests for flask fork controller of pagure """
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
224b96 |
def set_up_git_repo(
|
|
Pierre-Yves Chibon |
2427e2 |
self, new_project=None, branch_from='feature', mtype='FF',
|
|
Pierre-Yves Chibon |
2427e2 |
prid=1, name_from='test'):
|
|
Pierre-Yves Chibon |
9347b5 |
""" Set up the git repo and create the corresponding PullRequest
|
|
Pierre-Yves Chibon |
9347b5 |
object.
|
|
Pierre-Yves Chibon |
9347b5 |
"""
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Create a git repo to play with
|
|
Pierre-Yves Chibon |
2427e2 |
gitrepo = os.path.join(self.path, 'repos', '%s.git' % name_from)
|
|
Pierre-Yves Chibon |
9347b5 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Pierre-Yves Chibon |
eaaf26 |
repopath = os.path.join(newpath, 'test')
|
|
Pierre-Yves Chibon |
eaaf26 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Create a file in that git repo
|
|
Pierre-Yves Chibon |
eaaf26 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
9347b5 |
stream.write('foo\n bar')
|
|
Pierre-Yves Chibon |
9347b5 |
clone_repo.index.add('sources')
|
|
Pierre-Yves Chibon |
9347b5 |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
2427e2 |
try:
|
|
Pierre-Yves Chibon |
2427e2 |
com = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
2427e2 |
prev_commit = [com.oid.hex]
|
|
Pierre-Yves Chibon |
2427e2 |
except:
|
|
Pierre-Yves Chibon |
2427e2 |
prev_commit = []
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Commits the files added
|
|
Pierre-Yves Chibon |
9347b5 |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
9347b5 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
9347b5 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
9347b5 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
9347b5 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
9347b5 |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
9347b5 |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
9347b5 |
author,
|
|
Pierre-Yves Chibon |
9347b5 |
committer,
|
|
Pierre-Yves Chibon |
9347b5 |
'Add sources file for testing',
|
|
Pierre-Yves Chibon |
9347b5 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
9347b5 |
tree,
|
|
Pierre-Yves Chibon |
9347b5 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
2427e2 |
prev_commit
|
|
Pierre-Yves Chibon |
9347b5 |
)
|
|
Pierre-Yves Chibon |
20a73c |
time.sleep(1)
|
|
Pierre-Yves Chibon |
9347b5 |
refname = 'refs/heads/master:refs/heads/master'
|
|
Pierre-Yves Chibon |
9347b5 |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
first_commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Aurélien Bompard |
619e2a |
def compatible_signature(name, email):
|
|
Aurélien Bompard |
619e2a |
if six.PY2:
|
|
Aurélien Bompard |
619e2a |
name = name.encode("utf-8")
|
|
Aurélien Bompard |
619e2a |
email = email.encode("utf-8")
|
|
Aurélien Bompard |
619e2a |
return pygit2.Signature(name, email)
|
|
Aurélien Bompard |
619e2a |
|
|
Pierre-Yves Chibon |
224b96 |
if mtype == 'merge':
|
|
Pierre-Yves Chibon |
eaaf26 |
with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
|
|
Pierre-Yves Chibon |
224b96 |
stream.write('*~')
|
|
Pierre-Yves Chibon |
224b96 |
clone_repo.index.add('.gitignore')
|
|
Pierre-Yves Chibon |
224b96 |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
224b96 |
|
|
Pierre-Yves Chibon |
224b96 |
# Commits the files added
|
|
Pierre-Yves Chibon |
224b96 |
tree = clone_repo.index.write_tree()
|
|
Aurélien Bompard |
619e2a |
author = compatible_signature(
|
|
Pierre-Yves Chibon |
7c68f8 |
'Alice Äuthòr', 'alice@äuthòrs.tld')
|
|
Aurélien Bompard |
619e2a |
comitter = compatible_signature(
|
|
Pierre-Yves Chibon |
7c68f8 |
'Cecil Cõmmîttër', 'cecil@cõmmîttërs.tld')
|
|
Pierre-Yves Chibon |
224b96 |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
224b96 |
'refs/heads/master',
|
|
Pierre-Yves Chibon |
224b96 |
author,
|
|
Pierre-Yves Chibon |
224b96 |
committer,
|
|
Pierre-Yves Chibon |
224b96 |
'Add .gitignore file for testing',
|
|
Pierre-Yves Chibon |
224b96 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
224b96 |
tree,
|
|
Pierre-Yves Chibon |
224b96 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
224b96 |
[first_commit.oid.hex]
|
|
Pierre-Yves Chibon |
224b96 |
)
|
|
Pierre-Yves Chibon |
224b96 |
refname = 'refs/heads/master:refs/heads/master'
|
|
Pierre-Yves Chibon |
224b96 |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
224b96 |
|
|
Pierre-Yves Chibon |
224b96 |
if mtype == 'conflicts':
|
|
Pierre-Yves Chibon |
eaaf26 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
224b96 |
stream.write('foo\n bar\nbaz')
|
|
Pierre-Yves Chibon |
224b96 |
clone_repo.index.add('sources')
|
|
Pierre-Yves Chibon |
224b96 |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
224b96 |
|
|
Pierre-Yves Chibon |
224b96 |
# Commits the files added
|
|
Pierre-Yves Chibon |
224b96 |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
224b96 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
224b96 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
224b96 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
224b96 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
224b96 |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
224b96 |
'refs/heads/master',
|
|
Pierre-Yves Chibon |
224b96 |
author,
|
|
Pierre-Yves Chibon |
224b96 |
committer,
|
|
Pierre-Yves Chibon |
224b96 |
'Add sources conflicting',
|
|
Pierre-Yves Chibon |
224b96 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
224b96 |
tree,
|
|
Pierre-Yves Chibon |
224b96 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
224b96 |
[first_commit.oid.hex]
|
|
Pierre-Yves Chibon |
224b96 |
)
|
|
Pierre-Yves Chibon |
224b96 |
refname = 'refs/heads/master:refs/heads/master'
|
|
Pierre-Yves Chibon |
224b96 |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
224b96 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Set the second repo
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
eaaf26 |
new_gitrepo = repopath
|
|
Pierre-Yves Chibon |
9347b5 |
if new_project:
|
|
Pierre-Yves Chibon |
9347b5 |
# Create a new git repo to play with
|
|
Pierre-Yves Chibon |
eaaf26 |
new_gitrepo = os.path.join(newpath, new_project.fullname)
|
|
Pierre-Yves Chibon |
9347b5 |
if not os.path.exists(new_gitrepo):
|
|
Pierre-Yves Chibon |
9347b5 |
os.makedirs(new_gitrepo)
|
|
Pierre-Yves Chibon |
9347b5 |
new_repo = pygit2.clone_repository(gitrepo, new_gitrepo)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
repo = pygit2.Repository(new_gitrepo)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
224b96 |
if mtype != 'nochanges':
|
|
Pierre-Yves Chibon |
224b96 |
# Edit the sources file again
|
|
Pierre-Yves Chibon |
224b96 |
with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
224b96 |
stream.write('foo\n bar\nbaz\n boose')
|
|
Pierre-Yves Chibon |
224b96 |
repo.index.add('sources')
|
|
Pierre-Yves Chibon |
224b96 |
repo.index.write()
|
|
Pierre-Yves Chibon |
224b96 |
|
|
Pierre-Yves Chibon |
224b96 |
# Commits the files added
|
|
Pierre-Yves Chibon |
224b96 |
tree = repo.index.write_tree()
|
|
Pierre-Yves Chibon |
224b96 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
224b96 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
224b96 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
224b96 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
224b96 |
repo.create_commit(
|
|
Pierre-Yves Chibon |
224b96 |
'refs/heads/%s' % branch_from,
|
|
Pierre-Yves Chibon |
224b96 |
author,
|
|
Pierre-Yves Chibon |
224b96 |
committer,
|
|
Pierre-Yves Chibon |
224b96 |
'A commit on branch %s' % branch_from,
|
|
Pierre-Yves Chibon |
224b96 |
tree,
|
|
Pierre-Yves Chibon |
224b96 |
[first_commit.oid.hex]
|
|
Pierre-Yves Chibon |
224b96 |
)
|
|
Pierre-Yves Chibon |
eaaf26 |
refname = 'refs/heads/%s' % (branch_from)
|
|
Pierre-Yves Chibon |
eaaf26 |
ori_remote = repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Create a PR for these changes
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
9347b5 |
session=self.session,
|
|
Pierre-Yves Chibon |
9347b5 |
repo_from=project,
|
|
Pierre-Yves Chibon |
9347b5 |
branch_from=branch_from,
|
|
Pierre-Yves Chibon |
9347b5 |
repo_to=project,
|
|
Pierre-Yves Chibon |
9347b5 |
branch_to='master',
|
|
Pierre-Yves Chibon |
9347b5 |
title='PR from the %s branch' % branch_from,
|
|
Pierre-Yves Chibon |
9347b5 |
user='pingou',
|
|
Pierre-Yves Chibon |
9347b5 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
9347b5 |
)
|
|
Pierre-Yves Chibon |
9347b5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(req.id, prid)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'PR from the %s branch' % branch_from)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
5d6e3d |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
5d6e3d |
|
|
Pierre-Yves Chibon |
8b725c |
def test_request_pull_reference(self):
|
|
Pierre-Yves Chibon |
8b725c |
""" Test if there is a reference created for a new PR. """
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
8b725c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
8b725c |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
8b725c |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
8b725c |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
8b725c |
self.assertEqual(len(project.requests), 1)
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
8b725c |
# View the pull-request
|
|
Pierre-Yves Chibon |
8b725c |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
8b725c |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
8b725c |
# Give time to the worker to process the task
|
|
Pierre-Yves Chibon |
8b725c |
time.sleep(1)
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
8b725c |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
8b725c |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
8b725c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
8b725c |
list(repo.listall_references()),
|
|
Pierre-Yves Chibon |
8b725c |
['refs/heads/feature', 'refs/heads/master', 'refs/pull/1/head']
|
|
Pierre-Yves Chibon |
8b725c |
)
|
|
Pierre-Yves Chibon |
8b725c |
|
|
Pierre-Yves Chibon |
9347b5 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
9347b5 |
def test_request_pull(self, send_email):
|
|
Pierre-Yves Chibon |
9347b5 |
""" Test the request_pull endpoint. """
|
|
Pierre-Yves Chibon |
9347b5 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
9347b5 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Non-existant project
|
|
Pierre-Yves Chibon |
9347b5 |
output = self.app.get('/foobar/pull-request/1')
|
|
Pierre-Yves Chibon |
9347b5 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
# Project has no PR
|
|
Pierre-Yves Chibon |
9347b5 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
9347b5 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
9347b5 |
self.assertEqual(len(project.requests), 1)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
9347b5 |
# View the pull-request
|
|
Pierre-Yves Chibon |
9347b5 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
9347b5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
b130e5 |
#self.assertIn(
|
|
Pierre-Yves Chibon |
b130e5 |
#'PR#1\n'
|
|
Aurélien Bompard |
626417 |
#' PR from the feature branch\n',
|
|
Aurélien Bompard |
626417 |
#output_text)
|
|
Pierre-Yves Chibon |
9347b5 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'title="View file as of 2a552b">sources', output_text)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pradeep CE (cep) |
3cbb79 |
# Test if the `open changed file icon` is displayed.
|
|
Pradeep CE (cep) |
3cbb79 |
self.assertIn(
|
|
Pradeep CE (cep) |
3cbb79 |
'class="open_changed_file_icon_wrap">
|
|
Pradeep CE (cep) |
3cbb79 |
'class="oi open_changed_file_icon" data-glyph="eye" '
|
|
Pradeep CE (cep) |
3cbb79 |
'alt="Open changed file" title="Open changed file">'
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Pradeep CE (cep) |
3cbb79 |
|
|
Clement Verna |
a77f88 |
self.assertIn(
|
|
Clement Verna |
a77f88 |
'
|
|
Aurélien Bompard |
626417 |
'pull-xs-right text-mono">+3', output_text)
|
|
Clement Verna |
a77f88 |
self.assertIn(
|
|
Clement Verna |
a77f88 |
'-1',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Clement Verna |
a77f88 |
|
|
Pierre-Yves Chibon |
502b7a |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
502b7a |
def test_merge_request_pull_FF(self, send_email):
|
|
Pierre-Yves Chibon |
8911da |
""" Test the merge_request_pull endpoint with a FF PR. """
|
|
Pierre-Yves Chibon |
502b7a |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
self.test_request_pull()
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# No CSRF
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data={}, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
b130e5 |
#self.assertIn(
|
|
Pierre-Yves Chibon |
b130e5 |
#'PR#1\n'
|
|
Aurélien Bompard |
626417 |
#' PR from the feature branch\n',
|
|
Aurélien Bompard |
626417 |
#output_text)
|
|
Pierre-Yves Chibon |
99b438 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'title="View file as of 2a552b">sources', output_text)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Wrong project
|
|
Pierre-Yves Chibon |
502b7a |
data = {
|
|
Pierre-Yves Chibon |
502b7a |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
502b7a |
}
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/foobar/pull-request/100/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Wrong project
|
|
Pierre-Yves Chibon |
502b7a |
data = {
|
|
Pierre-Yves Chibon |
502b7a |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
502b7a |
}
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Wrong request id
|
|
Pierre-Yves Chibon |
502b7a |
data = {
|
|
Pierre-Yves Chibon |
502b7a |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
502b7a |
}
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/100/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Project w/o pull-request
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
502b7a |
settings = repo.settings
|
|
Pierre-Yves Chibon |
502b7a |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
502b7a |
repo.settings = settings
|
|
Pierre-Yves Chibon |
502b7a |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
502b7a |
self.session.commit()
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Pull-request disabled
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Project w pull-request but only assignee can merge
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
502b7a |
settings['pull_requests'] = True
|
|
Pierre-Yves Chibon |
502b7a |
settings['Only_assignee_can_merge_pull-request'] = True
|
|
Pierre-Yves Chibon |
502b7a |
repo.settings = settings
|
|
Pierre-Yves Chibon |
502b7a |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
502b7a |
self.session.commit()
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
99b438 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n This request must be '
|
|
Aurélien Bompard |
626417 |
'assigned to be merged', output_text)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# PR assigned but not to this user
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
502b7a |
req = repo.requests[0]
|
|
Pierre-Yves Chibon |
502b7a |
req.assignee_id = 2
|
|
Pierre-Yves Chibon |
502b7a |
self.session.add(req)
|
|
Pierre-Yves Chibon |
502b7a |
self.session.commit()
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Only the assignee can '
|
|
Aurélien Bompard |
626417 |
'merge this review', output_text)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Project w/ minimal PR score
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
502b7a |
settings['Only_assignee_can_merge_pull-request'] = False
|
|
Pierre-Yves Chibon |
502b7a |
settings['Minimum_score_to_merge_pull-request'] = 2
|
|
Pierre-Yves Chibon |
502b7a |
repo.settings = settings
|
|
Pierre-Yves Chibon |
502b7a |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
502b7a |
self.session.commit()
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n This request does not '
|
|
Pierre-Yves Chibon |
19b2ae |
'have the minimum review score necessary to be merged',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
502b7a |
|
|
Pierre-Yves Chibon |
502b7a |
# Merge
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
502b7a |
settings['Minimum_score_to_merge_pull-request'] = -1
|
|
Pierre-Yves Chibon |
502b7a |
repo.settings = settings
|
|
Pierre-Yves Chibon |
502b7a |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
502b7a |
self.session.commit()
|
|
Pierre-Yves Chibon |
502b7a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
502b7a |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertEqual(output.status_code, 200)
|
|
Ryan Lerch |
6d2e06 |
|
|
Ryan Lerch |
6d2e06 |
output = self.app.get('/test/commits')
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Ryan Lerch |
6d2e06 |
'<title>Commits - test - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
502b7a |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'A commit on branch feature', output_text)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertNotIn(
|
|
Aurélien Bompard |
626417 |
'Merge #1 `PR from the feature branch`', output_text)
|
|
Ryan Lerch |
6d2e06 |
|
|
Pierre-Yves Chibon |
21dd34 |
# Check if the closing notification was added
|
|
Pierre-Yves Chibon |
21dd34 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
21dd34 |
self.assertIn(
|
|
Pierre-Yves Chibon |
be62f6 |
'<small>Pull-Request has been merged by pingou </small>',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
21dd34 |
|
|
Pierre-Yves Chibon |
4ce7b3 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
4ce7b3 |
def test_merge_request_pull_merge(self, send_email):
|
|
Pierre-Yves Chibon |
4ce7b3 |
""" Test the merge_request_pull endpoint with a merge PR. """
|
|
Pierre-Yves Chibon |
4ce7b3 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
4ce7b3 |
|
|
Pierre-Yves Chibon |
4ce7b3 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
4ce7b3 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
4ce7b3 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
4ce7b3 |
new_project=None, branch_from='feature', mtype='merge')
|
|
Pierre-Yves Chibon |
4ce7b3 |
|
|
Pierre-Yves Chibon |
4ce7b3 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
4ce7b3 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
4ce7b3 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
4ce7b3 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
4ce7b3 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
4ce7b3 |
|
|
Pierre-Yves Chibon |
4ce7b3 |
data = {
|
|
Pierre-Yves Chibon |
4ce7b3 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
4ce7b3 |
}
|
|
Pierre-Yves Chibon |
4ce7b3 |
|
|
Pierre-Yves Chibon |
4ce7b3 |
# Merge
|
|
Pierre-Yves Chibon |
4ce7b3 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
4ce7b3 |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
4ce7b3 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
4ce7b3 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Overview - test - Pagure</title>', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
4ce7b3 |
|
|
Pierre-Yves Chibon |
21dd34 |
# Check if the closing notification was added
|
|
Pierre-Yves Chibon |
21dd34 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
21dd34 |
self.assertIn(
|
|
Pierre-Yves Chibon |
be62f6 |
'<small>Pull-Request has been merged by pingou </small>',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
21dd34 |
|
|
Pierre-Yves Chibon |
fb36e7 |
@patch('pagure.lib.notify.send_email')
|
|
Lubomír Sedlář |
19e746 |
def test_merge_request_pull_merge_with_delete_branch(self, send_email):
|
|
Lubomír Sedlář |
19e746 |
""" Test the merge_request_pull endpoint with a merge PR and delete source branch. """
|
|
Lubomír Sedlář |
19e746 |
send_email.return_value = True
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
tests.create_projects(self.session)
|
|
Lubomír Sedlář |
19e746 |
tests.create_projects_git(
|
|
Lubomír Sedlář |
19e746 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Lubomír Sedlář |
19e746 |
self.set_up_git_repo(
|
|
Lubomír Sedlář |
19e746 |
new_project=None, branch_from='feature-branch', mtype='merge')
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
user = tests.FakeUser()
|
|
Lubomír Sedlář |
19e746 |
user.username = 'pingou'
|
|
Lubomír Sedlář |
19e746 |
with tests.user_set(self.app.application, user):
|
|
Lubomír Sedlář |
19e746 |
output = self.app.get('/test/pull-request/1')
|
|
Lubomír Sedlář |
19e746 |
self.assertEqual(output.status_code, 200)
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
data = {
|
|
Lubomír Sedlář |
19e746 |
'csrf_token': self.get_csrf(output=output),
|
|
Lubomír Sedlář |
19e746 |
'delete_branch': True,
|
|
Lubomír Sedlář |
19e746 |
}
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
# Merge
|
|
Lubomír Sedlář |
19e746 |
output = self.app.post(
|
|
Lubomír Sedlář |
19e746 |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Lubomír Sedlář |
19e746 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Lubomír Sedlář |
19e746 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Overview - test - Pagure</title>', output_text)
|
|
Lubomír Sedlář |
19e746 |
# Check the branch is not mentioned
|
|
Lubomír Sedlář |
19e746 |
self.assertNotIn(
|
|
Aurélien Bompard |
626417 |
'
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
fb36e7 |
def test_merge_request_pull_conflicts(self, send_email):
|
|
Pierre-Yves Chibon |
fb36e7 |
""" Test the merge_request_pull endpoint with a conflicting PR. """
|
|
Pierre-Yves Chibon |
fb36e7 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
fb36e7 |
|
|
Pierre-Yves Chibon |
fb36e7 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
fb36e7 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
fb36e7 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
fb36e7 |
new_project=None, branch_from='feature', mtype='conflicts')
|
|
Pierre-Yves Chibon |
fb36e7 |
|
|
Pierre-Yves Chibon |
fb36e7 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
fb36e7 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
fb36e7 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
fb36e7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fb36e7 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
fb36e7 |
|
|
Pierre-Yves Chibon |
fb36e7 |
data = {
|
|
Pierre-Yves Chibon |
fb36e7 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
fb36e7 |
}
|
|
Pierre-Yves Chibon |
fb36e7 |
|
|
Pierre-Yves Chibon |
fb36e7 |
# Merge conflicts
|
|
Pierre-Yves Chibon |
fb36e7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
fb36e7 |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
fb36e7 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
fb36e7 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Merge conflicts!', output_text)
|
|
Pierre-Yves Chibon |
fb36e7 |
|
|
Pierre-Yves Chibon |
51d667 |
@patch('pagure.lib.notify.send_email')
|
|
Lubomír Sedlář |
19e746 |
def test_merge_request_pull_conflicts_with_delete_branch(self, send_email):
|
|
Lubomír Sedlář |
19e746 |
""" Test the merge_request_pull endpoint with a conflicting PR and request deletion of branch. """
|
|
Lubomír Sedlář |
19e746 |
send_email.return_value = True
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
tests.create_projects(self.session)
|
|
Lubomír Sedlář |
19e746 |
tests.create_projects_git(
|
|
Lubomír Sedlář |
19e746 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Lubomír Sedlář |
19e746 |
self.set_up_git_repo(
|
|
Lubomír Sedlář |
19e746 |
new_project=None, branch_from='feature-branch', mtype='conflicts')
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
user = tests.FakeUser()
|
|
Lubomír Sedlář |
19e746 |
user.username = 'pingou'
|
|
Lubomír Sedlář |
19e746 |
with tests.user_set(self.app.application, user):
|
|
Lubomír Sedlář |
19e746 |
output = self.app.get('/test/pull-request/1')
|
|
Lubomír Sedlář |
19e746 |
self.assertEqual(output.status_code, 200)
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
data = {
|
|
Lubomír Sedlář |
19e746 |
'csrf_token': self.get_csrf(output=output),
|
|
Lubomír Sedlář |
19e746 |
'delete_branch': True,
|
|
Lubomír Sedlář |
19e746 |
}
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
# Merge conflicts
|
|
Lubomír Sedlář |
19e746 |
output = self.app.post(
|
|
Lubomír Sedlář |
19e746 |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Lubomír Sedlář |
19e746 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Lubomír Sedlář |
19e746 |
self.assertIn(
|
|
Lubomír Sedlář |
19e746 |
'PR#1\n'
|
|
Lubomír Sedlář |
19e746 |
' PR from the feature-branch branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Merge conflicts!', output_text)
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
# Check the branch still exists
|
|
Ryan Lerch |
6d2e06 |
output = self.app.get('/test/branches')
|
|
Aurélien Bompard |
626417 |
self.assertIn('feature-branch', output.get_data(as_text=True))
|
|
Lubomír Sedlář |
19e746 |
|
|
Lubomír Sedlář |
19e746 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
51d667 |
def test_merge_request_pull_nochange(self, send_email):
|
|
Pierre-Yves Chibon |
51d667 |
""" Test the merge_request_pull endpoint. """
|
|
Pierre-Yves Chibon |
51d667 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
51d667 |
|
|
Pierre-Yves Chibon |
51d667 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
51d667 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
51d667 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
51d667 |
new_project=None, branch_from='master', mtype='nochanges')
|
|
Pierre-Yves Chibon |
51d667 |
|
|
Pierre-Yves Chibon |
51d667 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
51d667 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
51d667 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
51d667 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
51d667 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
51d667 |
|
|
Pierre-Yves Chibon |
51d667 |
data = {
|
|
Pierre-Yves Chibon |
51d667 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
51d667 |
}
|
|
Pierre-Yves Chibon |
51d667 |
|
|
Pierre-Yves Chibon |
51d667 |
# Nothing to merge
|
|
Pierre-Yves Chibon |
51d667 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
51d667 |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
51d667 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
51d667 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' Merged',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Patrick Uiterwijk |
bb2453 |
self.assertIn('Nothing to do, changes were already merged',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
51d667 |
|
|
Pierre-Yves Chibon |
21dd34 |
# Check if the closing notification was added
|
|
Pierre-Yves Chibon |
21dd34 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
21dd34 |
self.assertIn(
|
|
Pierre-Yves Chibon |
be62f6 |
'<small>Pull-Request has been merged by pingou </small>',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
21dd34 |
|
|
Pierre-Yves Chibon |
21924a |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
21924a |
def test_request_pull_close(self, send_email):
|
|
Pierre-Yves Chibon |
21924a |
""" Test the request_pull endpoint with a closed PR. """
|
|
Pierre-Yves Chibon |
21924a |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
21924a |
|
|
Pierre-Yves Chibon |
21924a |
self.test_merge_request_pull_FF()
|
|
Pierre-Yves Chibon |
21924a |
|
|
Pierre-Yves Chibon |
21924a |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
21924a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
21924a |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' ', output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Merged by\n', output_text)
|
|
Pierre-Yves Chibon |
21924a |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'title="View file as of 2a552b">sources', output_text)
|
|
Pierre-Yves Chibon |
21924a |
|
|
Pierre-Yves Chibon |
c19e35 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
c19e35 |
def test_request_pull_disabled(self, send_email):
|
|
Pierre-Yves Chibon |
c19e35 |
""" Test the request_pull endpoint with PR disabled. """
|
|
Pierre-Yves Chibon |
c19e35 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
c19e35 |
|
|
Pierre-Yves Chibon |
c19e35 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
c19e35 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
c19e35 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Pierre-Yves Chibon |
c19e35 |
|
|
Pierre-Yves Chibon |
c19e35 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c19e35 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
c19e35 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
c19e35 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
c19e35 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
c19e35 |
self.session.commit()
|
|
Pierre-Yves Chibon |
c19e35 |
|
|
Pierre-Yves Chibon |
c19e35 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
c19e35 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
c19e35 |
|
|
Pierre-Yves Chibon |
cbbc1c |
@patch('pagure.lib.notify.send_email')
|
|
Aurélien Bompard |
d90ed4 |
@patch('pagure.lib.git.update_pull_ref')
|
|
Aurélien Bompard |
d90ed4 |
def test_request_pull_empty_repo(self, send_email, update_pull_ref):
|
|
Pierre-Yves Chibon |
ee247e |
""" Test the request_pull endpoint against an empty repo. """
|
|
Aurélien Bompard |
d90ed4 |
# Mock update_pull_ref or the repo won't be empty anymore
|
|
Aurélien Bompard |
d90ed4 |
# (the PR will have been pushed to refs/pull)
|
|
Pierre-Yves Chibon |
cbbc1c |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
cbbc1c |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
cbbc1c |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
cbbc1c |
name='test',
|
|
Pierre-Yves Chibon |
cbbc1c |
description='test project #1',
|
|
Pierre-Yves Chibon |
cbbc1c |
hook_token='aaabbb',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
Pierre-Yves Chibon |
cbbc1c |
parent_id=1,
|
|
Pierre-Yves Chibon |
cbbc1c |
)
|
|
Pierre-Yves Chibon |
cbbc1c |
self.session.add(item)
|
|
Pierre-Yves Chibon |
cbbc1c |
self.session.commit()
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
cbbc1c |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'forks', 'foo'), bare=True)
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
cbbc1c |
self.assertFalse(os.path.exists(gitrepo))
|
|
Pierre-Yves Chibon |
cbbc1c |
os.makedirs(gitrepo)
|
|
Pierre-Yves Chibon |
cbbc1c |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
# Create a fork of this repo
|
|
Pierre-Yves Chibon |
cbbc1c |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Pierre-Yves Chibon |
cbbc1c |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
# Edit the sources file again
|
|
Pierre-Yves Chibon |
cbbc1c |
with open(os.path.join(newpath, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
cbbc1c |
stream.write('foo\n bar\nbaz\n boose')
|
|
Pierre-Yves Chibon |
cbbc1c |
new_repo.index.add('sources')
|
|
Pierre-Yves Chibon |
cbbc1c |
new_repo.index.write()
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
# Commits the files added
|
|
Pierre-Yves Chibon |
cbbc1c |
tree = new_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
cbbc1c |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
cbbc1c |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
cbbc1c |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
cbbc1c |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
cbbc1c |
new_repo.create_commit(
|
|
Pierre-Yves Chibon |
cbbc1c |
'refs/heads/feature',
|
|
Pierre-Yves Chibon |
cbbc1c |
author,
|
|
Pierre-Yves Chibon |
cbbc1c |
committer,
|
|
Pierre-Yves Chibon |
cbbc1c |
'A commit on branch feature',
|
|
Pierre-Yves Chibon |
cbbc1c |
tree,
|
|
Pierre-Yves Chibon |
cbbc1c |
[]
|
|
Pierre-Yves Chibon |
cbbc1c |
)
|
|
Pierre-Yves Chibon |
cbbc1c |
refname = 'refs/heads/feature:refs/heads/feature'
|
|
Pierre-Yves Chibon |
cbbc1c |
ori_remote = new_repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
# Create a PR for these changes
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
cbbc1c |
session=self.session,
|
|
Pierre-Yves Chibon |
cbbc1c |
repo_from=item,
|
|
Pierre-Yves Chibon |
cbbc1c |
branch_from='feature',
|
|
Pierre-Yves Chibon |
cbbc1c |
repo_to=project,
|
|
Pierre-Yves Chibon |
cbbc1c |
branch_to='master',
|
|
Pierre-Yves Chibon |
cbbc1c |
title='PR from the feature branch',
|
|
Pierre-Yves Chibon |
cbbc1c |
user='pingou',
|
|
Pierre-Yves Chibon |
cbbc1c |
requestfolder=None,
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
)
|
|
Pierre-Yves Chibon |
cbbc1c |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'PR from the feature branch')
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
cbbc1c |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
cbbc1c |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
cbbc1c |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
fec7de |
self.assertTrue(
|
|
Aurélien Bompard |
626417 |
output_text.count(
|
|
Aurélien Bompard |
626417 |
'
|
|
Aurélien Bompard |
13bcde |
self.assertTrue(update_pull_ref.called)
|
|
Pierre-Yves Chibon |
cbbc1c |
|
|
Pierre-Yves Chibon |
54d454 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
54d454 |
|
|
Pierre-Yves Chibon |
981ad4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
981ad4 |
def test_request_pull_empty_fork(self, send_email):
|
|
Pierre-Yves Chibon |
981ad4 |
""" Test the request_pull endpoint from an empty fork. """
|
|
Pierre-Yves Chibon |
981ad4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
981ad4 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
981ad4 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
981ad4 |
name='test',
|
|
Pierre-Yves Chibon |
981ad4 |
description='test project #1',
|
|
Pierre-Yves Chibon |
981ad4 |
hook_token='aaabbb',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
Pierre-Yves Chibon |
981ad4 |
parent_id=1,
|
|
Pierre-Yves Chibon |
981ad4 |
)
|
|
Pierre-Yves Chibon |
981ad4 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
981ad4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
981ad4 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'forks', 'foo'), bare=True)
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
981ad4 |
self.assertFalse(os.path.exists(gitrepo))
|
|
Pierre-Yves Chibon |
981ad4 |
os.makedirs(gitrepo)
|
|
Pierre-Yves Chibon |
981ad4 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
# Create a fork of this repo
|
|
Pierre-Yves Chibon |
981ad4 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Pierre-Yves Chibon |
5bf6f1 |
gitrepo = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Pierre-Yves Chibon |
981ad4 |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
# Create a PR for these "changes" (there are none, both repos are
|
|
Pierre-Yves Chibon |
981ad4 |
# empty)
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
981ad4 |
session=self.session,
|
|
Pierre-Yves Chibon |
981ad4 |
repo_from=item,
|
|
Pierre-Yves Chibon |
981ad4 |
branch_from='feature',
|
|
Pierre-Yves Chibon |
981ad4 |
repo_to=project,
|
|
Pierre-Yves Chibon |
981ad4 |
branch_to='master',
|
|
Pierre-Yves Chibon |
981ad4 |
title='PR from the feature branch',
|
|
Pierre-Yves Chibon |
981ad4 |
user='pingou',
|
|
Pierre-Yves Chibon |
981ad4 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
)
|
|
Pierre-Yves Chibon |
981ad4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'PR from the feature branch')
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
981ad4 |
output = self.app.get('/test/pull-request/1', follow_redirects=True)
|
|
Pierre-Yves Chibon |
981ad4 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
981ad4 |
self.assertIn(
|
|
Pierre-Yves Chibon |
0428ed |
'<title>PR#1: PR from the feature branch - test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
981ad4 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'\n Fork is empty, there are no '
|
|
Aurélien Bompard |
626417 |
'commits to create a pull request with',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
981ad4 |
|
|
Pierre-Yves Chibon |
54d454 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
54d454 |
|
|
Pierre-Yves Chibon |
e8b89f |
@patch('pagure.lib.notify.send_email')
|
|
ymdatta |
9ab5d0 |
def test_request_pulls_order(self, send_email):
|
|
ymdatta |
9ab5d0 |
"""Test the request_pulls
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
i.e Make sure that the results are displayed
|
|
ymdatta |
9ab5d0 |
in the order required by the user"""
|
|
ymdatta |
9ab5d0 |
send_email.return_value = True
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
#Initially no project
|
|
ymdatta |
9ab5d0 |
output = self.app.get('/test/pull-requests')
|
|
ymdatta |
9ab5d0 |
self.assertEqual(output.status_code, 404)
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
tests.create_projects(self.session)
|
|
ymdatta |
9ab5d0 |
tests.create_projects_git(
|
|
ymdatta |
9ab5d0 |
os.path.join(self.path, 'repos'), bare=True)
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
ymdatta |
9ab5d0 |
item = pagure.lib.model.Project(
|
|
ymdatta |
9ab5d0 |
user_id=2,
|
|
ymdatta |
9ab5d0 |
name='test',
|
|
ymdatta |
9ab5d0 |
description='test project #1',
|
|
ymdatta |
9ab5d0 |
hook_token='aaabbb',
|
|
ymdatta |
9ab5d0 |
is_fork=True,
|
|
ymdatta |
9ab5d0 |
parent_id=1,
|
|
ymdatta |
9ab5d0 |
)
|
|
ymdatta |
9ab5d0 |
self.session.add(item)
|
|
ymdatta |
9ab5d0 |
self.session.commit()
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# create PR's to play with
|
|
ymdatta |
9ab5d0 |
# PR-1
|
|
ymdatta |
9ab5d0 |
req = pagure.lib.new_pull_request(
|
|
ymdatta |
9ab5d0 |
session=self.session,
|
|
ymdatta |
9ab5d0 |
repo_to=repo,
|
|
ymdatta |
9ab5d0 |
repo_from=item,
|
|
ymdatta |
9ab5d0 |
branch_from='feature',
|
|
ymdatta |
9ab5d0 |
branch_to='master',
|
|
ymdatta |
9ab5d0 |
title='PR from the feature branch',
|
|
ymdatta |
9ab5d0 |
user='pingou',
|
|
ymdatta |
9ab5d0 |
status='Open',
|
|
ymdatta |
9ab5d0 |
requestfolder=None,
|
|
ymdatta |
9ab5d0 |
)
|
|
ymdatta |
9ab5d0 |
self.session.commit()
|
|
ymdatta |
9ab5d0 |
self.assertEqual(req.id, 1)
|
|
ymdatta |
9ab5d0 |
self.assertEqual(req.title, 'PR from the feature branch')
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# PR-2
|
|
ymdatta |
9ab5d0 |
req = pagure.lib.new_pull_request(
|
|
ymdatta |
9ab5d0 |
session=self.session,
|
|
ymdatta |
9ab5d0 |
repo_to=repo,
|
|
ymdatta |
9ab5d0 |
branch_to='master',
|
|
ymdatta |
9ab5d0 |
branch_from='feature',
|
|
ymdatta |
9ab5d0 |
repo_from=item,
|
|
ymdatta |
9ab5d0 |
title='test PR',
|
|
ymdatta |
9ab5d0 |
user='pingou',
|
|
ymdatta |
9ab5d0 |
status='Open',
|
|
ymdatta |
9ab5d0 |
requestfolder=None,
|
|
ymdatta |
9ab5d0 |
)
|
|
ymdatta |
9ab5d0 |
self.session.commit()
|
|
ymdatta |
9ab5d0 |
self.assertEqual(req.title, 'test PR')
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# PR-3
|
|
ymdatta |
9ab5d0 |
req = pagure.lib.new_pull_request(
|
|
ymdatta |
9ab5d0 |
session=self.session,
|
|
ymdatta |
9ab5d0 |
repo_to=repo,
|
|
ymdatta |
9ab5d0 |
branch_from='feature',
|
|
ymdatta |
9ab5d0 |
branch_to='master',
|
|
ymdatta |
9ab5d0 |
repo_from=item,
|
|
ymdatta |
9ab5d0 |
title='test Invalid PR',
|
|
ymdatta |
9ab5d0 |
user='pingou',
|
|
ymdatta |
9ab5d0 |
status='Closed',
|
|
ymdatta |
9ab5d0 |
requestfolder=None,
|
|
ymdatta |
9ab5d0 |
)
|
|
ymdatta |
9ab5d0 |
self.session.commit()
|
|
ymdatta |
9ab5d0 |
self.assertEqual(req.title, 'test Invalid PR')
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# PR-4
|
|
ymdatta |
9ab5d0 |
req = pagure.lib.new_pull_request(
|
|
ymdatta |
9ab5d0 |
session=self.session,
|
|
ymdatta |
9ab5d0 |
repo_to=repo,
|
|
ymdatta |
9ab5d0 |
branch_from='feature',
|
|
ymdatta |
9ab5d0 |
title='test PR for sort',
|
|
ymdatta |
9ab5d0 |
repo_from=item,
|
|
ymdatta |
9ab5d0 |
user='pingou',
|
|
ymdatta |
9ab5d0 |
branch_to='master',
|
|
ymdatta |
9ab5d0 |
status='Open',
|
|
ymdatta |
9ab5d0 |
requestfolder=None,
|
|
ymdatta |
9ab5d0 |
)
|
|
ymdatta |
9ab5d0 |
self.session.commit()
|
|
ymdatta |
9ab5d0 |
self.assertEqual(req.title, 'test PR for sort')
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# sort by last_updated
|
|
ymdatta |
9ab5d0 |
output = self.app.get('/test/pull-requests?order_key=last_updated')
|
|
Pierre-Yves Chibon |
587ce4 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
587ce4 |
tr_elements = re.findall('(.*?)', output_text, re.M | re.S)
|
|
ymdatta |
9ab5d0 |
self.assertEqual(output.status_code, 200)
|
|
ymdatta |
9ab5d0 |
arrowed_th = ('Modified\n
|
|
ymdatta |
9ab5d0 |
'"arrow-thick-bottom">')
|
|
ymdatta |
9ab5d0 |
# First table row is the header
|
|
ymdatta |
9ab5d0 |
self.assertIn(arrowed_th, tr_elements[0])
|
|
ymdatta |
9ab5d0 |
# Make sure that issue four is first since it was modified last
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/4"', tr_elements[1])
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/2"', tr_elements[2])
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/1"', tr_elements[3])
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
pr_one = pagure.lib.search_pull_requests(
|
|
ymdatta |
9ab5d0 |
self.session, project_id=1, requestid=1)
|
|
ymdatta |
9ab5d0 |
pr_one.last_updated = datetime.utcnow() + timedelta(seconds=2)
|
|
ymdatta |
9ab5d0 |
self.session.add(pr_one)
|
|
ymdatta |
9ab5d0 |
self.session.commit()
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# sort by last_updated
|
|
ymdatta |
9ab5d0 |
output = self.app.get('/test/pull-requests?order_key=last_updated')
|
|
Pierre-Yves Chibon |
587ce4 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
587ce4 |
tr_elements = re.findall(r'(.*?)', output_text, re.M | re.S)
|
|
ymdatta |
9ab5d0 |
self.assertEqual(output.status_code, 200)
|
|
ymdatta |
9ab5d0 |
# Make sure that PR four is first since it was modified last
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/1"', tr_elements[1])
|
|
ymdatta |
9ab5d0 |
# Make sure that PR two is second since it was modified second
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/4"', tr_elements[2])
|
|
ymdatta |
9ab5d0 |
# Make sure that PR one is last since it was modified first
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/2"', tr_elements[3])
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
# Now query so that the results are ascending
|
|
ymdatta |
9ab5d0 |
output = self.app.get('/test/pull-requests?'
|
|
ymdatta |
9ab5d0 |
'order_key=last_updated&order=asc')
|
|
Pierre-Yves Chibon |
587ce4 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
587ce4 |
tr_elements = re.findall(r'(.*?)', output_text, re.M | re.S)
|
|
ymdatta |
9ab5d0 |
arrowed_th = ('Modified\n
|
|
ymdatta |
9ab5d0 |
'"arrow-thick-top">')
|
|
ymdatta |
9ab5d0 |
self.assertIn(arrowed_th, tr_elements[0])
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/2"', tr_elements[1])
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/4"', tr_elements[2])
|
|
ymdatta |
9ab5d0 |
self.assertIn('href="/test/pull-request/1"', tr_elements[3])
|
|
ymdatta |
9ab5d0 |
|
|
ymdatta |
9ab5d0 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
e8b89f |
def test_request_pulls(self, send_email):
|
|
Pierre-Yves Chibon |
a2d4e0 |
""" Test the request_pulls endpoint. """
|
|
Pierre-Yves Chibon |
e8b89f |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
e8b89f |
|
|
Pierre-Yves Chibon |
a2d4e0 |
# No such project
|
|
Pierre-Yves Chibon |
a2d4e0 |
output = self.app.get('/test/pull-requests')
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
a2d4e0 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b243a0 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos'), bare=True)
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
a2d4e0 |
output = self.app.get('/test/pull-requests')
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
fec7de |
self.assertIn(
|
|
Pierre-Yves Chibon |
a08c06 |
'\n 0 Pull Requests (of 0)\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Ryan Lerch |
8cc0a8 |
# Open is primary
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
8cc0a8 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests">Open', output_text)
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
eef090 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests?status=0">Closed', output_text)
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
a2d4e0 |
output = self.app.get('/test/pull-requests')
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
fec7de |
self.assertIn(
|
|
Pierre-Yves Chibon |
a08c06 |
'\n 1 Pull Requests (of 1)\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Ryan Lerch |
8cc0a8 |
# Open is primary
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
8cc0a8 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests">Open', output_text)
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
eef090 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests?status=0">Closed', output_text)
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
6e3c4b |
output = self.app.get('/test/pull-requests?status=Closed')
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
fec7de |
self.assertIn(
|
|
Pierre-Yves Chibon |
a08c06 |
'\n 0 Closed Pull Requests (of 0)\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Ryan Lerch |
8cc0a8 |
# Close is primary
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
8cc0a8 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests">Open', output_text)
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
8cc0a8 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests?status=0">Closed', output_text)
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
6e3c4b |
output = self.app.get('/test/pull-requests?status=0')
|
|
Pierre-Yves Chibon |
6e3c4b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
fec7de |
self.assertIn(
|
|
Pierre-Yves Chibon |
a08c06 |
'\n 0 Closed/Merged Pull Requests (of 0)\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
ymdatta |
9ab5d0 |
|
|
Ryan Lerch |
8cc0a8 |
# Close is primary
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
8cc0a8 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests">Open', output_text)
|
|
Ryan Lerch |
8cc0a8 |
self.assertIn(
|
|
Ryan Lerch |
8cc0a8 |
'
|
|
Aurélien Bompard |
626417 |
'href="/test/pull-requests?status=0">Closed', output_text)
|
|
Pierre-Yves Chibon |
6e3c4b |
|
|
Pierre-Yves Chibon |
a2d4e0 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
a2d4e0 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
a2d4e0 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
a2d4e0 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.session.commit()
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
a2d4e0 |
output = self.app.get('/test/pull-requests')
|
|
Pierre-Yves Chibon |
a2d4e0 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
a2d4e0 |
|
|
Pierre-Yves Chibon |
d61bcb |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
d61bcb |
def test_request_pull_patch(self, send_email):
|
|
Pierre-Yves Chibon |
d61bcb |
""" Test the request_pull_patch endpoint. """
|
|
Pierre-Yves Chibon |
d61bcb |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
output = self.app.get('/test/pull-request/1.patch')
|
|
Pierre-Yves Chibon |
d61bcb |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
d61bcb |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
d61bcb |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
d61bcb |
new_project=None, branch_from='feature', mtype='merge')
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
output = self.app.get('/test/pull-request/100.patch')
|
|
Pierre-Yves Chibon |
d61bcb |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
output = self.app.get('/test/pull-request/1.patch')
|
|
Pierre-Yves Chibon |
d61bcb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
npatch = []
|
|
Aurélien Bompard |
626417 |
for row in output.get_data(as_text=True).split('\n'):
|
|
Pierre-Yves Chibon |
d61bcb |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
d61bcb |
continue
|
|
Pierre-Yves Chibon |
d61bcb |
if row.startswith('From '):
|
|
Pierre-Yves Chibon |
d61bcb |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
d61bcb |
npatch.append(row)
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
d61bcb |
From: Alice Author <alice@authors.tld></alice@authors.tld>
|
|
Pierre-Yves Chibon |
d61bcb |
Subject: A commit on branch feature
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
---
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
diff --git a/.gitignore b/.gitignore
|
|
Pierre-Yves Chibon |
d61bcb |
new file mode 100644
|
|
Pierre-Yves Chibon |
d61bcb |
index 0000000..e4e5f6c
|
|
Pierre-Yves Chibon |
d61bcb |
--- /dev/null
|
|
Pierre-Yves Chibon |
d61bcb |
+++ b/.gitignore
|
|
Pierre-Yves Chibon |
d61bcb |
@@ -0,0 +1 @@
|
|
Pierre-Yves Chibon |
d61bcb |
+*~
|
|
Pierre-Yves Chibon |
d61bcb |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
d61bcb |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
d61bcb |
index 9f44358..2a552bb 100644
|
|
Pierre-Yves Chibon |
d61bcb |
--- a/sources
|
|
Pierre-Yves Chibon |
d61bcb |
+++ b/sources
|
|
Pierre-Yves Chibon |
d61bcb |
@@ -1,2 +1,4 @@
|
|
Pierre-Yves Chibon |
d61bcb |
foo
|
|
Pierre-Yves Chibon |
d61bcb |
- bar
|
|
Pierre-Yves Chibon |
d61bcb |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
d61bcb |
+ bar
|
|
Pierre-Yves Chibon |
d61bcb |
+baz
|
|
Pierre-Yves Chibon |
d61bcb |
+ boose
|
|
Pierre-Yves Chibon |
d61bcb |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
"""
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
d61bcb |
#print patch
|
|
Pierre-Yves Chibon |
d61bcb |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
d61bcb |
settings = repo.settings
|
|
Pierre-Yves Chibon |
d61bcb |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
d61bcb |
repo.settings = settings
|
|
Pierre-Yves Chibon |
d61bcb |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
d61bcb |
self.session.commit()
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
d61bcb |
output = self.app.get('/test/pull-request/1.patch')
|
|
Pierre-Yves Chibon |
d61bcb |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d61bcb |
|
|
Pierre-Yves Chibon |
b54ac4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
d9d369 |
def test_request_pull_diff(self, send_email):
|
|
Pierre-Yves Chibon |
d9d369 |
""" Test the request_pull_patch endpoint. """
|
|
Pierre-Yves Chibon |
d9d369 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
output = self.app.get('/test/pull-request/1.diff')
|
|
Pierre-Yves Chibon |
d9d369 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
d9d369 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
d9d369 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
d9d369 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
d9d369 |
new_project=None, branch_from='feature', mtype='merge')
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
output = self.app.get('/test/pull-request/100.diff')
|
|
Pierre-Yves Chibon |
d9d369 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
output = self.app.get('/test/pull-request/1.diff')
|
|
Pierre-Yves Chibon |
d9d369 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
exp = """diff --git a/.gitignore b/.gitignore
|
|
Pierre-Yves Chibon |
d9d369 |
new file mode 100644
|
|
Pierre-Yves Chibon |
d9d369 |
index 0000000..e4e5f6c
|
|
Pierre-Yves Chibon |
d9d369 |
--- /dev/null
|
|
Pierre-Yves Chibon |
d9d369 |
+++ b/.gitignore
|
|
Pierre-Yves Chibon |
d9d369 |
@@ -0,0 +1 @@
|
|
Pierre-Yves Chibon |
d9d369 |
+*~
|
|
Pierre-Yves Chibon |
d9d369 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
d9d369 |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
d9d369 |
index 9f44358..2a552bb 100644
|
|
Pierre-Yves Chibon |
d9d369 |
--- a/sources
|
|
Pierre-Yves Chibon |
d9d369 |
+++ b/sources
|
|
Pierre-Yves Chibon |
d9d369 |
@@ -1,2 +1,4 @@
|
|
Pierre-Yves Chibon |
d9d369 |
foo
|
|
Pierre-Yves Chibon |
d9d369 |
- bar
|
|
Pierre-Yves Chibon |
d9d369 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
d9d369 |
+ bar
|
|
Pierre-Yves Chibon |
d9d369 |
+baz
|
|
Pierre-Yves Chibon |
d9d369 |
+ boose
|
|
Pierre-Yves Chibon |
d9d369 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
d9d369 |
"""
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Aurélien Bompard |
626417 |
self.assertEqual(output.get_data(as_text=True), exp)
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
d9d369 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
d9d369 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
d9d369 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
d9d369 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
d9d369 |
self.session.commit()
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
output = self.app.get('/test/pull-request/1.diff')
|
|
Pierre-Yves Chibon |
d9d369 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
d9d369 |
|
|
Pierre-Yves Chibon |
d9d369 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
f75e13 |
def test_request_pull_patch_close(self, send_email):
|
|
Pierre-Yves Chibon |
f75e13 |
""" Test the request_pull_patch endpoint with a closed PR. """
|
|
Pierre-Yves Chibon |
f75e13 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
self.test_merge_request_pull_FF()
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
output = self.app.get('/test/pull-request/1.patch')
|
|
Pierre-Yves Chibon |
f75e13 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
npatch = []
|
|
Aurélien Bompard |
626417 |
for row in output.get_data(as_text=True).split('\n'):
|
|
Pierre-Yves Chibon |
f75e13 |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
f75e13 |
continue
|
|
Pierre-Yves Chibon |
f75e13 |
if row.startswith('From '):
|
|
Pierre-Yves Chibon |
f75e13 |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
f75e13 |
npatch.append(row)
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
f75e13 |
From: Alice Author <alice@authors.tld></alice@authors.tld>
|
|
Pierre-Yves Chibon |
f75e13 |
Subject: A commit on branch feature
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
---
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
f75e13 |
index 9f44358..2a552bb 100644
|
|
Pierre-Yves Chibon |
f75e13 |
--- a/sources
|
|
Pierre-Yves Chibon |
f75e13 |
+++ b/sources
|
|
Pierre-Yves Chibon |
f75e13 |
@@ -1,2 +1,4 @@
|
|
Pierre-Yves Chibon |
f75e13 |
foo
|
|
Pierre-Yves Chibon |
f75e13 |
- bar
|
|
Pierre-Yves Chibon |
f75e13 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
f75e13 |
+ bar
|
|
Pierre-Yves Chibon |
f75e13 |
+baz
|
|
Pierre-Yves Chibon |
f75e13 |
+ boose
|
|
Pierre-Yves Chibon |
f75e13 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
"""
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
f75e13 |
#print patch
|
|
Pierre-Yves Chibon |
f75e13 |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
f75e13 |
|
|
Pierre-Yves Chibon |
f75e13 |
@patch('pagure.lib.notify.send_email')
|
|
Aurélien Bompard |
d90ed4 |
@patch('pagure.lib.git.update_pull_ref')
|
|
Aurélien Bompard |
d90ed4 |
def test_request_pull_patch_empty_repo(self, send_email, update_pull_ref):
|
|
Pierre-Yves Chibon |
300a00 |
""" Test the request_pull_patch endpoint against an empty repo. """
|
|
Aurélien Bompard |
d90ed4 |
# Mock update_pull_ref or the repo won't be empty anymore
|
|
Aurélien Bompard |
d90ed4 |
# (the PR will have been pushed to refs/pull)
|
|
Pierre-Yves Chibon |
300a00 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
300a00 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
300a00 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
300a00 |
name='test',
|
|
Pierre-Yves Chibon |
300a00 |
description='test project #1',
|
|
Pierre-Yves Chibon |
300a00 |
hook_token='aaabbb',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
Pierre-Yves Chibon |
300a00 |
parent_id=1,
|
|
Pierre-Yves Chibon |
300a00 |
)
|
|
Pierre-Yves Chibon |
300a00 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
300a00 |
self.session.commit()
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
300a00 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'forks', 'foo'), bare=True)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
300a00 |
self.assertFalse(os.path.exists(gitrepo))
|
|
Pierre-Yves Chibon |
300a00 |
os.makedirs(gitrepo)
|
|
Pierre-Yves Chibon |
300a00 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
# Create a fork of this repo
|
|
Pierre-Yves Chibon |
300a00 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Pierre-Yves Chibon |
5bf6f1 |
gitrepo = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Pierre-Yves Chibon |
300a00 |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
# Edit the sources file again
|
|
Pierre-Yves Chibon |
300a00 |
with open(os.path.join(newpath, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
300a00 |
stream.write('foo\n bar\nbaz\n boose')
|
|
Pierre-Yves Chibon |
300a00 |
new_repo.index.add('sources')
|
|
Pierre-Yves Chibon |
300a00 |
new_repo.index.write()
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
# Commits the files added
|
|
Pierre-Yves Chibon |
300a00 |
tree = new_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
300a00 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
300a00 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
300a00 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
300a00 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
300a00 |
new_repo.create_commit(
|
|
Pierre-Yves Chibon |
300a00 |
'refs/heads/feature',
|
|
Pierre-Yves Chibon |
300a00 |
author,
|
|
Pierre-Yves Chibon |
300a00 |
committer,
|
|
Pierre-Yves Chibon |
300a00 |
'A commit on branch feature',
|
|
Pierre-Yves Chibon |
300a00 |
tree,
|
|
Pierre-Yves Chibon |
300a00 |
[]
|
|
Pierre-Yves Chibon |
300a00 |
)
|
|
Pierre-Yves Chibon |
300a00 |
refname = 'refs/heads/feature:refs/heads/feature'
|
|
Pierre-Yves Chibon |
300a00 |
ori_remote = new_repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
# Create a PR for these "changes" (there are none, both repos are
|
|
Pierre-Yves Chibon |
300a00 |
# empty)
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
300a00 |
session=self.session,
|
|
Pierre-Yves Chibon |
300a00 |
repo_from=item,
|
|
Pierre-Yves Chibon |
300a00 |
branch_from='feature',
|
|
Pierre-Yves Chibon |
300a00 |
repo_to=project,
|
|
Pierre-Yves Chibon |
300a00 |
branch_to='master',
|
|
Pierre-Yves Chibon |
300a00 |
title='PR from the feature branch',
|
|
Pierre-Yves Chibon |
300a00 |
user='pingou',
|
|
Pierre-Yves Chibon |
300a00 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
)
|
|
Pierre-Yves Chibon |
300a00 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'PR from the feature branch')
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
5bf6f1 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
5bf6f1 |
'/test/pull-request/1.patch', follow_redirects=True)
|
|
Pierre-Yves Chibon |
300a00 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
npatch = []
|
|
Aurélien Bompard |
626417 |
for row in output.get_data(as_text=True).split('\n'):
|
|
Pierre-Yves Chibon |
300a00 |
if row.startswith('Date:'):
|
|
Pierre-Yves Chibon |
300a00 |
continue
|
|
Pierre-Yves Chibon |
300a00 |
if row.startswith('From '):
|
|
Pierre-Yves Chibon |
300a00 |
row = row.split(' ', 2)[2]
|
|
Pierre-Yves Chibon |
300a00 |
npatch.append(row)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
exp = """Mon Sep 17 00:00:00 2001
|
|
Pierre-Yves Chibon |
300a00 |
From: Alice Author <alice@authors.tld></alice@authors.tld>
|
|
Pierre-Yves Chibon |
300a00 |
Subject: A commit on branch feature
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
---
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
diff --git a/sources b/sources
|
|
Pierre-Yves Chibon |
300a00 |
new file mode 100644
|
|
Pierre-Yves Chibon |
300a00 |
index 0000000..2a552bb
|
|
Pierre-Yves Chibon |
300a00 |
--- /dev/null
|
|
Pierre-Yves Chibon |
300a00 |
+++ b/sources
|
|
Pierre-Yves Chibon |
300a00 |
@@ -0,0 +1,4 @@
|
|
Pierre-Yves Chibon |
300a00 |
+foo
|
|
Pierre-Yves Chibon |
300a00 |
+ bar
|
|
Pierre-Yves Chibon |
300a00 |
+baz
|
|
Pierre-Yves Chibon |
300a00 |
+ boose
|
|
Pierre-Yves Chibon |
300a00 |
\ No newline at end of file
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
"""
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
300a00 |
patch = '\n'.join(npatch)
|
|
Pierre-Yves Chibon |
300a00 |
#print patch
|
|
Pierre-Yves Chibon |
300a00 |
self.assertEqual(patch, exp)
|
|
Pierre-Yves Chibon |
300a00 |
|
|
Pierre-Yves Chibon |
54d454 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
54d454 |
|
|
Pierre-Yves Chibon |
300a00 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
b54ac4 |
def test_request_pull_patch_empty_fork(self, send_email):
|
|
Pierre-Yves Chibon |
b54ac4 |
""" Test the request_pull_patch endpoint from an empty fork. """
|
|
Pierre-Yves Chibon |
b54ac4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
b54ac4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b54ac4 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
b54ac4 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
b54ac4 |
name='test',
|
|
Pierre-Yves Chibon |
b54ac4 |
description='test project #1',
|
|
Pierre-Yves Chibon |
b54ac4 |
hook_token='aaabbb',
|
|
farhaanbukhsh |
907098 |
is_fork=True,
|
|
Pierre-Yves Chibon |
b54ac4 |
parent_id=1,
|
|
Pierre-Yves Chibon |
b54ac4 |
)
|
|
Pierre-Yves Chibon |
b54ac4 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
b54ac4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
b54ac4 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
b54ac4 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'forks', 'foo'), bare=True)
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
b54ac4 |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
b54ac4 |
self.assertFalse(os.path.exists(gitrepo))
|
|
Pierre-Yves Chibon |
b54ac4 |
os.makedirs(gitrepo)
|
|
Pierre-Yves Chibon |
b54ac4 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
b54ac4 |
# Create a fork of this repo
|
|
Pierre-Yves Chibon |
b54ac4 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Pierre-Yves Chibon |
5bf6f1 |
gitrepo = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Pierre-Yves Chibon |
b54ac4 |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
b54ac4 |
# Create a PR for these "changes" (there are none, both repos are
|
|
Pierre-Yves Chibon |
b54ac4 |
# empty)
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
b54ac4 |
session=self.session,
|
|
Pierre-Yves Chibon |
b54ac4 |
repo_from=item,
|
|
Pierre-Yves Chibon |
b54ac4 |
branch_from='feature',
|
|
Pierre-Yves Chibon |
b54ac4 |
repo_to=project,
|
|
Pierre-Yves Chibon |
b54ac4 |
branch_to='master',
|
|
Pierre-Yves Chibon |
b54ac4 |
title='PR from the feature branch',
|
|
Pierre-Yves Chibon |
b54ac4 |
user='pingou',
|
|
Pierre-Yves Chibon |
b54ac4 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
b54ac4 |
)
|
|
Pierre-Yves Chibon |
b54ac4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'PR from the feature branch')
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Aurélien Bompard |
626417 |
output = self.app.get('/test/pull-request/1.patch',
|
|
Aurélien Bompard |
626417 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
b54ac4 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
b54ac4 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Overview - test - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
b54ac4 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'\n Fork is empty, there are no '
|
|
Aurélien Bompard |
626417 |
'commits to create a pull request with',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
b54ac4 |
|
|
Pierre-Yves Chibon |
54d454 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
54d454 |
|
|
Pierre-Yves Chibon |
ccefd8 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
ccefd8 |
def test_cancel_request_pull(self, send_email):
|
|
Pierre-Yves Chibon |
ccefd8 |
""" Test the cancel_request_pull endpoint. """
|
|
Pierre-Yves Chibon |
ccefd8 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
ccefd8 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
ccefd8 |
new_project=None, branch_from='feature', mtype='merge')
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post('/test/pull-request/cancel/1')
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ccefd8 |
'/test/pull-request/cancel/1', follow_redirects=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Overview - test - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Invalid input submitted',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
data = {
|
|
Pierre-Yves Chibon |
ccefd8 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
ccefd8 |
}
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
# Invalid project
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
bea002 |
'/foo/pull-request/cancel/1', data=data,
|
|
Pierre-Yves Chibon |
bea002 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
# Invalid PR id
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
bea002 |
'/test/pull-request/cancel/100', data=data,
|
|
Pierre-Yves Chibon |
bea002 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
# Invalid user for this project
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
bea002 |
'/test/pull-request/cancel/1', data=data,
|
|
Pierre-Yves Chibon |
bea002 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
ccefd8 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
ccefd8 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
ccefd8 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
ccefd8 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
ccefd8 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
bea002 |
'/test/pull-request/cancel/1', data=data,
|
|
Pierre-Yves Chibon |
bea002 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
0add6c |
# Project w/ pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
ccefd8 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
ccefd8 |
settings['pull_requests'] = True
|
|
Pierre-Yves Chibon |
ccefd8 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
ccefd8 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
ccefd8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
bea002 |
'/test/pull-request/cancel/1', data=data,
|
|
Pierre-Yves Chibon |
bea002 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'<title>Overview - test - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
ccefd8 |
self.assertIn(
|
|
Stanislav Laznicka |
14c8c3 |
'\n Pull request canceled!',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
ccefd8 |
|
|
Pierre-Yves Chibon |
c29244 |
@patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
c29244 |
def test_update_pull_requests_assign(self):
|
|
Pierre-Yves Chibon |
c29244 |
""" Test the update_pull_requests endpoint when assigning a PR.
|
|
Pierre-Yves Chibon |
c29244 |
"""
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
005063 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
005063 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
user = tests.FakeUser()
|
|
Ryan Lerch |
deaa7c |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
2af4a0 |
# No such project
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post('/foo/pull-request/1/update')
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post('/test/pull-request/100/update')
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
# Invalid input
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', follow_redirects=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Request assigned',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
data = {
|
|
Pierre-Yves Chibon |
005063 |
'user': 'pingou',
|
|
Pierre-Yves Chibon |
005063 |
}
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
# No CSRF
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
005063 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Request assigned',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
# Invalid assignee
|
|
Pierre-Yves Chibon |
005063 |
data = {
|
|
Pierre-Yves Chibon |
005063 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
005063 |
'user': 'bar',
|
|
Pierre-Yves Chibon |
005063 |
}
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
005063 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n No user "bar" found',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
# Assign the PR
|
|
Pierre-Yves Chibon |
005063 |
data = {
|
|
Pierre-Yves Chibon |
005063 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
005063 |
'user': 'pingou',
|
|
Pierre-Yves Chibon |
005063 |
}
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
2af4a0 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
2af4a0 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
2af4a0 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
2af4a0 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
2af4a0 |
|
|
Pierre-Yves Chibon |
2af4a0 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
005063 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
005063 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Request assigned',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
# Pull-Request closed
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
005063 |
req = repo.requests[0]
|
|
Pierre-Yves Chibon |
ce0f3f |
req.status = 'Closed'
|
|
Pierre-Yves Chibon |
ce0f3f |
req.closed_by_in = 1
|
|
Pierre-Yves Chibon |
005063 |
self.session.add(req)
|
|
Pierre-Yves Chibon |
005063 |
self.session.commit()
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
c29244 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c29244 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
c29244 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
c29244 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
c29244 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
c29244 |
self.session.commit()
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
c29244 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
@patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
c29244 |
def test_update_pull_requests_tag(self):
|
|
Pierre-Yves Chibon |
c29244 |
""" Test the update_pull_requests endpoint when tagging a PR.
|
|
Pierre-Yves Chibon |
c29244 |
"""
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
c29244 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
c29244 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
c29244 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
data = {
|
|
Pierre-Yves Chibon |
c29244 |
'tag': 'black',
|
|
Pierre-Yves Chibon |
c29244 |
}
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
# No CSRF
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
c29244 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c29244 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c29244 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
c29244 |
'\n Request assigned',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
# Tag the PR
|
|
Pierre-Yves Chibon |
c29244 |
data = {
|
|
Pierre-Yves Chibon |
c29244 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
c29244 |
'tag': 'black',
|
|
Pierre-Yves Chibon |
c29244 |
}
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
c29244 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c29244 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c29244 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c29244 |
'\n Pull-request tagged with: black',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertIn(
|
|
Pierre-Yves Chibon |
c29244 |
'title="comma separated list of tags"\n '
|
|
Aurélien Bompard |
626417 |
'value="black" />', output_text)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
# Try as another user
|
|
Pierre-Yves Chibon |
c29244 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
c29244 |
# Tag the PR
|
|
Pierre-Yves Chibon |
c29244 |
data = {
|
|
Pierre-Yves Chibon |
c29244 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
c29244 |
'tag': 'blue, yellow',
|
|
Pierre-Yves Chibon |
c29244 |
}
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
c29244 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
# Make the PR be from foo
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c29244 |
req = repo.requests[0]
|
|
Pierre-Yves Chibon |
c29244 |
req.user_id = 2
|
|
Pierre-Yves Chibon |
c29244 |
self.session.add(req)
|
|
Pierre-Yves Chibon |
c29244 |
self.session.commit()
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
# Re-try to tag the PR
|
|
Pierre-Yves Chibon |
c29244 |
data = {
|
|
Pierre-Yves Chibon |
c29244 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
c29244 |
'tag': 'blue, yellow',
|
|
Pierre-Yves Chibon |
c29244 |
}
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
c29244 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
c29244 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
soup = BeautifulSoup(output.get_data(as_text=True), "html.parser")
|
|
Aurélien Bompard |
f61bb3 |
self.assertEqual(
|
|
Aurélien Bompard |
f61bb3 |
soup.find("title").string,
|
|
Aurélien Bompard |
f61bb3 |
'PR#1: PR from the feature branch - test\n - Pagure'
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Aurélien Bompard |
f61bb3 |
h3 = soup.find("h3")
|
|
Aurélien Bompard |
f61bb3 |
self.assertIsNotNone(h3)
|
|
Aurélien Bompard |
f61bb3 |
self.assertListEqual(
|
|
Aurélien Bompard |
f61bb3 |
h3.find("span")["class"], ["label", "label-default"])
|
|
Aurélien Bompard |
f61bb3 |
self.assertEqual(h3.find("span").string, "PR#1")
|
|
Aurélien Bompard |
f61bb3 |
self.assertEqual(
|
|
Aurélien Bompard |
f61bb3 |
list(h3.stripped_strings)[1], 'PR from the feature branch')
|
|
Aurélien Bompard |
f61bb3 |
alerts = [
|
|
Aurélien Bompard |
f61bb3 |
list(a.stripped_strings)[2] for a in
|
|
Aurélien Bompard |
f61bb3 |
soup.find_all("div", class_="alert")
|
|
Aurélien Bompard |
f61bb3 |
if list(a.stripped_strings)
|
|
Aurélien Bompard |
f61bb3 |
]
|
|
Aurélien Bompard |
f61bb3 |
self.assertIn('Pull-request **un**tagged with: black', alerts)
|
|
Aurélien Bompard |
f61bb3 |
self.assertIn('Pull-request tagged with: blue, yellow', alerts)
|
|
Aurélien Bompard |
f61bb3 |
input_tag = soup.find("input", id="tag")
|
|
Aurélien Bompard |
f61bb3 |
self.assertEqual(
|
|
Aurélien Bompard |
f61bb3 |
input_tag["title"], "comma separated list of tags")
|
|
Aurélien Bompard |
f61bb3 |
# The order is not guaranteed, compare sets.
|
|
Aurélien Bompard |
f61bb3 |
self.assertEqual(
|
|
Aurélien Bompard |
f61bb3 |
set(input_tag["value"].split(",")),
|
|
Aurélien Bompard |
f61bb3 |
set(["blue", "yellow"])
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
c29244 |
# Pull-Request closed
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
c29244 |
req = repo.requests[0]
|
|
Pierre-Yves Chibon |
c29244 |
req.status = 'Closed'
|
|
Pierre-Yves Chibon |
c29244 |
req.closed_by_in = 1
|
|
Pierre-Yves Chibon |
c29244 |
self.session.add(req)
|
|
Pierre-Yves Chibon |
c29244 |
self.session.commit()
|
|
Pierre-Yves Chibon |
c29244 |
|
|
Pierre-Yves Chibon |
c29244 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
005063 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
005063 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
005063 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
005063 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
005063 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
005063 |
self.session.commit()
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
005063 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
c29244 |
'/test/pull-request/1/update', data=data,
|
|
Pierre-Yves Chibon |
005063 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
005063 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
005063 |
|
|
Pierre-Yves Chibon |
652a23 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
652a23 |
def test_fork_project(self, send_email):
|
|
Pierre-Yves Chibon |
652a23 |
""" Test the fork_project endpoint. """
|
|
Pierre-Yves Chibon |
652a23 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
2099a6 |
for folder in ['docs', 'tickets', 'requests', 'repos']:
|
|
Pierre-Yves Chibon |
652a23 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, folder), bare=True)
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
652a23 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
652a23 |
output = self.app.post('/do_fork/test')
|
|
Pierre-Yves Chibon |
652a23 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
output = self.app.get('/new/')
|
|
Pierre-Yves Chibon |
652a23 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Create new Project', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
data = {
|
|
Pierre-Yves Chibon |
652a23 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
652a23 |
}
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
652a23 |
'/do_fork/foo', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
652a23 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
652a23 |
output = self.app.post('/do_fork/test')
|
|
Pierre-Yves Chibon |
652a23 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
data = {
|
|
Pierre-Yves Chibon |
652a23 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
652a23 |
}
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
652a23 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
652a23 |
'/do_fork/test', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
652a23 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
652a23 |
|
|
Pierre-Yves Chibon |
cec97d |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
e3d601 |
def test_new_request_pull_branch_space(self, send_email):
|
|
Pierre-Yves Chibon |
e3d601 |
""" Test the new_request_pull endpoint. """
|
|
Pierre-Yves Chibon |
e3d601 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
e3d601 |
|
|
Pierre-Yves Chibon |
e3d601 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
e3d601 |
|
|
Pierre-Yves Chibon |
e3d601 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
e3d601 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
e3d601 |
|
|
Pierre-Yves Chibon |
e3d601 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
e3d601 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
e3d601 |
|
|
Pierre-Yves Chibon |
e3d601 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
e3d601 |
new_project=fork, branch_from='feature', mtype='FF')
|
|
Pierre-Yves Chibon |
e3d601 |
|
|
Pierre-Yves Chibon |
e3d601 |
user = tests.FakeUser(username = 'pingou')
|
|
Pierre-Yves Chibon |
e3d601 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
e3d601 |
output = self.app.get('/test/diff/master..foo bar')
|
|
Pierre-Yves Chibon |
e3d601 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
e3d601 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
e3d601 |
self.assertIn(
|
|
Pierre-Yves Chibon |
e3d601 |
'Branch foo bar does not exist ', output_text)
|
|
Pierre-Yves Chibon |
e3d601 |
|
|
Pierre-Yves Chibon |
e3d601 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
cec97d |
def test_new_request_pull(self, send_email):
|
|
Pierre-Yves Chibon |
cec97d |
""" Test the new_request_pull endpoint. """
|
|
Pierre-Yves Chibon |
cec97d |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b130e5 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
cec97d |
new_project=fork, branch_from='feature', mtype='FF')
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
cec97d |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.get('/foo/diff/master..feature')
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.get('/test/diff/master..foo')
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.get('/test/diff/foo..master')
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.get('/test/diff/feature..master')
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertIn(
|
|
Pierre-Yves Chibon |
8544f4 |
'<title>Diff from master to feature - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
' No commits found ', output_text)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertIn(
|
|
Pierre-Yves Chibon |
8544f4 |
'<title>Diff from feature to master - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
cec97d |
'
|
|
Aurélien Bompard |
626417 |
'value="Create">', output_text)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertIn(
|
|
Pierre-Yves Chibon |
8544f4 |
'<title>Create new Pull Request for master - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertIn(
|
|
Pierre-Yves Chibon |
fec7de |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Clement Verna |
43d191 |
# Case 1 - Add an initial comment
|
|
Pierre-Yves Chibon |
cec97d |
data = {
|
|
Pierre-Yves Chibon |
cec97d |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
cec97d |
'title': 'foo bar PR',
|
|
Clement Verna |
f6e82b |
'initial_comment': 'Test Initial Comment',
|
|
Pierre-Yves Chibon |
cec97d |
}
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pierre-Yves Chibon |
cec97d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
cec97d |
'/test/diff/master..feature', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
cec97d |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#2: foo bar PR - test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Test Initial Comment ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertEqual(
|
|
Aurélien Bompard |
626417 |
output_text.count('title="PY C (pingou)"'),
|
|
Aurélien Bompard |
626417 |
1)
|
|
Pierre-Yves Chibon |
cec97d |
|
|
Pradeep CE (cep) |
3cbb79 |
# Test if the `open changed file icon` is displayed.
|
|
Pradeep CE (cep) |
3cbb79 |
self.assertIn(
|
|
Pradeep CE (cep) |
3cbb79 |
'class="open_changed_file_icon_wrap">
|
|
Pradeep CE (cep) |
3cbb79 |
'class="oi open_changed_file_icon" data-glyph="eye" '
|
|
Pradeep CE (cep) |
3cbb79 |
'alt="Open changed file" title="Open changed file">'
|
|
Aurélien Bompard |
626417 |
'', output_text)
|
|
Clement Verna |
43d191 |
|
|
Clement Verna |
43d191 |
# Case 2 - Add an empty initial comment
|
|
Clement Verna |
43d191 |
data = {
|
|
Clement Verna |
43d191 |
'csrf_token': csrf_token,
|
|
Clement Verna |
43d191 |
'title': 'foo bar PR',
|
|
Clement Verna |
43d191 |
'initial_comment': '',
|
|
Clement Verna |
43d191 |
}
|
|
Clement Verna |
43d191 |
|
|
Clement Verna |
43d191 |
output = self.app.post(
|
|
Clement Verna |
43d191 |
'/test/diff/master..feature', data=data, follow_redirects=True)
|
|
Clement Verna |
43d191 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Clement Verna |
43d191 |
self.assertIn(
|
|
Clement Verna |
43d191 |
'<title>PR#3: foo bar PR - test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertNotIn('
|
|
Clement Verna |
43d191 |
|
|
Pierre-Yves Chibon |
5fb13f |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
93cd1e |
def test_new_request_pull_req_sign_off_view(self, send_email):
|
|
Pierre-Yves Chibon |
93cd1e |
""" Test the new_request_pull endpoint. """
|
|
Pierre-Yves Chibon |
93cd1e |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
93cd1e |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b130e5 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
# Enforce Signed-of-by in the repo
|
|
Pierre-Yves Chibon |
93cd1e |
settings = repo.settings
|
|
Pierre-Yves Chibon |
93cd1e |
settings['Enforce_signed-off_commits_in_pull-request'] = True
|
|
Pierre-Yves Chibon |
93cd1e |
repo.settings = settings
|
|
Pierre-Yves Chibon |
93cd1e |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
93cd1e |
self.session.commit()
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
93cd1e |
new_project=fork, branch_from='feature', mtype='FF')
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
93cd1e |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'<title>Diff from feature to master - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'\n This project enforces the '
|
|
Aurélien Bompard |
626417 |
'Signed-off-by statement on all commits', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'\n This repo enforces that '
|
|
Aurélien Bompard |
626417 |
'all commits are signed off by their author.', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
93cd1e |
def test_new_request_pull_req_sign_off_submit(self, send_email):
|
|
Pierre-Yves Chibon |
93cd1e |
""" Test the new_request_pull endpoint. """
|
|
Pierre-Yves Chibon |
93cd1e |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
93cd1e |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b130e5 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
# Enforce Signed-of-by in the repo
|
|
Pierre-Yves Chibon |
93cd1e |
settings = repo.settings
|
|
Pierre-Yves Chibon |
93cd1e |
settings['Enforce_signed-off_commits_in_pull-request'] = True
|
|
Pierre-Yves Chibon |
93cd1e |
repo.settings = settings
|
|
Pierre-Yves Chibon |
93cd1e |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
93cd1e |
self.session.commit()
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
93cd1e |
new_project=fork, branch_from='feature', mtype='FF')
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
93cd1e |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'<title>Create new Pull Request for master - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'\n This project enforces the '
|
|
Aurélien Bompard |
626417 |
'Signed-off-by statement on all commits', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
# Try to create the PR
|
|
Pierre-Yves Chibon |
93cd1e |
data = {
|
|
Pierre-Yves Chibon |
93cd1e |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
93cd1e |
'title': 'foo bar PR',
|
|
Pierre-Yves Chibon |
93cd1e |
'initial_comment': 'Test Initial Comment',
|
|
Pierre-Yves Chibon |
93cd1e |
}
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
93cd1e |
'/test/diff/master..feature', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'<title>Create new Pull Request for master - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
# Flashed information message
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'\n This project enforces the '
|
|
Aurélien Bompard |
626417 |
'Signed-off-by statement on all commits', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
# Flashed error message
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'\n This repo enforces that '
|
|
Aurélien Bompard |
626417 |
'all commits are signed off by their author.', output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
self.assertIn(
|
|
Pierre-Yves Chibon |
93cd1e |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
93cd1e |
|
|
Pierre-Yves Chibon |
93cd1e |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
ede430 |
def test_request_pull_commit_start_stop(self, send_email):
|
|
Pierre-Yves Chibon |
ede430 |
""" Test the the commit start and stop of brand new PR. """
|
|
Pierre-Yves Chibon |
ede430 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
ede430 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b130e5 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
ede430 |
new_project=fork, branch_from='feature', mtype='FF')
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
ede430 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
ede430 |
output = self.app.get('/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
ede430 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
ede430 |
self.assertIn(
|
|
Pierre-Yves Chibon |
ede430 |
'<title>Create new Pull Request for master - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
ede430 |
self.assertIn(
|
|
Pierre-Yves Chibon |
ede430 |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
# Case 1 - Add an initial comment
|
|
Pierre-Yves Chibon |
ede430 |
data = {
|
|
Pierre-Yves Chibon |
ede430 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
ede430 |
'title': 'foo bar PR',
|
|
Pierre-Yves Chibon |
ede430 |
'initial_comment': 'Test Initial Comment',
|
|
Pierre-Yves Chibon |
ede430 |
}
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ede430 |
'/test/diff/master..feature', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
ede430 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
ede430 |
self.assertIn(
|
|
Pierre-Yves Chibon |
ede430 |
'<title>PR#2: foo bar PR - test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Test Initial Comment ', output_text)
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
# Check if commit start and stop have been set for PR#2
|
|
Pierre-Yves Chibon |
ede430 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
ede430 |
self.session, project_id=1, requestid=2)
|
|
Pierre-Yves Chibon |
ede430 |
self.assertIsNotNone(request.commit_start)
|
|
Pierre-Yves Chibon |
ede430 |
self.assertIsNotNone(request.commit_stop)
|
|
Pierre-Yves Chibon |
ede430 |
|
|
Pierre-Yves Chibon |
ede430 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
2427e2 |
def test_new_request_pull_fork_to_fork_pr_disabled(self, send_email):
|
|
Pierre-Yves Chibon |
2427e2 |
""" Test creating a fork to fork PR. """
|
|
Pierre-Yves Chibon |
2427e2 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Create a 3rd user
|
|
Pierre-Yves Chibon |
2427e2 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
2427e2 |
user='ralph',
|
|
Pierre-Yves Chibon |
2427e2 |
fullname='Ralph bar',
|
|
Pierre-Yves Chibon |
2427e2 |
password='ralph_foo',
|
|
Pierre-Yves Chibon |
2427e2 |
default_email='ralph@bar.com',
|
|
Pierre-Yves Chibon |
2427e2 |
)
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
2427e2 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
2427e2 |
user_id=3,
|
|
Pierre-Yves Chibon |
2427e2 |
email='ralph@bar.com')
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
2427e2 |
user.username = 'ralph'
|
|
Pierre-Yves Chibon |
2427e2 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
2427e2 |
# Have Ralph fork, foo's fork of test
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.get('/fork/foo/test')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.post('/do_fork/fork/foo/test')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
2427e2 |
data = {
|
|
Pierre-Yves Chibon |
2427e2 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
2427e2 |
}
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
2427e2 |
'/do_fork/fork/foo/test', data=data,
|
|
Pierre-Yves Chibon |
2427e2 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Check that Ralph's fork do exist
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.get('/fork/ralph/test')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
2427e2 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
fork = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
2427e2 |
self.session, 'test', user='ralph')
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
2427e2 |
new_project=fork, branch_from='feature', mtype='FF')
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Try opening a pull-request
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
2427e2 |
'/fork/ralph/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'No pull-request allowed on this project ',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
2427e2 |
def test_new_request_pull_fork_to_fork(self, send_email):
|
|
Pierre-Yves Chibon |
2427e2 |
""" Test creating a fork to fork PR. """
|
|
Pierre-Yves Chibon |
2427e2 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Create a 3rd user
|
|
Pierre-Yves Chibon |
2427e2 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
2427e2 |
user='ralph',
|
|
Pierre-Yves Chibon |
2427e2 |
fullname='Ralph bar',
|
|
Pierre-Yves Chibon |
2427e2 |
password='ralph_foo',
|
|
Pierre-Yves Chibon |
2427e2 |
default_email='ralph@bar.com',
|
|
Pierre-Yves Chibon |
2427e2 |
)
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
2427e2 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
2427e2 |
user_id=3,
|
|
Pierre-Yves Chibon |
2427e2 |
email='ralph@bar.com')
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
2427e2 |
user.username = 'ralph'
|
|
Pierre-Yves Chibon |
2427e2 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
2427e2 |
# Have Ralph fork, foo's fork of test
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.get('/fork/foo/test')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.post('/do_fork/fork/foo/test')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
2427e2 |
data = {
|
|
Pierre-Yves Chibon |
2427e2 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
2427e2 |
}
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
2427e2 |
'/do_fork/fork/foo/test', data=data,
|
|
Pierre-Yves Chibon |
2427e2 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Check that Ralph's fork do exist
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.get('/fork/ralph/test')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
2427e2 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Turn on pull-request on the fork
|
|
Pierre-Yves Chibon |
2427e2 |
repo = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
2427e2 |
self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
2427e2 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
2427e2 |
settings['pull_requests'] = True
|
|
Pierre-Yves Chibon |
2427e2 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
2427e2 |
self.session.commit()
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Add some content to the parent
|
|
Pierre-Yves Chibon |
2427e2 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
2427e2 |
new_project=repo, branch_from='master', mtype='FF',
|
|
Pierre-Yves Chibon |
2427e2 |
name_from=repo.fullname)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
fork = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
2427e2 |
self.session, 'test', user='ralph')
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
2427e2 |
new_project=fork, branch_from='feature', mtype='FF',
|
|
Pierre-Yves Chibon |
2427e2 |
prid=2, name_from=fork.fullname)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Try opening a pull-request
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
2427e2 |
'/fork/ralph/test/diff/master..feature')
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2427e2 |
'<title>Create new Pull Request for master - fork/ralph/test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2427e2 |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
# Case 1 - Add an initial comment
|
|
Pierre-Yves Chibon |
2427e2 |
data = {
|
|
Pierre-Yves Chibon |
2427e2 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
2427e2 |
'title': 'foo bar PR',
|
|
Pierre-Yves Chibon |
2427e2 |
'initial_comment': 'Test Initial Comment',
|
|
Pierre-Yves Chibon |
2427e2 |
}
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
2427e2 |
'/fork/ralph/test/diff/master..feature',
|
|
Pierre-Yves Chibon |
2427e2 |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
2427e2 |
self.assertIn(
|
|
Pierre-Yves Chibon |
2427e2 |
'<title>PR#1: foo bar PR - fork/foo/test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Test Initial Comment ', output_text)
|
|
Pierre-Yves Chibon |
2427e2 |
|
|
Pierre-Yves Chibon |
2427e2 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
031d54 |
def test_new_request_pull_fork_to_other_fork(self, send_email):
|
|
Pierre-Yves Chibon |
031d54 |
""" Test creating a PR from fork to a fork of the same family. """
|
|
Pierre-Yves Chibon |
031d54 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Create a 3rd user
|
|
Pierre-Yves Chibon |
031d54 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
031d54 |
user='ralph',
|
|
Pierre-Yves Chibon |
031d54 |
fullname='Ralph bar',
|
|
Pierre-Yves Chibon |
031d54 |
password='ralph_foo',
|
|
Pierre-Yves Chibon |
031d54 |
default_email='ralph@bar.com',
|
|
Pierre-Yves Chibon |
031d54 |
)
|
|
Pierre-Yves Chibon |
031d54 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
031d54 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
031d54 |
user_id=3,
|
|
Pierre-Yves Chibon |
031d54 |
email='ralph@bar.com')
|
|
Pierre-Yves Chibon |
031d54 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
031d54 |
self.session.commit()
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
031d54 |
user.username = 'ralph'
|
|
Pierre-Yves Chibon |
031d54 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
031d54 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
031d54 |
data = {
|
|
Pierre-Yves Chibon |
031d54 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
031d54 |
}
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
031d54 |
'/do_fork/test', data=data,
|
|
Pierre-Yves Chibon |
031d54 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Check that Ralph's fork do exist
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.get('/fork/ralph/test')
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
031d54 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Turn on pull-request on the fork
|
|
Pierre-Yves Chibon |
031d54 |
repo = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
031d54 |
self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
031d54 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
031d54 |
settings['pull_requests'] = True
|
|
Pierre-Yves Chibon |
031d54 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
031d54 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
031d54 |
self.session.commit()
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Add some content to the parents
|
|
Pierre-Yves Chibon |
031d54 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
031d54 |
new_project=repo, branch_from='master', mtype='FF')
|
|
Pierre-Yves Chibon |
031d54 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
031d54 |
new_project=repo, branch_from='master', mtype='FF',
|
|
Pierre-Yves Chibon |
031d54 |
name_from=repo.fullname, prid=2)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
fork = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
031d54 |
self.session, 'test', user='ralph')
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
031d54 |
new_project=fork, branch_from='feature', mtype='FF',
|
|
Pierre-Yves Chibon |
031d54 |
prid=3, name_from=fork.fullname)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Try opening a pull-request
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
031d54 |
'/fork/ralph/test/diff/master..feature?project_to=fork/foo/test')
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertIn(
|
|
Pierre-Yves Chibon |
031d54 |
'<title>Create new Pull Request for master - fork/ralph/test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertIn(
|
|
Pierre-Yves Chibon |
031d54 |
'<input class="btn btn-primary" type="submit" value="Create">',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Case 1 - Opening PR to fork/foo/test
|
|
Pierre-Yves Chibon |
031d54 |
data = {
|
|
Pierre-Yves Chibon |
031d54 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
031d54 |
'title': 'foo bar PR',
|
|
Pierre-Yves Chibon |
031d54 |
'initial_comment': 'Test Initial Comment',
|
|
Pierre-Yves Chibon |
031d54 |
}
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
031d54 |
'/fork/ralph/test/diff/master..feature?project_to=fork/foo/test',
|
|
Pierre-Yves Chibon |
031d54 |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertIn(
|
|
Pierre-Yves Chibon |
031d54 |
'<title>PR#1: foo bar PR - fork/foo/test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Test Initial Comment ', output_text)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Case 1 - Opening PR to parent repo, shows project_to works
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
031d54 |
'/fork/ralph/test/diff/master..feature',
|
|
Pierre-Yves Chibon |
031d54 |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertIn(
|
|
Pierre-Yves Chibon |
031d54 |
'<title>PR#4: foo bar PR - test\n - Pagure</title>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Test Initial Comment ', output_text)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
031d54 |
def test_new_request_pull_fork_to_other_unrelated_fork(self, send_email):
|
|
Pierre-Yves Chibon |
031d54 |
""" Test creating a PR from fork to fork that isn't from the same
|
|
Pierre-Yves Chibon |
031d54 |
family.
|
|
Pierre-Yves Chibon |
031d54 |
"""
|
|
Pierre-Yves Chibon |
031d54 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Create a 3rd user
|
|
Pierre-Yves Chibon |
031d54 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
031d54 |
user='ralph',
|
|
Pierre-Yves Chibon |
031d54 |
fullname='Ralph bar',
|
|
Pierre-Yves Chibon |
031d54 |
password='ralph_foo',
|
|
Pierre-Yves Chibon |
031d54 |
default_email='ralph@bar.com',
|
|
Pierre-Yves Chibon |
031d54 |
)
|
|
Pierre-Yves Chibon |
031d54 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
031d54 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
031d54 |
user_id=3,
|
|
Pierre-Yves Chibon |
031d54 |
email='ralph@bar.com')
|
|
Pierre-Yves Chibon |
031d54 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
031d54 |
self.session.commit()
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
031d54 |
user.username = 'ralph'
|
|
Pierre-Yves Chibon |
031d54 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
031d54 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
031d54 |
data = {
|
|
Pierre-Yves Chibon |
031d54 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
031d54 |
}
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
031d54 |
'/do_fork/test2', data=data,
|
|
Pierre-Yves Chibon |
031d54 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Check that Ralph's fork do exist
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.get('/fork/ralph/test2')
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
031d54 |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Turn on pull-request on the fork
|
|
Pierre-Yves Chibon |
031d54 |
repo = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
031d54 |
self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
031d54 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
031d54 |
settings['pull_requests'] = True
|
|
Pierre-Yves Chibon |
031d54 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
031d54 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
031d54 |
self.session.commit()
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Add some content to the parent
|
|
Pierre-Yves Chibon |
031d54 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
031d54 |
new_project=repo, branch_from='master', mtype='FF',
|
|
Pierre-Yves Chibon |
031d54 |
name_from=repo.fullname)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
fork = pagure.lib.get_authorized_project(
|
|
Pierre-Yves Chibon |
031d54 |
self.session, 'test2', user='ralph')
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
031d54 |
new_project=fork, branch_from='feature', mtype='FF',
|
|
Pierre-Yves Chibon |
031d54 |
prid=2, name_from=fork.fullname)
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
# Case 1 - Opening PR to fork/foo/test
|
|
Pierre-Yves Chibon |
031d54 |
data = {
|
|
Pierre-Yves Chibon |
031d54 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
031d54 |
'title': 'foo bar PR',
|
|
Pierre-Yves Chibon |
031d54 |
'initial_comment': 'Test Initial Comment',
|
|
Pierre-Yves Chibon |
031d54 |
}
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
031d54 |
'/fork/ralph/test2/diff/master..feature?project_to=fork/foo/test',
|
|
Pierre-Yves Chibon |
031d54 |
data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
031d54 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
"fork/foo/test is not part of fork/ralph/test2's "
|
|
Aurélien Bompard |
626417 |
"family", output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
031d54 |
|
|
Pierre-Yves Chibon |
031d54 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
5fb13f |
def test_new_request_pull_empty_repo(self, send_email):
|
|
Pierre-Yves Chibon |
5fb13f |
""" Test the new_request_pull endpoint against an empty repo. """
|
|
Pierre-Yves Chibon |
5fb13f |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b130e5 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
5fb13f |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
# Create a fork of this repo
|
|
Pierre-Yves Chibon |
5fb13f |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Pierre-Yves Chibon |
5fb13f |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
5fb13f |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
4a3837 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
4a3837 |
'/fork/foo/test/diff/master..feature',
|
|
Pierre-Yves Chibon |
4a3837 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
875a08 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
5fb13f |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'Fork is empty, there are no commits to create a pull '
|
|
Aurélien Bompard |
626417 |
'request with', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
bab89f |
output = self.app.get('/test/new_issue')
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
data = {
|
|
Pierre-Yves Chibon |
5fb13f |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
5fb13f |
'title': 'foo bar PR',
|
|
Pierre-Yves Chibon |
5fb13f |
}
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
5fb13f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5fb13f |
'/test/diff/master..feature', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
875a08 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
5fb13f |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'Fork is empty, there are no commits to create a pull '
|
|
Aurélien Bompard |
626417 |
'request with', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5fb13f |
|
|
Pierre-Yves Chibon |
54d454 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
54d454 |
|
|
Pierre-Yves Chibon |
c18cb0 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
c18cb0 |
def test_new_request_pull_empty_fork(self, send_email):
|
|
Pierre-Yves Chibon |
c18cb0 |
""" Test the new_request_pull endpoint against an empty repo. """
|
|
Pierre-Yves Chibon |
c18cb0 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
c18cb0 |
self.test_fork_project()
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
c18cb0 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b130e5 |
fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo')
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
c18cb0 |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
c18cb0 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
c18cb0 |
# Create a fork of this repo
|
|
Pierre-Yves Chibon |
c18cb0 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Pierre-Yves Chibon |
5bf6f1 |
gitrepo = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Pierre-Yves Chibon |
c18cb0 |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
c18cb0 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
c18cb0 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
c18cb0 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
c18cb0 |
'/fork/foo/test/diff/master..master', follow_redirects=True)
|
|
Pierre-Yves Chibon |
875a08 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
c18cb0 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'Fork is empty, there are no commits to create a pull '
|
|
Aurélien Bompard |
626417 |
'request with', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
c18cb0 |
|
|
Pierre-Yves Chibon |
54d454 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
54d454 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
eeb8a9 |
def test_pull_request_add_comment(self, send_email):
|
|
Pierre-Yves Chibon |
eeb8a9 |
""" Test the pull_request_add_comment endpoint. """
|
|
Pierre-Yves Chibon |
eeb8a9 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.test_request_pull()
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
eeb8a9 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
eeb8a9 |
output = self.app.post('/foo/pull-request/1/comment')
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
output = self.app.post('/test/pull-request/100/comment')
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
output = self.app.post('/test/pull-request/1/comment')
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertTrue(
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True).startswith('\n<section class="add_comment">'))</section>
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
data = {
|
|
Pierre-Yves Chibon |
eeb8a9 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
eeb8a9 |
'comment': 'This look alright but we can do better',
|
|
Pierre-Yves Chibon |
eeb8a9 |
}
|
|
Pierre-Yves Chibon |
eeb8a9 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
eeb8a9 |
'/test/pull-request/1/comment', data=data,
|
|
Pierre-Yves Chibon |
eeb8a9 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertIn(
|
|
Pierre-Yves Chibon |
99b438 |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Comment added',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Aurélien Bompard |
626417 |
self.assertEqual(output_text.count('title="PY C (pingou)"'), 2)
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
eeb8a9 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
eeb8a9 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
eeb8a9 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.session.commit()
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
eeb8a9 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
eeb8a9 |
'/test/pull-request/1/comment', data=data,
|
|
Pierre-Yves Chibon |
eeb8a9 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
eeb8a9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
eeb8a9 |
|
|
Pierre-Yves Chibon |
6d9a52 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
6d9a52 |
def test_pull_request_drop_comment(self, send_email):
|
|
Pierre-Yves Chibon |
6d9a52 |
""" Test the pull_request_drop_comment endpoint. """
|
|
Pierre-Yves Chibon |
6d9a52 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
self.test_pull_request_add_comment()
|
|
Pierre-Yves Chibon |
6d9a52 |
# Project w/ pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6d9a52 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
6d9a52 |
settings['pull_requests'] = True
|
|
Pierre-Yves Chibon |
6d9a52 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
6d9a52 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
6d9a52 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post('/foo/pull-request/1/comment/drop')
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post('/test/pull-request/100/comment/drop')
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6d9a52 |
'/test/pull-request/1/comment/drop', follow_redirects=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Aurélien Bompard |
626417 |
#self.assertIn('href="#comment-1">¶', output_text)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertIn(
|
|
Pierre-Yves Chibon |
6d9a52 |
'This look alright but we can do better ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
# Invalid comment id
|
|
Pierre-Yves Chibon |
6d9a52 |
data = {
|
|
Pierre-Yves Chibon |
6d9a52 |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
6d9a52 |
'drop_comment': '10',
|
|
Pierre-Yves Chibon |
6d9a52 |
}
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6d9a52 |
'/test/pull-request/1/comment/drop', data=data,
|
|
Pierre-Yves Chibon |
6d9a52 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
data['drop_comment'] = '1'
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6d9a52 |
'/test/pull-request/1/comment/drop', data=data,
|
|
Pierre-Yves Chibon |
6d9a52 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
6d9a52 |
# Drop comment
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6d9a52 |
'/test/pull-request/1/comment/drop', data=data,
|
|
Pierre-Yves Chibon |
6d9a52 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Comment removed',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6d9a52 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
6d9a52 |
settings['pull_requests'] = False
|
|
Pierre-Yves Chibon |
6d9a52 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
6d9a52 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
Pierre-Yves Chibon |
6d9a52 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6d9a52 |
'/test/pull-request/1/comment/drop', data=data,
|
|
Pierre-Yves Chibon |
6d9a52 |
follow_redirects=True)
|
|
Pierre-Yves Chibon |
6d9a52 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
6d9a52 |
|
|
farhaanbukhsh |
a04e02 |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
a04e02 |
def test_pull_request_edit_comment(self, send_email):
|
|
farhaanbukhsh |
a04e02 |
""" Test the pull request edit comment endpoint """
|
|
farhaanbukhsh |
a04e02 |
send_email.return_value = True
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
self.test_request_pull()
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
user = tests.FakeUser()
|
|
farhaanbukhsh |
a04e02 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
a04e02 |
# Repo 'foo' does not exist so it is verifying that condition
|
|
farhaanbukhsh |
a04e02 |
output = self.app.post('/foo/pull-request/1/comment/1/edit')
|
|
farhaanbukhsh |
a04e02 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
# Here no comment is present in the PR so its verifying that condition
|
|
farhaanbukhsh |
a04e02 |
output = self.app.post('/test/pull-request/100/comment/100/edit')
|
|
farhaanbukhsh |
a04e02 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
output = self.app.post('/test/pull-request/1/comment')
|
|
farhaanbukhsh |
a04e02 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
a04e02 |
# Creating comment to play with
|
|
farhaanbukhsh |
a04e02 |
self.assertTrue(
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True).startswith('\n<section class="add_comment">'))</section>
|
|
farhaanbukhsh |
a04e02 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
data = {
|
|
farhaanbukhsh |
a04e02 |
'csrf_token': csrf_token,
|
|
farhaanbukhsh |
a04e02 |
'comment': 'This look alright but we can do better',
|
|
farhaanbukhsh |
a04e02 |
}
|
|
farhaanbukhsh |
a04e02 |
output = self.app.post(
|
|
farhaanbukhsh |
a04e02 |
'/test/pull-request/1/comment', data=data,
|
|
farhaanbukhsh |
a04e02 |
follow_redirects=True)
|
|
farhaanbukhsh |
a04e02 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
a04e02 |
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Pierre-Yves Chibon |
19b2ae |
'\n Comment added',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
a04e02 |
# Check if the comment is there
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'This look alright but we can do better ', output_text)
|
|
farhaanbukhsh |
a04e02 |
output = self.app.get('/test/pull-request/1/comment/1/edit')
|
|
farhaanbukhsh |
a04e02 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
a04e02 |
|
|
Aurélien Bompard |
626417 |
self.assertIn('<section class="edit_comment">', output_text)</section>
|
|
farhaanbukhsh |
a04e02 |
# Checking if the comment is there in the update page
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'This look alright but we can do better', output_text)
|
|
farhaanbukhsh |
a04e02 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
data = {
|
|
farhaanbukhsh |
a04e02 |
'csrf_token': csrf_token,
|
|
farhaanbukhsh |
a04e02 |
'update_comment': 'This look alright but we can do better than this.',
|
|
farhaanbukhsh |
a04e02 |
}
|
|
farhaanbukhsh |
a04e02 |
output = self.app.post(
|
|
farhaanbukhsh |
a04e02 |
'/test/pull-request/1/comment/1/edit', data=data,
|
|
farhaanbukhsh |
a04e02 |
follow_redirects=True)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
a04e02 |
# Checking if the comment is updated in the main page
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'This look alright but we can do better than this. ', output_text)
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Pierre-Yves Chibon |
137f65 |
'PR#1\n'
|
|
Pierre-Yves Chibon |
137f65 |
' PR from the feature branch\n ',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
a04e02 |
# Checking if Edited by User is there or not
|
|
Pierre-Yves Chibon |
cf5986 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
cf5986 |
'<small class="text-muted">Edited just now by pingou </small>'
|
|
Aurélien Bompard |
626417 |
in output_text
|
|
Pierre-Yves Chibon |
cf5986 |
or
|
|
Pierre-Yves Chibon |
cf5986 |
'<small class="text-muted">Edited seconds ago by pingou </small>'
|
|
Aurélien Bompard |
626417 |
in output_text)
|
|
farhaanbukhsh |
a04e02 |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'\n Comment updated', output_text)
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
# Project w/o pull-request
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
farhaanbukhsh |
a04e02 |
settings = repo.settings
|
|
farhaanbukhsh |
a04e02 |
settings['pull_requests'] = False
|
|
farhaanbukhsh |
a04e02 |
repo.settings = settings
|
|
farhaanbukhsh |
a04e02 |
self.session.add(repo)
|
|
farhaanbukhsh |
a04e02 |
self.session.commit()
|
|
farhaanbukhsh |
a04e02 |
|
|
farhaanbukhsh |
a04e02 |
output = self.app.post(
|
|
farhaanbukhsh |
a04e02 |
'/test/pull-request/1/comment/edit/1', data=data,
|
|
farhaanbukhsh |
a04e02 |
follow_redirects=True)
|
|
farhaanbukhsh |
a04e02 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
9347b5 |
|
|
Pierre-Yves Chibon |
edfd4c |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
edfd4c |
def test_merge_request_pull_FF_w_merge_commit(self, send_email):
|
|
Pierre-Yves Chibon |
edfd4c |
""" Test the merge_request_pull endpoint with a FF PR but with a
|
|
Pierre-Yves Chibon |
edfd4c |
merge commit.
|
|
Pierre-Yves Chibon |
edfd4c |
"""
|
|
Pierre-Yves Chibon |
edfd4c |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
self.test_request_pull()
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
edfd4c |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
# No CSRF
|
|
Pierre-Yves Chibon |
edfd4c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
edfd4c |
'/test/pull-request/1/merge', data={}, follow_redirects=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertIn(
|
|
Pierre-Yves Chibon |
edfd4c |
'<title>PR#1: PR from the feature branch - test\n - '</title>
|
|
Aurélien Bompard |
626417 |
'Pagure', output_text)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertIn(
|
|
Pierre-Yves Chibon |
edfd4c |
'PR#1\n'
|
|
Aurélien Bompard |
626417 |
' PR from the feature branch\n', output_text)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'title="View file as of 2a552b">sources', output_text)
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
# Wrong project
|
|
Pierre-Yves Chibon |
edfd4c |
data = {
|
|
Pierre-Yves Chibon |
edfd4c |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
edfd4c |
}
|
|
Pierre-Yves Chibon |
edfd4c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
edfd4c |
'/foobar/pull-request/100/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
# Wrong project
|
|
Pierre-Yves Chibon |
edfd4c |
data = {
|
|
Pierre-Yves Chibon |
edfd4c |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
edfd4c |
}
|
|
Pierre-Yves Chibon |
edfd4c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
edfd4c |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
# Wrong request id
|
|
Pierre-Yves Chibon |
edfd4c |
data = {
|
|
Pierre-Yves Chibon |
edfd4c |
'csrf_token': csrf_token,
|
|
Pierre-Yves Chibon |
edfd4c |
}
|
|
Pierre-Yves Chibon |
edfd4c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
edfd4c |
'/test/pull-request/100/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
# Project requiring a merge commit
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
edfd4c |
settings = repo.settings
|
|
Pierre-Yves Chibon |
edfd4c |
settings['always_merge'] = True
|
|
Pierre-Yves Chibon |
edfd4c |
repo.settings = settings
|
|
Pierre-Yves Chibon |
edfd4c |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
edfd4c |
self.session.commit()
|
|
Pierre-Yves Chibon |
edfd4c |
|
|
Pierre-Yves Chibon |
edfd4c |
# Merge
|
|
Pierre-Yves Chibon |
edfd4c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
edfd4c |
'/test/pull-request/1/merge', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertEqual(output.status_code, 200)
|
|
Ryan Lerch |
6d2e06 |
|
|
Ryan Lerch |
6d2e06 |
output = self.app.get('/test/commits')
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertIn(
|
|
Ryan Lerch |
6d2e06 |
'<title>Commits - test - Pagure</title>', output_text)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'Merge #1 `PR from the feature branch`', output_text)
|
|
Pierre-Yves Chibon |
edfd4c |
self.assertIn(
|
|
Aurélien Bompard |
626417 |
'A commit on branch feature', output_text)
|
|
Ryan Lerch |
6d2e06 |
|
|
Pierre-Yves Chibon |
21dd34 |
# Check if the closing notification was added
|
|
Pierre-Yves Chibon |
21dd34 |
output = self.app.get('/test/pull-request/1')
|
|
Pierre-Yves Chibon |
21dd34 |
self.assertIn(
|
|
Pierre-Yves Chibon |
be62f6 |
'<small>Pull-Request has been merged by pingou </small>',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
21dd34 |
|
|
Farhaan Bukhsh |
3c36a9 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
0add6c |
def test_internal_endpoint_main_ahead(self, send_email):
|
|
Pierre-Yves Chibon |
0add6c |
""" Test the new_request_pull endpoint when the main repo is ahead
|
|
Pierre-Yves Chibon |
0add6c |
of the fork.
|
|
Pierre-Yves Chibon |
0add6c |
"""
|
|
Pierre-Yves Chibon |
0add6c |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
0add6c |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
0add6c |
os.path.join(self.path, 'requests'), bare=True)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
self.set_up_git_repo(
|
|
Pierre-Yves Chibon |
0add6c |
new_project=None,
|
|
Pierre-Yves Chibon |
0add6c |
branch_from='feature')
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
0add6c |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Make the main repo be ahead of the fork
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# First commit
|
|
Pierre-Yves Chibon |
0add6c |
newpath = tempfile.mkdtemp(prefix='pagure-test')
|
|
Pierre-Yves Chibon |
0add6c |
repopath = os.path.join(newpath, 'test')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Create a file in that git repo
|
|
Pierre-Yves Chibon |
0add6c |
with open(os.path.join(repopath, 'testfile'), 'w') as stream:
|
|
Pierre-Yves Chibon |
0add6c |
stream.write('foo\n bar')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.index.add('testfile')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Commits the files added
|
|
Pierre-Yves Chibon |
0add6c |
last_commit = clone_repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
0add6c |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
0add6c |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
0add6c |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
0add6c |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
0add6c |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
0add6c |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
0add6c |
author,
|
|
Pierre-Yves Chibon |
0add6c |
committer,
|
|
Pierre-Yves Chibon |
0add6c |
'Add testfile file for testing',
|
|
Pierre-Yves Chibon |
0add6c |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
0add6c |
tree,
|
|
Pierre-Yves Chibon |
0add6c |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
0add6c |
[last_commit.oid.hex]
|
|
Pierre-Yves Chibon |
0add6c |
)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Second commit
|
|
Pierre-Yves Chibon |
0add6c |
with open(os.path.join(repopath, 'testfile'), 'a') as stream:
|
|
Pierre-Yves Chibon |
0add6c |
stream.write('\nfoo2\n bar2')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.index.add('testfile')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Commits the files added
|
|
Pierre-Yves Chibon |
0add6c |
last_commit = clone_repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
0add6c |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
0add6c |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
0add6c |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
0add6c |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
0add6c |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
0add6c |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
0add6c |
author,
|
|
Pierre-Yves Chibon |
0add6c |
committer,
|
|
Pierre-Yves Chibon |
0add6c |
'Add a second commit to testfile for testing',
|
|
Pierre-Yves Chibon |
0add6c |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
0add6c |
tree,
|
|
Pierre-Yves Chibon |
0add6c |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
0add6c |
[last_commit.oid.hex]
|
|
Pierre-Yves Chibon |
0add6c |
)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Third commit
|
|
Pierre-Yves Chibon |
0add6c |
with open(os.path.join(repopath, 'testfile'), 'a') as stream:
|
|
Pierre-Yves Chibon |
0add6c |
stream.write('\nfoo3\n bar3')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.index.add('testfile')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
# Commits the files added
|
|
Pierre-Yves Chibon |
0add6c |
last_commit = clone_repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
0add6c |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
0add6c |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
0add6c |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
0add6c |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
0add6c |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
0add6c |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
0add6c |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
0add6c |
author,
|
|
Pierre-Yves Chibon |
0add6c |
committer,
|
|
Pierre-Yves Chibon |
0add6c |
'Add a third commit to testfile for testing',
|
|
Pierre-Yves Chibon |
0add6c |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
0add6c |
tree,
|
|
Pierre-Yves Chibon |
0add6c |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
0add6c |
[last_commit.oid.hex]
|
|
Pierre-Yves Chibon |
0add6c |
)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
refname = 'refs/heads/master:refs/heads/master'
|
|
Pierre-Yves Chibon |
0add6c |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
0add6c |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
0add6c |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Aurélien Bompard |
626417 |
csrf_token = self.get_csrf()
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
0add6c |
'/pv/pull-request/ready',
|
|
Pierre-Yves Chibon |
0add6c |
data={'repo': 'test', 'csrf_token': csrf_token}
|
|
Pierre-Yves Chibon |
0add6c |
)
|
|
Pierre-Yves Chibon |
0add6c |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
0add6c |
self.assertEqual(
|
|
Pierre-Yves Chibon |
0add6c |
data,
|
|
Pierre-Yves Chibon |
0add6c |
{
|
|
Pierre-Yves Chibon |
0add6c |
"code": "OK",
|
|
Pierre-Yves Chibon |
0add6c |
"message": {
|
|
Pierre-Yves Chibon |
0add6c |
"branch_w_pr": {
|
|
Pierre-Yves Chibon |
f41f07 |
"feature": "test/pull-request/1"
|
|
Pierre-Yves Chibon |
0add6c |
},
|
|
Pierre-Yves Chibon |
0add6c |
"new_branch": {}
|
|
Pierre-Yves Chibon |
0add6c |
}
|
|
Pierre-Yves Chibon |
0add6c |
}
|
|
Pierre-Yves Chibon |
0add6c |
)
|
|
Pierre-Yves Chibon |
0add6c |
|
|
Pierre-Yves Chibon |
0add6c |
@patch('pagure.lib.notify.send_email')
|
|
Farhaan Bukhsh |
3c36a9 |
def test_fork_edit_file(self, send_email):
|
|
Farhaan Bukhsh |
3c36a9 |
""" Test the fork_edit file endpoint. """
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
send_email.return_value = True
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Pierre-Yves Chibon |
3f60e3 |
# Git repo not found
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.post('fork_edit/test/edit/master/f/sources')
|
|
Pierre-Yves Chibon |
3f60e3 |
self.assertEqual(output.status_code, 404)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
tests.create_projects(self.session)
|
|
Farhaan Bukhsh |
3c36a9 |
for folder in ['docs', 'tickets', 'requests', 'repos']:
|
|
Farhaan Bukhsh |
3c36a9 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, folder), bare=True)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Pierre-Yves Chibon |
3f60e3 |
# User not logged in
|
|
Pierre-Yves Chibon |
3f60e3 |
output = self.app.post('fork_edit/test/edit/master/f/sources')
|
|
Pierre-Yves Chibon |
3f60e3 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
3f60e3 |
|
|
Farhaan Bukhsh |
3c36a9 |
user = tests.FakeUser()
|
|
Farhaan Bukhsh |
3c36a9 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
d90b91 |
# Invalid request
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.post('fork_edit/test/edit/master/f/source')
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertEqual(output.status_code, 400)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.get('/new/')
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Create new Project', output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Pierre-Yves Chibon |
a754ea |
csrf_token = self.get_csrf(output=output)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
data = {
|
|
Farhaan Bukhsh |
3c36a9 |
'csrf_token': csrf_token,
|
|
Farhaan Bukhsh |
3c36a9 |
}
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
d90b91 |
# No files can be found since they are not added
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.post('fork_edit/test/edit/master/f/sources',
|
|
Farhaan Bukhsh |
3c36a9 |
data=data, follow_redirects=True)
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertEqual(output.status_code, 404)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
user = tests.FakeUser()
|
|
Farhaan Bukhsh |
3c36a9 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
data = {
|
|
Farhaan Bukhsh |
3c36a9 |
'csrf_token': csrf_token,
|
|
Farhaan Bukhsh |
3c36a9 |
}
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
d90b91 |
# Invalid request
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.post('fork_edit/test/edit/master/f/sources',
|
|
Farhaan Bukhsh |
3c36a9 |
follow_redirects=True)
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertEqual(output.status_code, 400)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
63c088 |
# Add content to the repo
|
|
Farhaan Bukhsh |
3c36a9 |
tests.add_content_git_repo(os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['GIT_FOLDER'], 'test.git'))
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
tests.add_readme_git_repo(os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['GIT_FOLDER'], 'test.git'))
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
tests.add_binary_git_repo(
|
|
Farhaan Bukhsh |
3c36a9 |
os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['GIT_FOLDER'], 'test.git'), 'test.jpg')
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
63c088 |
# Check if button exists
|
|
Farhaan Bukhsh |
69bc30 |
output = self.app.get('/test/blob/master/f/sources')
|
|
Farhaan Bukhsh |
69bc30 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
69bc30 |
self.assertIn(
|
|
Farhaan Bukhsh |
69bc30 |
'Fork and Edit\n \n',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
63c088 |
|
|
Farhaan Bukhsh |
d90b91 |
# Check fork-edit doesn't show for binary files
|
|
Farhaan Bukhsh |
63c088 |
output = self.app.get('/test/blob/master/f/test.jpg')
|
|
Farhaan Bukhsh |
63c088 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
63c088 |
self.assertNotIn(
|
|
Farhaan Bukhsh |
63c088 |
'Fork and Edit\n \n',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
63c088 |
|
|
Farhaan Bukhsh |
63c088 |
# Check for edit panel
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.post('fork_edit/test/edit/master/f/sources',
|
|
Farhaan Bukhsh |
3c36a9 |
data=data, follow_redirects=True)
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertIn(
|
|
Farhaan Bukhsh |
3c36a9 |
''
|
|
Ryan Lerch |
6d2e06 |
' master'
|
|
Ryan Lerch |
6d2e06 |
''
|
|
Farhaan Bukhsh |
3c36a9 |
' sources',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertIn(
|
|
Farhaan Bukhsh |
3c36a9 |
'<textarea id="textareaCode" name="content">foo\n bar</textarea>',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Farhaan Bukhsh |
3c36a9 |
|
|
Farhaan Bukhsh |
3c36a9 |
# View what's supposed to be an image
|
|
Farhaan Bukhsh |
3c36a9 |
output = self.app.post('fork_edit/test/edit/master/f/test.jpg',
|
|
Farhaan Bukhsh |
3c36a9 |
data=data, follow_redirects=True)
|
|
Farhaan Bukhsh |
3c36a9 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
self.assertIn('Cannot edit binary files ', output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e64141 |
|
|
Farhaan Bukhsh |
d90b91 |
# Check fork-edit shows when user is not logged in
|
|
Farhaan Bukhsh |
d90b91 |
output = self.app.get('/test/blob/master/f/sources')
|
|
Farhaan Bukhsh |
d90b91 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
d90b91 |
self.assertIn(
|
|
Farhaan Bukhsh |
d90b91 |
'Fork and Edit\n \n',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
d90b91 |
|
|
Farhaan Bukhsh |
d90b91 |
# Check if fork-edit shows for different user
|
|
Farhaan Bukhsh |
d90b91 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
d90b91 |
|
|
Farhaan Bukhsh |
d90b91 |
# Check if button exists
|
|
Farhaan Bukhsh |
d90b91 |
output = self.app.get('/test/blob/master/f/sources')
|
|
Farhaan Bukhsh |
d90b91 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
d90b91 |
self.assertIn(
|
|
Pierre-Yves Chibon |
025aab |
'Edit in your fork\n \n',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
d90b91 |
|
|
Farhaan Bukhsh |
d90b91 |
# Check fork-edit doesn't show for binary
|
|
Farhaan Bukhsh |
d90b91 |
output = self.app.get('/test/blob/master/f/test.jpg')
|
|
Farhaan Bukhsh |
d90b91 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
d90b91 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
025aab |
'Edit in your fork\n \n',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
d90b91 |
|
|
Farhaan Bukhsh |
7fedd0 |
@patch('pagure.lib.notify.send_email')
|
|
Farhaan Bukhsh |
7fedd0 |
def test_fork_without_main_repo(self, send_email):
|
|
Farhaan Bukhsh |
7fedd0 |
""" Test the fork without the main repo. """
|
|
Farhaan Bukhsh |
7fedd0 |
send_email.return_value = True
|
|
Farhaan Bukhsh |
7fedd0 |
|
|
Farhaan Bukhsh |
7fedd0 |
tests.create_projects(self.session)
|
|
Farhaan Bukhsh |
6279ea |
|
|
Farhaan Bukhsh |
6279ea |
# Create a fork with no parent i.e parent_id = None
|
|
Farhaan Bukhsh |
7fedd0 |
item = pagure.lib.model.Project(
|
|
Farhaan Bukhsh |
7fedd0 |
user_id=2, # foo
|
|
Farhaan Bukhsh |
7fedd0 |
name='test',
|
|
Farhaan Bukhsh |
7fedd0 |
description='test project #1',
|
|
Farhaan Bukhsh |
7fedd0 |
hook_token='aaabbb',
|
|
Farhaan Bukhsh |
7fedd0 |
is_fork=True,
|
|
Farhaan Bukhsh |
6279ea |
parent_id=None,
|
|
Farhaan Bukhsh |
7fedd0 |
)
|
|
Farhaan Bukhsh |
7fedd0 |
self.session.add(item)
|
|
Farhaan Bukhsh |
7fedd0 |
self.session.commit()
|
|
Farhaan Bukhsh |
7fedd0 |
|
|
Farhaan Bukhsh |
6279ea |
# Get fork project
|
|
Farhaan Bukhsh |
83f8bc |
project = pagure.lib._get_project(self.session, 'test', 'foo')
|
|
Farhaan Bukhsh |
6279ea |
|
|
Farhaan Bukhsh |
6279ea |
# Pull-requests and issue-trackers are off for forks
|
|
Farhaan Bukhsh |
6279ea |
# lib function is not used here so mannually turning them off
|
|
Farhaan Bukhsh |
6279ea |
project_settings = project.settings
|
|
Farhaan Bukhsh |
6279ea |
project_settings['pull_requests'] = False
|
|
Farhaan Bukhsh |
6279ea |
project_settings['issue_tracker'] = False
|
|
Farhaan Bukhsh |
6279ea |
project.settings = project_settings
|
|
Farhaan Bukhsh |
6279ea |
self.session.add(project)
|
|
Farhaan Bukhsh |
6279ea |
self.session.commit()
|
|
Farhaan Bukhsh |
6279ea |
|
|
Farhaan Bukhsh |
7fedd0 |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'repos', 'forks', 'foo'), bare=True)
|
|
Farhaan Bukhsh |
7fedd0 |
|
|
Farhaan Bukhsh |
7fedd0 |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Farhaan Bukhsh |
7fedd0 |
self.assertFalse(os.path.exists(gitrepo))
|
|
Farhaan Bukhsh |
7fedd0 |
os.makedirs(gitrepo)
|
|
Farhaan Bukhsh |
7fedd0 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Farhaan Bukhsh |
7fedd0 |
|
|
Farhaan Bukhsh |
7fedd0 |
# Create a fork of this repo
|
|
Farhaan Bukhsh |
7fedd0 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'forks', 'foo', 'test.git')
|
|
Farhaan Bukhsh |
7fedd0 |
new_repo = pygit2.clone_repository(gitrepo, newpath)
|
|
Farhaan Bukhsh |
7fedd0 |
tests.add_content_git_repo(gitrepo)
|
|
Farhaan Bukhsh |
7fedd0 |
|
|
Farhaan Bukhsh |
7fedd0 |
# UI test for deleted main
|
|
Farhaan Bukhsh |
7fedd0 |
output = self.app.get('/fork/foo/test')
|
|
Farhaan Bukhsh |
7fedd0 |
self.assertEqual(output.status_code, 200)
|
|
Ryan Lerch |
6d2e06 |
self.assertIn('Forked from a deleted repository', output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
7fedd0 |
|
|
Farhaan Bukhsh |
7fedd0 |
# Testing commit endpoint
|
|
Farhaan Bukhsh |
7fedd0 |
output = self.app.get('/fork/foo/test/commits/master')
|
|
Farhaan Bukhsh |
7fedd0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
self.assertIn(
|
|
Ryan Lerch |
6d2e06 |
'Commits 2\n',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
6279ea |
|
|
Farhaan Bukhsh |
6279ea |
# Test pull-request endpoint
|
|
Farhaan Bukhsh |
6279ea |
output = self.app.get('/fork/foo/test/pull-requests')
|
|
Farhaan Bukhsh |
6279ea |
self.assertEqual(output.status_code, 404)
|
|
Farhaan Bukhsh |
6279ea |
|
|
Farhaan Bukhsh |
6279ea |
# Test issue-tracker endpoint
|
|
Farhaan Bukhsh |
6279ea |
output = self.app.get('/fork/foo/test/issues')
|
|
Farhaan Bukhsh |
6279ea |
self.assertEqual(output.status_code, 404)
|
|
Farhaan Bukhsh |
6279ea |
|
|
Farhaan Bukhsh |
7fedd0 |
shutil.rmtree(newpath)
|
|
Farhaan Bukhsh |
d90b91 |
|
|
Pierre-Yves Chibon |
9347b5 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|