|
farhaanbukhsh |
1df65f |
# -*- coding: utf-8 -*-
|
|
farhaanbukhsh |
1df65f |
|
|
Aurélien Bompard |
626417 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
626417 |
|
|
farhaanbukhsh |
1df65f |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
farhaanbukhsh |
1df65f |
import pkg_resources
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
60d445 |
import datetime
|
|
farhaanbukhsh |
1df65f |
import unittest
|
|
farhaanbukhsh |
1df65f |
import shutil
|
|
farhaanbukhsh |
1df65f |
import sys
|
|
farhaanbukhsh |
c4f329 |
import tempfile
|
|
farhaanbukhsh |
1df65f |
import os
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
import json
|
|
farhaanbukhsh |
c4f329 |
import pygit2
|
|
Aurélien Bompard |
626417 |
from mock import patch, MagicMock
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
farhaanbukhsh |
1df65f |
os.path.abspath(__file__)), '..'))
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
import pagure.lib
|
|
farhaanbukhsh |
1df65f |
import tests
|
|
farhaanbukhsh |
c4f329 |
from pagure.lib.repo import PagureRepo
|
|
farhaanbukhsh |
1df65f |
|
|
Farhaan Bukhsh |
8aa0f5 |
FULL_ISSUE_LIST = [
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "We should work on this",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 8,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": True,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "Test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 7,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": True,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 6,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": True,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 5,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 4,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 3,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 2,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"assignee": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"blocks": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"close_status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"comments": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8aa0f5 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"depends": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"id": 1,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"private": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"status": "Open",
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8aa0f5 |
"user": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8aa0f5 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
]
|
|
Farhaan Bukhsh |
8aa0f5 |
|
|
farhaanbukhsh |
753ee7 |
|
|
farhaanbukhsh |
1df65f |
class PagurePrivateRepotest(tests.Modeltests):
|
|
farhaanbukhsh |
1df65f |
""" Tests for private repo in pagure """
|
|
farhaanbukhsh |
1df65f |
|
|
Pierre-Yves Chibon |
2521db |
maxDiff = None
|
|
Pierre-Yves Chibon |
2521db |
|
|
farhaanbukhsh |
1df65f |
def setUp(self):
|
|
farhaanbukhsh |
1df65f |
""" Set up the environnment, ran before every tests. """
|
|
farhaanbukhsh |
1df65f |
super(PagurePrivateRepotest, self).setUp()
|
|
farhaanbukhsh |
1df65f |
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['DATAGREPPER_URL'] = None
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['PRIVATE_PROJECTS'] = True
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['VIRUS_SCAN_ATTACHMENTS'] = False
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
c4f329 |
def set_up_git_repo(
|
|
farhaanbukhsh |
c4f329 |
self, new_project=None, branch_from='feature', mtype='FF'):
|
|
farhaanbukhsh |
c4f329 |
""" Set up the git repo and create the corresponding PullRequest
|
|
farhaanbukhsh |
c4f329 |
object.
|
|
farhaanbukhsh |
c4f329 |
"""
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Create a git repo to play with
|
|
Patrick Uiterwijk |
170974 |
gitrepo = os.path.join(self.path, 'repos', 'pmc.git')
|
|
farhaanbukhsh |
c4f329 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
4ea512 |
newpath = tempfile.mkdtemp(prefix='pagure-private-test')
|
|
farhaanbukhsh |
4858f8 |
repopath = os.path.join(newpath, 'test')
|
|
farhaanbukhsh |
c4f329 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Create a file in that git repo
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('foo\n bar')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.add('sources')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/master', # the name of the reference to update
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'Add sources file for testing',
|
|
farhaanbukhsh |
c4f329 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
c4f329 |
[]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
c4f329 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
first_commit = repo.revparse_single('HEAD')
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
if mtype == 'merge':
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('*~')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.add('.gitignore')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Äuthòr', 'alice@äuthòrs.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Cõmmîttër', 'cecil@cõmmîttërs.tld')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/master',
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'Add .gitignore file for testing',
|
|
farhaanbukhsh |
c4f329 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
c4f329 |
[first_commit.oid.hex]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
c4f329 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
if mtype == 'conflicts':
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('foo\n bar\nbaz')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.add('sources')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
c4f329 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/master',
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'Add sources conflicting',
|
|
farhaanbukhsh |
c4f329 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
c4f329 |
[first_commit.oid.hex]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
c4f329 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Set the second repo
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
new_gitrepo = repopath
|
|
farhaanbukhsh |
c4f329 |
if new_project:
|
|
farhaanbukhsh |
c4f329 |
# Create a new git repo to play with
|
|
farhaanbukhsh |
c4f329 |
new_gitrepo = os.path.join(newpath, new_project.fullname)
|
|
farhaanbukhsh |
c4f329 |
if not os.path.exists(new_gitrepo):
|
|
farhaanbukhsh |
c4f329 |
os.makedirs(new_gitrepo)
|
|
farhaanbukhsh |
c4f329 |
new_repo = pygit2.clone_repository(gitrepo, new_gitrepo)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
repo = pygit2.Repository(new_gitrepo)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
if mtype != 'nochanges':
|
|
farhaanbukhsh |
c4f329 |
# Edit the sources file again
|
|
farhaanbukhsh |
c4f329 |
with open(os.path.join(new_gitrepo, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
c4f329 |
stream.write('foo\n bar\nbaz\n boose')
|
|
farhaanbukhsh |
c4f329 |
repo.index.add('sources')
|
|
farhaanbukhsh |
c4f329 |
repo.index.write()
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Commits the files added
|
|
farhaanbukhsh |
c4f329 |
tree = repo.index.write_tree()
|
|
farhaanbukhsh |
c4f329 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
c4f329 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
c4f329 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
c4f329 |
repo.create_commit(
|
|
farhaanbukhsh |
c4f329 |
'refs/heads/%s' % branch_from,
|
|
farhaanbukhsh |
c4f329 |
author,
|
|
farhaanbukhsh |
c4f329 |
committer,
|
|
farhaanbukhsh |
c4f329 |
'A commit on branch %s' % branch_from,
|
|
farhaanbukhsh |
c4f329 |
tree,
|
|
farhaanbukhsh |
c4f329 |
[first_commit.oid.hex]
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
refname = 'refs/heads/%s' % (branch_from)
|
|
farhaanbukhsh |
c4f329 |
ori_remote = repo.remotes[0]
|
|
farhaanbukhsh |
c4f329 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Create a PR for these changes
|
|
Farhaan Bukhsh |
839011 |
project = pagure.lib._get_project(self.session, 'pmc')
|
|
farhaanbukhsh |
c4f329 |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
c4f329 |
session=self.session,
|
|
farhaanbukhsh |
c4f329 |
repo_from=project,
|
|
farhaanbukhsh |
c4f329 |
branch_from=branch_from,
|
|
farhaanbukhsh |
c4f329 |
repo_to=project,
|
|
farhaanbukhsh |
c4f329 |
branch_to='master',
|
|
farhaanbukhsh |
c4f329 |
title='PR from the %s branch' % branch_from,
|
|
farhaanbukhsh |
c4f329 |
user='pingou',
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
self.session.commit()
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(req.title, 'PR from the %s branch' % branch_from)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
shutil.rmtree(newpath)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
1df65f |
def test_index(self):
|
|
farhaanbukhsh |
1df65f |
""" Test the index endpoint. """
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
output = self.app.get('/')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
b1ec6e |
'All Projects '
|
|
Pierre-Yves Chibon |
b1ec6e |
'0',
|
|
Aurélien Bompard |
626417 |
output.get_data(as_text=True))
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a private project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test3',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeee',
|
|
farhaanbukhsh |
1df65f |
private=True,
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a public project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test4',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeeeccceee',
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
self.session.commit()
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
output = self.app.get('/?page=abc')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
b1ec6e |
'All Projects '
|
|
Pierre-Yves Chibon |
b1ec6e |
'1',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
user = tests.FakeUser(username='foo')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Ryan Lerch |
336cd6 |
output = self.app.get('/', follow_redirects=True)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Ryan Lerch |
336cd6 |
'My Projects',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
Pierre-Yves Chibon |
837e8c |
self.assertIn('2 Projects', output_text)
|
|
Ryan Lerch |
336cd6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
837e8c |
'Forks', output_text)
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(
|
|
Ryan Lerch |
336cd6 |
output_text.count('Groups'), 0)
|
|
Ryan Lerch |
336cd6 |
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
def test_view_user(self):
|
|
farhaanbukhsh |
1df65f |
""" Test the view_user endpoint. """
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
output = self.app.get('/user/foo?repopage=abc&forkpage=def')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
75b0c3 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
75b0c3 |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Projects
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
75b0c3 |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Forks
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
Pierre-Yves Chibon |
75b0c3 |
self.assertIn(
|
|
Pierre-Yves Chibon |
75b0c3 |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Groups
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a private project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test3',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeee',
|
|
farhaanbukhsh |
1df65f |
private=True,
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
# Add a public project
|
|
farhaanbukhsh |
1df65f |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
1df65f |
user_id=2, # foo
|
|
farhaanbukhsh |
1df65f |
name='test4',
|
|
farhaanbukhsh |
1df65f |
description='test project description',
|
|
farhaanbukhsh |
1df65f |
hook_token='aaabbbeeeccceee',
|
|
farhaanbukhsh |
1df65f |
)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.session.add(item)
|
|
farhaanbukhsh |
1df65f |
self.session.commit()
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
self.gitrepos = tests.create_projects_git(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['GIT_FOLDER'])
|
|
farhaanbukhsh |
1df65f |
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/user/foo')
|
|
farhaanbukhsh |
1df65f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
75b0c3 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
75b0c3 |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Projects
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
1
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
75b0c3 |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Forks
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
Pierre-Yves Chibon |
75b0c3 |
self.assertIn(
|
|
Pierre-Yves Chibon |
75b0c3 |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Groups
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
1df65f |
user = tests.FakeUser(username='foo')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/user/foo')
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Projects
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
1
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Forks
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
Pierre-Yves Chibon |
f0babf |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Groups
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
b909de |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3604c1 |
output = self.app.get('/user/foo')
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Projects
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
1
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Forks
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
Pierre-Yves Chibon |
f0babf |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Groups
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output_text)
|
|
farhaanbukhsh |
1df65f |
|
|
farhaanbukhsh |
d59922 |
# Check pingou has 0 projects
|
|
farhaanbukhsh |
d59922 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Ryan Lerch |
336cd6 |
output = self.app.get('/', follow_redirects=True)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
d59922 |
self.assertIn(
|
|
Ryan Lerch |
336cd6 |
'My Projects',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
d59922 |
self.assertIn(
|
|
Pierre-Yves Chibon |
837e8c |
'0 Projects',
|
|
Ryan Lerch |
336cd6 |
output_text)
|
|
Ryan Lerch |
336cd6 |
self.assertNotIn(
|
|
Ryan Lerch |
336cd6 |
'Forks',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
d59922 |
self.assertEqual(
|
|
Ryan Lerch |
336cd6 |
output_text.count('Groups'), 0)
|
|
farhaanbukhsh |
d59922 |
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test3')
|
|
farhaanbukhsh |
b909de |
|
|
farhaanbukhsh |
b909de |
msg = pagure.lib.add_user_to_project(
|
|
farhaanbukhsh |
b6711e |
session=self.session,
|
|
farhaanbukhsh |
b6711e |
project=repo,
|
|
farhaanbukhsh |
b6711e |
new_user='pingou',
|
|
farhaanbukhsh |
b6711e |
user='foo',
|
|
farhaanbukhsh |
b6711e |
)
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
farhaanbukhsh |
b909de |
self.assertEqual(msg, 'User added')
|
|
farhaanbukhsh |
b6711e |
|
|
farhaanbukhsh |
b6711e |
# New user added to private projects
|
|
farhaanbukhsh |
b909de |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Ryan Lerch |
336cd6 |
output = self.app.get('/', follow_redirects=True)
|
|
Aurélien Bompard |
626417 |
output_text = output.get_data(as_text=True)
|
|
farhaanbukhsh |
b6711e |
self.assertIn(
|
|
Ryan Lerch |
336cd6 |
'My Projects',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
b6711e |
self.assertIn(
|
|
Pierre-Yves Chibon |
837e8c |
'1 Projects',
|
|
Ryan Lerch |
336cd6 |
output_text)
|
|
Ryan Lerch |
336cd6 |
self.assertNotIn(
|
|
Ryan Lerch |
336cd6 |
'Forks',
|
|
Aurélien Bompard |
626417 |
output_text)
|
|
farhaanbukhsh |
b6711e |
self.assertEqual(
|
|
Ryan Lerch |
336cd6 |
output_text.count('Groups'), 0)
|
|
farhaanbukhsh |
b6711e |
|
|
Clement Verna |
afe475 |
@patch('pagure.decorators.admin_session_timedout')
|
|
farhaanbukhsh |
c4f329 |
def test_private_settings_ui(self, ast):
|
|
farhaanbukhsh |
c4f329 |
""" Test UI for private repo"""
|
|
Pierre-Yves Chibon |
52565d |
ast.return_value = False
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
b909de |
# Add private repo
|
|
farhaanbukhsh |
0163a1 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
0163a1 |
user_id=1, # pingou
|
|
farhaanbukhsh |
0163a1 |
name='test4',
|
|
farhaanbukhsh |
0163a1 |
description='test project description',
|
|
farhaanbukhsh |
0163a1 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
0163a1 |
private=True,
|
|
farhaanbukhsh |
0163a1 |
)
|
|
farhaanbukhsh |
0163a1 |
self.session.add(item)
|
|
farhaanbukhsh |
0163a1 |
self.session.commit()
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
0163a1 |
# Add a git repo
|
|
farhaanbukhsh |
b909de |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get('GIT_FOLDER'), 'test4.git')
|
|
farhaanbukhsh |
0163a1 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
0163a1 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
0163a1 |
pygit2.init_repository(repo_path)
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
c4f329 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b130e5 |
tests.create_projects_git(pagure.config.config.get('GIT_FOLDER'))
|
|
farhaanbukhsh |
c4f329 |
|
|
Pierre-Yves Chibon |
52565d |
output = self.app.get('/test/settings')
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
0163a1 |
# Check for a public repo
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
52565d |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
52565d |
'
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
farhaanbukhsh |
c4f329 |
|
|
Pierre-Yves Chibon |
52565d |
output = self.app.get('/test4/settings')
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
0163a1 |
# Check for private repo
|
|
farhaanbukhsh |
0163a1 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
0163a1 |
self.assertIn(
|
|
Pierre-Yves Chibon |
bdcc9e |
'<input checked="" name="private" type="checkbox" value="private">',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
fc046c |
# Check the new project form has 'private' checkbox
|
|
farhaanbukhsh |
fc046c |
output = self.app.get('/new')
|
|
farhaanbukhsh |
fc046c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
fc046c |
self.assertIn(
|
|
Pierre-Yves Chibon |
52565d |
'<input id="private" name="private" type="checkbox" value="y">',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
|
|
Clement Verna |
afe475 |
@patch('pagure.decorators.admin_session_timedout')
|
|
Pierre-Yves Chibon |
52565d |
def test_private_settings_ui_update_privacy_false(self, ast):
|
|
Pierre-Yves Chibon |
52565d |
""" Test UI for private repo"""
|
|
Pierre-Yves Chibon |
52565d |
ast.return_value = False
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Add private repo
|
|
Pierre-Yves Chibon |
52565d |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
52565d |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
52565d |
name='test4',
|
|
Pierre-Yves Chibon |
52565d |
description='test project description',
|
|
Pierre-Yves Chibon |
52565d |
hook_token='aaabbbeeeceee',
|
|
Pierre-Yves Chibon |
52565d |
private=True,
|
|
Pierre-Yves Chibon |
52565d |
)
|
|
Pierre-Yves Chibon |
52565d |
self.session.add(item)
|
|
Pierre-Yves Chibon |
52565d |
self.session.commit()
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Add a git repo
|
|
Pierre-Yves Chibon |
52565d |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get('GIT_FOLDER'), 'test4.git')
|
|
Pierre-Yves Chibon |
52565d |
pygit2.init_repository(repo_path)
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Check for private repo
|
|
Pierre-Yves Chibon |
52565d |
output = self.app.get('/test4/settings')
|
|
Pierre-Yves Chibon |
52565d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
52565d |
self.assertIn(
|
|
Pierre-Yves Chibon |
bdcc9e |
'<input checked="" name="private" type="checkbox" value="private">',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
52565d |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Pierre-Yves Chibon |
52565d |
self.assertTrue(repo.private)
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Make the project public
|
|
Pierre-Yves Chibon |
52565d |
data = {
|
|
Pierre-Yves Chibon |
52565d |
'description': 'test project description',
|
|
Pierre-Yves Chibon |
52565d |
'private': False,
|
|
Pierre-Yves Chibon |
52565d |
'csrf_token': self.get_csrf(),
|
|
Pierre-Yves Chibon |
52565d |
}
|
|
Pierre-Yves Chibon |
52565d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
52565d |
'/test4/update', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
52565d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
52565d |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Project updated',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
bdcc9e |
'<input checked="" name="private" type="checkbox" value="private">',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
52565d |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Pierre-Yves Chibon |
52565d |
self.assertFalse(repo.private)
|
|
Pierre-Yves Chibon |
52565d |
|
|
Clement Verna |
afe475 |
@patch('pagure.decorators.admin_session_timedout')
|
|
Pierre-Yves Chibon |
52565d |
def test_private_settings_ui_update_privacy_true(self, ast):
|
|
Pierre-Yves Chibon |
52565d |
""" Test UI for private repo"""
|
|
Pierre-Yves Chibon |
52565d |
ast.return_value = False
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Add private repo
|
|
Pierre-Yves Chibon |
52565d |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
52565d |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
52565d |
name='test4',
|
|
Pierre-Yves Chibon |
52565d |
description='test project description',
|
|
Pierre-Yves Chibon |
52565d |
hook_token='aaabbbeeeceee',
|
|
Pierre-Yves Chibon |
52565d |
private=False,
|
|
Pierre-Yves Chibon |
52565d |
)
|
|
Pierre-Yves Chibon |
52565d |
self.session.add(item)
|
|
Pierre-Yves Chibon |
52565d |
self.session.commit()
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Add a git repo
|
|
Pierre-Yves Chibon |
52565d |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get('GIT_FOLDER'), 'test4.git')
|
|
Pierre-Yves Chibon |
52565d |
pygit2.init_repository(repo_path)
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Check for public repo
|
|
Pierre-Yves Chibon |
52565d |
output = self.app.get('/test4/settings')
|
|
Pierre-Yves Chibon |
52565d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
52565d |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
52565d |
'<input checked="" name="private" type="checkbox" value="private">',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
52565d |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Pierre-Yves Chibon |
52565d |
self.assertFalse(repo.private)
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# Make the project private
|
|
Pierre-Yves Chibon |
52565d |
data = {
|
|
Pierre-Yves Chibon |
52565d |
'description': 'test project description',
|
|
Pierre-Yves Chibon |
52565d |
'private': True,
|
|
Pierre-Yves Chibon |
52565d |
'csrf_token': self.get_csrf(),
|
|
Pierre-Yves Chibon |
52565d |
}
|
|
Pierre-Yves Chibon |
52565d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
52565d |
'/test4/update', data=data, follow_redirects=True)
|
|
Pierre-Yves Chibon |
52565d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
52565d |
self.assertIn(
|
|
Ryan Lerch |
90916a |
'Project updated',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
52565d |
'<input checked="" name="private" type="checkbox" value="private">',
|
|
Pierre-Yves Chibon |
52565d |
output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
52565d |
|
|
Pierre-Yves Chibon |
52565d |
# No change since we can't do public -> private
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
52565d |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Pierre-Yves Chibon |
52565d |
self.assertFalse(repo.private)
|
|
farhaanbukhsh |
0163a1 |
|
|
farhaanbukhsh |
4ea512 |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
4ea512 |
def test_private_pr(self, send_email):
|
|
farhaanbukhsh |
c4f329 |
"""Test pull request made to the private repo"""
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
4ea512 |
send_email.return_value = True
|
|
farhaanbukhsh |
c4f329 |
# Add a private project
|
|
farhaanbukhsh |
c4f329 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
c4f329 |
user_id=1, # pingou
|
|
farhaanbukhsh |
c4f329 |
name='pmc',
|
|
farhaanbukhsh |
c4f329 |
description='test project description',
|
|
farhaanbukhsh |
c4f329 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
c4f329 |
private=True,
|
|
farhaanbukhsh |
c4f329 |
)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
self.session.add(item)
|
|
farhaanbukhsh |
c4f329 |
self.session.commit()
|
|
farhaanbukhsh |
c4f329 |
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'pmc')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
msg = pagure.lib.add_user_to_project(
|
|
farhaanbukhsh |
f889f7 |
session=self.session,
|
|
farhaanbukhsh |
f889f7 |
project=repo,
|
|
farhaanbukhsh |
f889f7 |
new_user='foo',
|
|
farhaanbukhsh |
f889f7 |
user='pingou',
|
|
farhaanbukhsh |
f889f7 |
)
|
|
farhaanbukhsh |
f889f7 |
self.session.commit()
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(msg, 'User added')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
c4f329 |
# Create all the git repos
|
|
farhaanbukhsh |
c4f329 |
tests.create_projects_git(
|
|
Farhaan Bukhsh |
02f421 |
os.path.join(self.path, 'requests'), bare=True)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
1432c1 |
# Add a git repo
|
|
farhaanbukhsh |
b909de |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get('REQUESTS_FOLDER'), 'pmc.git')
|
|
farhaanbukhsh |
1432c1 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
1432c1 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
1432c1 |
pygit2.init_repository(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
f0babf |
# Check repo was created - Doesn't show on the public page
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/user/pingou/')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Projects
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0babf |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Forks
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
0
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0babf |
|
|
Pierre-Yves Chibon |
f0babf |
# Shows on the front page
|
|
Pierre-Yves Chibon |
f0babf |
output = self.app.get('/dashboard/projects')
|
|
Pierre-Yves Chibon |
f0babf |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
self.assertIn(
|
|
Pierre-Yves Chibon |
f0babf |
"""
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
Projects
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
1
|
|
Pierre-Yves Chibon |
75b0c3 |
|
|
Pierre-Yves Chibon |
75b0c3 |
""", output.get_data(as_text=True))
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
self.set_up_git_repo(new_project=None, branch_from='feature')
|
|
Farhaan Bukhsh |
839011 |
project = pagure.lib._get_project(self.session, 'pmc')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(len(project.requests), 1)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/pmc/pull-request/1')
|
|
farhaanbukhsh |
c4f329 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
# Check repo was created
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/pmc/pull-requests')
|
|
farhaanbukhsh |
e9261e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
c4f329 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
c4f329 |
output = self.app.get('/pmc/pull-requests')
|
|
farhaanbukhsh |
1432c1 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c4f329 |
|
|
farhaanbukhsh |
f889f7 |
user = tests.FakeUser(username='foo')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
f889f7 |
output = self.app.get('/pmc/pull-requests')
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
420a97 |
@patch('pagure.lib.git.update_git')
|
|
farhaanbukhsh |
420a97 |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
420a97 |
def test_private_repo_issues_ui(self, p_send_email, p_ugt):
|
|
farhaanbukhsh |
420a97 |
""" Test issues made to private repo"""
|
|
farhaanbukhsh |
420a97 |
p_send_email.return_value = True
|
|
farhaanbukhsh |
420a97 |
p_ugt.return_value = True
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Add private repo
|
|
farhaanbukhsh |
420a97 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
420a97 |
user_id=1, # pingou
|
|
farhaanbukhsh |
420a97 |
name='test4',
|
|
farhaanbukhsh |
420a97 |
description='test project description',
|
|
farhaanbukhsh |
420a97 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
420a97 |
private=True,
|
|
farhaanbukhsh |
420a97 |
)
|
|
farhaanbukhsh |
420a97 |
self.session.add(item)
|
|
farhaanbukhsh |
420a97 |
self.session.commit()
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
d59922 |
for repo in ['GIT_FOLDER', 'TICKETS_FOLDER']:
|
|
farhaanbukhsh |
d59922 |
# Add a git repo
|
|
farhaanbukhsh |
d59922 |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get(repo), 'test4.git')
|
|
farhaanbukhsh |
d59922 |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
d59922 |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
d59922 |
pygit2.init_repository(repo_path)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
44a97a |
# Check if the private repo issues are publicly not accesible
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
e9261e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Create issues to play with
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
420a97 |
msg = pagure.lib.new_issue(
|
|
farhaanbukhsh |
420a97 |
session=self.session,
|
|
farhaanbukhsh |
420a97 |
repo=repo,
|
|
farhaanbukhsh |
420a97 |
title='Test issue',
|
|
farhaanbukhsh |
420a97 |
content='We should work on this',
|
|
farhaanbukhsh |
420a97 |
user='pingou',
|
|
farhaanbukhsh |
420a97 |
)
|
|
farhaanbukhsh |
420a97 |
self.session.commit()
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(msg.title, 'Test issue')
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Whole list
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
e9261e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Check single issue
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issue/1')
|
|
farhaanbukhsh |
e9261e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
44a97a |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
44a97a |
# Whole list
|
|
farhaanbukhsh |
44a97a |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
44a97a |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
420a97 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Whole list
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
d59922 |
self.assertIn(
|
|
farhaanbukhsh |
c87985 |
'<title>Issues - test4 - Pagure</title>', output.get_data(as_text=True))
|
|
farhaanbukhsh |
420a97 |
self.assertTrue(
|
|
Ryan Lerch |
5483e2 |
' 1 Open Issues\n' in output.get_data(as_text=True))
|
|
farhaanbukhsh |
420a97 |
|
|
farhaanbukhsh |
420a97 |
# Check single issue
|
|
farhaanbukhsh |
420a97 |
output = self.app.get('/test4/issue/1')
|
|
farhaanbukhsh |
420a97 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
420a97 |
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
msg = pagure.lib.add_user_to_project(
|
|
farhaanbukhsh |
f889f7 |
session=self.session,
|
|
farhaanbukhsh |
f889f7 |
project=repo,
|
|
farhaanbukhsh |
f889f7 |
new_user='foo',
|
|
farhaanbukhsh |
f889f7 |
user='pingou',
|
|
farhaanbukhsh |
f889f7 |
)
|
|
farhaanbukhsh |
f889f7 |
self.session.commit()
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(msg, 'User added')
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
d59922 |
user.username = 'foo'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
# Whole list
|
|
farhaanbukhsh |
f889f7 |
output = self.app.get('/test4/issues')
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
d59922 |
self.assertIn(
|
|
farhaanbukhsh |
c87985 |
'<title>Issues - test4 - Pagure</title>', output.get_data(as_text=True))
|
|
farhaanbukhsh |
f889f7 |
self.assertTrue(
|
|
Ryan Lerch |
5483e2 |
' 1 Open Issues\n' in output.get_data(as_text=True))
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
f889f7 |
# Check single issue
|
|
farhaanbukhsh |
f889f7 |
output = self.app.get('/test4/issue/1')
|
|
farhaanbukhsh |
f889f7 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
@patch('pagure.decorators.admin_session_timedout')
|
|
Farhaan Bukhsh |
c03c25 |
def test_private_repo_ui_for_different_repo_user(self, ast):
|
|
Farhaan Bukhsh |
c03c25 |
""" Test the private repo for different ACLS"""
|
|
Farhaan Bukhsh |
c03c25 |
ast.return_value = False
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Add private repo
|
|
Farhaan Bukhsh |
c03c25 |
item = pagure.lib.model.Project(
|
|
Farhaan Bukhsh |
c03c25 |
user_id=1, # pingou
|
|
Farhaan Bukhsh |
c03c25 |
name='test4',
|
|
Farhaan Bukhsh |
c03c25 |
description='test project description',
|
|
Farhaan Bukhsh |
c03c25 |
hook_token='aaabbbeeeceee',
|
|
Farhaan Bukhsh |
c03c25 |
private=True,
|
|
Farhaan Bukhsh |
c03c25 |
)
|
|
Farhaan Bukhsh |
c03c25 |
self.session.add(item)
|
|
Farhaan Bukhsh |
c03c25 |
self.session.commit()
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
repo = pagure.lib._get_project(self.session, "test4")
|
|
Farhaan Bukhsh |
c03c25 |
# Add a git repo
|
|
Farhaan Bukhsh |
c03c25 |
repo_path = os.path.join(
|
|
Farhaan Bukhsh |
c03c25 |
pagure.config.config.get('GIT_FOLDER'), 'test4.git')
|
|
Farhaan Bukhsh |
c03c25 |
pygit2.init_repository(repo_path)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
user = tests.FakeUser(username='pingou')
|
|
Farhaan Bukhsh |
c03c25 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Check for private repo
|
|
Farhaan Bukhsh |
c03c25 |
output = self.app.get('/test4')
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Check if the user who doesn't have access to private repo can access it
|
|
Farhaan Bukhsh |
c03c25 |
user = tests.FakeUser(username="foo")
|
|
Farhaan Bukhsh |
c03c25 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
output = self.app.get('/test4')
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(output.status_code, 404)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Add commit access to a user
|
|
Farhaan Bukhsh |
c03c25 |
pagure.lib.add_user_to_project(
|
|
Farhaan Bukhsh |
c03c25 |
self.session,
|
|
Farhaan Bukhsh |
c03c25 |
project=repo,
|
|
Farhaan Bukhsh |
c03c25 |
new_user="foo",
|
|
Farhaan Bukhsh |
c03c25 |
user="pingou",
|
|
Farhaan Bukhsh |
c03c25 |
access='commit'
|
|
Farhaan Bukhsh |
c03c25 |
)
|
|
Farhaan Bukhsh |
c03c25 |
self.session.commit()
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
repo = pagure.lib._get_project(self.session, "test4")
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(len(repo.users), 1)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Check if the user can access private repo
|
|
Farhaan Bukhsh |
c03c25 |
user = tests.FakeUser(username="foo")
|
|
Farhaan Bukhsh |
c03c25 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
output = self.app.get('/test4')
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(output.status_code, 200)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Making a new user bar
|
|
Farhaan Bukhsh |
c03c25 |
item = pagure.lib.model.User(
|
|
Farhaan Bukhsh |
c03c25 |
user='bar',
|
|
Farhaan Bukhsh |
c03c25 |
fullname='bar baz',
|
|
Farhaan Bukhsh |
c03c25 |
password='foo',
|
|
Farhaan Bukhsh |
c03c25 |
default_email='bar@bar.com',
|
|
Farhaan Bukhsh |
c03c25 |
)
|
|
Farhaan Bukhsh |
c03c25 |
self.session.add(item)
|
|
Farhaan Bukhsh |
c03c25 |
item = pagure.lib.model.UserEmail(
|
|
Farhaan Bukhsh |
c03c25 |
user_id=3,
|
|
Farhaan Bukhsh |
c03c25 |
email='bar@bar.com')
|
|
Farhaan Bukhsh |
c03c25 |
self.session.add(item)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
self.session.commit()
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Check that bar shouldn't be able to access the project
|
|
Farhaan Bukhsh |
c03c25 |
user = tests.FakeUser(username="bar")
|
|
Farhaan Bukhsh |
c03c25 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
output = self.app.get('/test4')
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(output.status_code, 404)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Adding a ticket level access to bar
|
|
Farhaan Bukhsh |
c03c25 |
pagure.lib.add_user_to_project(
|
|
Farhaan Bukhsh |
c03c25 |
self.session,
|
|
Farhaan Bukhsh |
c03c25 |
project=repo,
|
|
Farhaan Bukhsh |
c03c25 |
new_user="bar",
|
|
Farhaan Bukhsh |
c03c25 |
user="pingou",
|
|
Farhaan Bukhsh |
c03c25 |
access='ticket'
|
|
Farhaan Bukhsh |
c03c25 |
)
|
|
Farhaan Bukhsh |
c03c25 |
self.session.commit()
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
repo = pagure.lib._get_project(self.session, "test4")
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(len(repo.users), 2)
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
# Check if the ticket level access user can access the project
|
|
Farhaan Bukhsh |
c03c25 |
user = tests.FakeUser(username="bar")
|
|
Farhaan Bukhsh |
c03c25 |
with tests.user_set(self.app.application, user):
|
|
Farhaan Bukhsh |
c03c25 |
|
|
Farhaan Bukhsh |
c03c25 |
output = self.app.get('/test4')
|
|
Farhaan Bukhsh |
c03c25 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
f889f7 |
|
|
farhaanbukhsh |
7ca1b1 |
# API checks
|
|
farhaanbukhsh |
7ca1b1 |
def test_api_private_repo_projects(self):
|
|
farhaanbukhsh |
7ca1b1 |
""" Test api points for private repo for projects"""
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Add private repo
|
|
farhaanbukhsh |
60d445 |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
60d445 |
user_id=1, # pingou
|
|
farhaanbukhsh |
60d445 |
name='test4',
|
|
farhaanbukhsh |
60d445 |
description='test project description',
|
|
farhaanbukhsh |
60d445 |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
60d445 |
private=True,
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
self.session.add(item)
|
|
farhaanbukhsh |
60d445 |
self.session.commit()
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Create a git repo to play with
|
|
Patrick Uiterwijk |
170974 |
gitrepo = os.path.join(self.path, 'repos', 'test4.git')
|
|
farhaanbukhsh |
60d445 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Patrick Uiterwijk |
170974 |
repopath = os.path.join(newpath, 'repos', 'test4')
|
|
farhaanbukhsh |
60d445 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
farhaanbukhsh |
60d445 |
# Create a file in that git repo
|
|
farhaanbukhsh |
60d445 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
farhaanbukhsh |
60d445 |
stream.write('foo\n bar')
|
|
farhaanbukhsh |
60d445 |
clone_repo.index.add('sources')
|
|
farhaanbukhsh |
60d445 |
clone_repo.index.write()
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Commits the files added
|
|
farhaanbukhsh |
60d445 |
tree = clone_repo.index.write_tree()
|
|
farhaanbukhsh |
60d445 |
author = pygit2.Signature(
|
|
farhaanbukhsh |
60d445 |
'Alice Author', 'alice@authors.tld')
|
|
farhaanbukhsh |
60d445 |
committer = pygit2.Signature(
|
|
farhaanbukhsh |
60d445 |
'Cecil Committer', 'cecil@committers.tld')
|
|
farhaanbukhsh |
60d445 |
clone_repo.create_commit(
|
|
farhaanbukhsh |
60d445 |
'refs/heads/master', # the name of the reference to update
|
|
farhaanbukhsh |
60d445 |
author,
|
|
farhaanbukhsh |
60d445 |
committer,
|
|
farhaanbukhsh |
60d445 |
'Add sources file for testing',
|
|
farhaanbukhsh |
60d445 |
# binary string representing the tree object ID
|
|
farhaanbukhsh |
60d445 |
tree,
|
|
farhaanbukhsh |
60d445 |
# list of binary strings representing parents of the new commit
|
|
farhaanbukhsh |
60d445 |
[]
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
refname = 'refs/heads/master:refs/heads/master'
|
|
farhaanbukhsh |
60d445 |
ori_remote = clone_repo.remotes[0]
|
|
farhaanbukhsh |
60d445 |
PagureRepo.push(ori_remote, refname)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Tag our first commit
|
|
farhaanbukhsh |
60d445 |
first_commit = repo.revparse_single('HEAD')
|
|
farhaanbukhsh |
60d445 |
tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0)
|
|
farhaanbukhsh |
60d445 |
repo.create_tag(
|
|
farhaanbukhsh |
60d445 |
"0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
|
|
farhaanbukhsh |
60d445 |
"Release 0.0.1")
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
# Create a token for foo for this project
|
|
farhaanbukhsh |
60d445 |
item = pagure.lib.model.Token(
|
|
farhaanbukhsh |
60d445 |
id='foobar_token',
|
|
farhaanbukhsh |
60d445 |
user_id=1,
|
|
farhaanbukhsh |
60d445 |
project_id=1,
|
|
farhaanbukhsh |
60d445 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
farhaanbukhsh |
60d445 |
days=30)
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
self.session.add(item)
|
|
farhaanbukhsh |
60d445 |
self.session.commit()
|
|
farhaanbukhsh |
60d445 |
item = pagure.lib.model.TokenAcl(
|
|
farhaanbukhsh |
60d445 |
token_id='foobar_token',
|
|
farhaanbukhsh |
d59922 |
acl_id=1,
|
|
farhaanbukhsh |
60d445 |
)
|
|
farhaanbukhsh |
60d445 |
self.session.add(item)
|
|
farhaanbukhsh |
60d445 |
self.session.commit()
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
753ee7 |
# Check if the admin requests
|
|
farhaanbukhsh |
753ee7 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
753ee7 |
# Check tags
|
|
farhaanbukhsh |
753ee7 |
output = self.app.get('/api/0/test4/git/tags')
|
|
farhaanbukhsh |
753ee7 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
753ee7 |
self.assertDictEqual(
|
|
farhaanbukhsh |
753ee7 |
data,
|
|
farhaanbukhsh |
753ee7 |
{'tags': ['0.0.1'], 'total_tags': 1}
|
|
farhaanbukhsh |
753ee7 |
)
|
|
farhaanbukhsh |
753ee7 |
|
|
farhaanbukhsh |
753ee7 |
output = self.app.get('/api/0/test4/git/tags')
|
|
farhaanbukhsh |
753ee7 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
753ee7 |
# Chekc if user is not admin
|
|
farhaanbukhsh |
753ee7 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
753ee7 |
output = self.app.get('/api/0/test4/git/tags')
|
|
farhaanbukhsh |
753ee7 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
60d445 |
|
|
farhaanbukhsh |
60d445 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
3604c1 |
|
|
farhaanbukhsh |
7ca1b1 |
# Check before adding
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
7ca1b1 |
self.assertEqual(repo.tags, [])
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
# Adding a tag
|
|
farhaanbukhsh |
7ca1b1 |
output = pagure.lib.update_tags(
|
|
Patrick Uiterwijk |
3f97f6 |
self.session, repo, 'infra', 'pingou')
|
|
Pierre-Yves Chibon |
ef1fe1 |
self.assertEqual(output, ['Project tagged with: infra'])
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
# Check after adding
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
7ca1b1 |
self.assertEqual(len(repo.tags), 1)
|
|
farhaanbukhsh |
7ca1b1 |
self.assertEqual(repo.tags_text, ['infra'])
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
# Check the API
|
|
farhaanbukhsh |
7ca1b1 |
output = self.app.get('/api/0/projects?tags=inf')
|
|
Pierre-Yves Chibon |
842acb |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
farhaanbukhsh |
7ca1b1 |
self.assertDictEqual(
|
|
farhaanbukhsh |
7ca1b1 |
data,
|
|
Pierre-Yves Chibon |
842acb |
{
|
|
Aurélien Bompard |
626417 |
'args': {
|
|
Aurélien Bompard |
626417 |
'fork': None,
|
|
Aurélien Bompard |
626417 |
'namespace': None,
|
|
Aurélien Bompard |
626417 |
'owner': None,
|
|
Karsten Hopp |
a5d5f1 |
'page': 1,
|
|
Aurélien Bompard |
626417 |
'pattern': None,
|
|
Karsten Hopp |
a5d5f1 |
'per_page': 20,
|
|
Aurélien Bompard |
626417 |
'short': False,
|
|
Aurélien Bompard |
626417 |
'tags': ['inf'],
|
|
Aurélien Bompard |
626417 |
'username': None
|
|
Pierre-Yves Chibon |
842acb |
},
|
|
Aurélien Bompard |
626417 |
'projects': [],
|
|
Aurélien Bompard |
626417 |
'total_projects': 0
|
|
Pierre-Yves Chibon |
842acb |
}
|
|
farhaanbukhsh |
7ca1b1 |
)
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
# Request by not a loggged in user
|
|
farhaanbukhsh |
7ca1b1 |
output = self.app.get('/api/0/projects?tags=infra')
|
|
Pierre-Yves Chibon |
842acb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
842acb |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Pierre-Yves Chibon |
842acb |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
842acb |
data,
|
|
Pierre-Yves Chibon |
842acb |
{
|
|
Aurélien Bompard |
626417 |
'args': {
|
|
Aurélien Bompard |
626417 |
'fork': None,
|
|
Aurélien Bompard |
626417 |
'namespace': None,
|
|
Aurélien Bompard |
626417 |
'owner': None,
|
|
Karsten Hopp |
a5d5f1 |
'page': 1,
|
|
Aurélien Bompard |
626417 |
'pattern': None,
|
|
Karsten Hopp |
a5d5f1 |
'per_page': 20,
|
|
Aurélien Bompard |
626417 |
'short': False,
|
|
Aurélien Bompard |
626417 |
'tags': ['infra'],
|
|
Aurélien Bompard |
626417 |
'username': None
|
|
Pierre-Yves Chibon |
842acb |
},
|
|
Aurélien Bompard |
626417 |
'projects': [],
|
|
Aurélien Bompard |
626417 |
'total_projects': 0
|
|
Pierre-Yves Chibon |
842acb |
}
|
|
Pierre-Yves Chibon |
842acb |
)
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
7ca1b1 |
# Request by a non authorized user
|
|
farhaanbukhsh |
7ca1b1 |
output = self.app.get('/api/0/projects?tags=infra')
|
|
Pierre-Yves Chibon |
842acb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
842acb |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Pierre-Yves Chibon |
842acb |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
842acb |
data,
|
|
Pierre-Yves Chibon |
842acb |
{
|
|
Aurélien Bompard |
626417 |
'args': {
|
|
Aurélien Bompard |
626417 |
'fork': None,
|
|
Aurélien Bompard |
626417 |
'namespace': None,
|
|
Aurélien Bompard |
626417 |
'owner': None,
|
|
Karsten Hopp |
a5d5f1 |
'page': 1,
|
|
Aurélien Bompard |
626417 |
'pattern': None,
|
|
Karsten Hopp |
a5d5f1 |
'per_page': 20,
|
|
Aurélien Bompard |
626417 |
'short': False,
|
|
Aurélien Bompard |
626417 |
'tags': ['infra'],
|
|
Aurélien Bompard |
626417 |
'username': None
|
|
Pierre-Yves Chibon |
842acb |
},
|
|
Aurélien Bompard |
626417 |
'projects': [],
|
|
Aurélien Bompard |
626417 |
'total_projects': 0
|
|
Pierre-Yves Chibon |
842acb |
}
|
|
Pierre-Yves Chibon |
842acb |
)
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
user.username = 'pingou'
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
7ca1b1 |
# Private repo username is compulsion to pass
|
|
farhaanbukhsh |
7ca1b1 |
output = self.app.get('/api/0/projects?tags=infra')
|
|
Pierre-Yves Chibon |
842acb |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
842acb |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Pierre-Yves Chibon |
842acb |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
842acb |
data,
|
|
Pierre-Yves Chibon |
842acb |
{
|
|
Aurélien Bompard |
626417 |
'args': {
|
|
Aurélien Bompard |
626417 |
'fork': None,
|
|
Aurélien Bompard |
626417 |
'namespace': None,
|
|
Aurélien Bompard |
626417 |
'owner': None,
|
|
Karsten Hopp |
a5d5f1 |
'page': 1,
|
|
Aurélien Bompard |
626417 |
'pattern': None,
|
|
Karsten Hopp |
a5d5f1 |
'per_page': 20,
|
|
Aurélien Bompard |
626417 |
'short': False,
|
|
Aurélien Bompard |
626417 |
'tags': ['infra'],
|
|
Aurélien Bompard |
626417 |
'username': None
|
|
Pierre-Yves Chibon |
842acb |
},
|
|
Aurélien Bompard |
626417 |
'projects': [],
|
|
Aurélien Bompard |
626417 |
'total_projects': 0
|
|
Pierre-Yves Chibon |
842acb |
}
|
|
Pierre-Yves Chibon |
842acb |
)
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
output = self.app.get('/api/0/projects?username=pingou')
|
|
farhaanbukhsh |
7ca1b1 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
7ca1b1 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
farhaanbukhsh |
7ca1b1 |
self.assertDictEqual(
|
|
farhaanbukhsh |
7ca1b1 |
data,
|
|
farhaanbukhsh |
7ca1b1 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"args": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fork": None,
|
|
Matt Prahl |
091bab |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Farhaan Bukhsh |
8aa0f5 |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
9993ca |
"short": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": [],
|
|
Farhaan Bukhsh |
8aa0f5 |
"username": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
farhaanbukhsh |
7ca1b1 |
"total_projects": 1,
|
|
farhaanbukhsh |
7ca1b1 |
"projects": [
|
|
farhaanbukhsh |
7ca1b1 |
{
|
|
Farhaan Bukhsh |
6ccd40 |
"access_groups": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
6ccd40 |
"access_users": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"owner": [
|
|
Farhaan Bukhsh |
6ccd40 |
"pingou"
|
|
Farhaan Bukhsh |
6ccd40 |
],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
990ffe |
"close_status": [],
|
|
Farhaan Bukhsh |
990ffe |
"custom_keys": [],
|
|
farhaanbukhsh |
7ca1b1 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
farhaanbukhsh |
7ca1b1 |
"description": "test project description",
|
|
farhaanbukhsh |
7ca1b1 |
"id": 1,
|
|
Farhaan Bukhsh |
990ffe |
"milestones": {},
|
|
farhaanbukhsh |
7ca1b1 |
"name": "test4",
|
|
Farhaan Bukhsh |
7c4229 |
"fullname": "test4",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test4",
|
|
Farhaan Bukhsh |
990ffe |
"namespace": None,
|
|
farhaanbukhsh |
7ca1b1 |
"parent": None,
|
|
farhaanbukhsh |
7ca1b1 |
"priorities": {},
|
|
farhaanbukhsh |
7ca1b1 |
"tags": ["infra"],
|
|
farhaanbukhsh |
7ca1b1 |
"user": {
|
|
farhaanbukhsh |
7ca1b1 |
"fullname": "PY C",
|
|
farhaanbukhsh |
7ca1b1 |
"name": "pingou"
|
|
farhaanbukhsh |
7ca1b1 |
}
|
|
farhaanbukhsh |
7ca1b1 |
},
|
|
farhaanbukhsh |
7ca1b1 |
]
|
|
farhaanbukhsh |
7ca1b1 |
}
|
|
farhaanbukhsh |
7ca1b1 |
)
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
7ca1b1 |
output = self.app.get('/api/0/projects?username=pingou&tags=infra')
|
|
farhaanbukhsh |
7ca1b1 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
7ca1b1 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
farhaanbukhsh |
7ca1b1 |
self.assertDictEqual(
|
|
farhaanbukhsh |
7ca1b1 |
data,
|
|
farhaanbukhsh |
7ca1b1 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
"args": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"fork": None,
|
|
Matt Prahl |
091bab |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Farhaan Bukhsh |
8aa0f5 |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
9993ca |
"short": False,
|
|
Farhaan Bukhsh |
8aa0f5 |
"tags": ["infra"],
|
|
Farhaan Bukhsh |
8aa0f5 |
"username": "pingou"
|
|
Farhaan Bukhsh |
8aa0f5 |
},
|
|
farhaanbukhsh |
7ca1b1 |
"total_projects": 1,
|
|
farhaanbukhsh |
7ca1b1 |
"projects": [
|
|
farhaanbukhsh |
7ca1b1 |
{
|
|
Farhaan Bukhsh |
6ccd40 |
"access_groups": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
6ccd40 |
"access_users": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"owner": [
|
|
Farhaan Bukhsh |
6ccd40 |
"pingou"
|
|
Farhaan Bukhsh |
6ccd40 |
],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
990ffe |
"close_status": [],
|
|
Farhaan Bukhsh |
990ffe |
"custom_keys": [],
|
|
farhaanbukhsh |
7ca1b1 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
farhaanbukhsh |
7ca1b1 |
"description": "test project description",
|
|
farhaanbukhsh |
7ca1b1 |
"id": 1,
|
|
Farhaan Bukhsh |
990ffe |
"milestones": {},
|
|
farhaanbukhsh |
7ca1b1 |
"name": "test4",
|
|
Farhaan Bukhsh |
7c4229 |
"fullname": "test4",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test4",
|
|
Farhaan Bukhsh |
990ffe |
"namespace": None,
|
|
farhaanbukhsh |
7ca1b1 |
"parent": None,
|
|
farhaanbukhsh |
7ca1b1 |
"priorities": {},
|
|
farhaanbukhsh |
7ca1b1 |
"tags": ["infra"],
|
|
farhaanbukhsh |
7ca1b1 |
"user": {
|
|
farhaanbukhsh |
7ca1b1 |
"fullname": "PY C",
|
|
farhaanbukhsh |
7ca1b1 |
"name": "pingou"
|
|
farhaanbukhsh |
7ca1b1 |
}
|
|
farhaanbukhsh |
7ca1b1 |
}
|
|
farhaanbukhsh |
7ca1b1 |
]
|
|
farhaanbukhsh |
7ca1b1 |
}
|
|
Farhaan Bukhsh |
990ffe |
|
|
farhaanbukhsh |
7ca1b1 |
)
|
|
farhaanbukhsh |
7ca1b1 |
|
|
farhaanbukhsh |
44a97a |
# Api pull-request views
|
|
farhaanbukhsh |
44a97a |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
e3c47c |
def test_api_private_repo_fork(self, send_email):
|
|
farhaanbukhsh |
44a97a |
""" Test api endpoints in api/fork"""
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
44a97a |
send_email.return_value = True
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
44a97a |
# Add private repo
|
|
farhaanbukhsh |
44a97a |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
44a97a |
user_id=1, # pingou
|
|
farhaanbukhsh |
44a97a |
name='test4',
|
|
farhaanbukhsh |
44a97a |
description='test project description',
|
|
farhaanbukhsh |
44a97a |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
44a97a |
private=True,
|
|
farhaanbukhsh |
44a97a |
)
|
|
farhaanbukhsh |
44a97a |
self.session.add(item)
|
|
farhaanbukhsh |
44a97a |
self.session.commit()
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
fd8d2a |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
fd8d2a |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
fd8d2a |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
44a97a |
# Create a pull-request
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Farhaan Bukhsh |
839011 |
forked_repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
44a97a |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
44a97a |
session=self.session,
|
|
farhaanbukhsh |
44a97a |
repo_from=forked_repo,
|
|
farhaanbukhsh |
44a97a |
branch_from='master',
|
|
farhaanbukhsh |
44a97a |
repo_to=repo,
|
|
farhaanbukhsh |
44a97a |
branch_to='master',
|
|
farhaanbukhsh |
44a97a |
title='test pull-request',
|
|
farhaanbukhsh |
44a97a |
user='pingou',
|
|
farhaanbukhsh |
44a97a |
)
|
|
farhaanbukhsh |
44a97a |
self.session.commit()
|
|
farhaanbukhsh |
44a97a |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
44a97a |
self.assertEqual(req.title, 'test pull-request')
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# Check list of PR
|
|
farhaanbukhsh |
44a97a |
output = self.app.get('/api/0/test4/pull-requests')
|
|
farhaanbukhsh |
44a97a |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
fd8d2a |
# Check single PR
|
|
farhaanbukhsh |
fd8d2a |
output = self.app.get('/api/0/test/pull-request/1')
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
44a97a |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
44a97a |
# List pull-requests
|
|
farhaanbukhsh |
44a97a |
output = self.app.get('/api/0/test4/pull-requests')
|
|
farhaanbukhsh |
44a97a |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
44a97a |
data['requests'][0]['date_created'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data['requests'][0]['updated_on'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data['requests'][0]['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['requests'][0]['project']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data['requests'][0]['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['requests'][0]['repo_from']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data['requests'][0]['uid'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['requests'][0]['last_updated'] = '1431414800'
|
|
Karsten Hopp |
566852 |
for k in ['first', 'last']:
|
|
Karsten Hopp |
566852 |
self.assertIsNotNone(data['pagination'][k])
|
|
Karsten Hopp |
566852 |
data['pagination'][k] = 'http://localhost...'
|
|
farhaanbukhsh |
44a97a |
self.assertDictEqual(
|
|
farhaanbukhsh |
44a97a |
data,
|
|
farhaanbukhsh |
44a97a |
{
|
|
Farhaan Bukhsh |
02f421 |
"args": {
|
|
Farhaan Bukhsh |
02f421 |
"assignee": None,
|
|
Farhaan Bukhsh |
02f421 |
"author": None,
|
|
Karsten Hopp |
566852 |
"page": 1,
|
|
Karsten Hopp |
566852 |
"per_page": 20,
|
|
Farhaan Bukhsh |
02f421 |
"status": True
|
|
Farhaan Bukhsh |
02f421 |
},
|
|
Karsten Hopp |
566852 |
"pagination": {
|
|
Karsten Hopp |
566852 |
"first": 'http://localhost...',
|
|
Karsten Hopp |
566852 |
"last": 'http://localhost...',
|
|
Karsten Hopp |
566852 |
"next": None,
|
|
Karsten Hopp |
566852 |
"page": 1,
|
|
Karsten Hopp |
566852 |
"pages": 1,
|
|
Karsten Hopp |
566852 |
"per_page": 20,
|
|
Karsten Hopp |
566852 |
"prev": None
|
|
Karsten Hopp |
566852 |
},
|
|
Farhaan Bukhsh |
02f421 |
"requests": [
|
|
Farhaan Bukhsh |
02f421 |
{
|
|
Farhaan Bukhsh |
02f421 |
"assignee": None,
|
|
Farhaan Bukhsh |
02f421 |
"branch": "master",
|
|
Farhaan Bukhsh |
02f421 |
"branch_from": "master",
|
|
Pierre-Yves Chibon |
f21734 |
"cached_merge_status": "unknown",
|
|
Farhaan Bukhsh |
02f421 |
"closed_at": None,
|
|
Farhaan Bukhsh |
02f421 |
"closed_by": None,
|
|
Farhaan Bukhsh |
02f421 |
"comments": [],
|
|
Farhaan Bukhsh |
02f421 |
"commit_start": None,
|
|
Farhaan Bukhsh |
02f421 |
"commit_stop": None,
|
|
Farhaan Bukhsh |
02f421 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"id": 1,
|
|
Farhaan Bukhsh |
02f421 |
"initial_comment": None,
|
|
Farhaan Bukhsh |
02f421 |
"project": {
|
|
Farhaan Bukhsh |
6ccd40 |
"access_groups": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
6ccd40 |
"access_users": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"owner": [
|
|
Farhaan Bukhsh |
6ccd40 |
"pingou"
|
|
Farhaan Bukhsh |
6ccd40 |
],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
02f421 |
"close_status": [],
|
|
Farhaan Bukhsh |
02f421 |
"custom_keys": [],
|
|
Farhaan Bukhsh |
02f421 |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"description": "test project description",
|
|
Farhaan Bukhsh |
02f421 |
"id": 1,
|
|
Farhaan Bukhsh |
02f421 |
"milestones": {},
|
|
Farhaan Bukhsh |
02f421 |
"name": "test4",
|
|
Farhaan Bukhsh |
7c4229 |
"fullname": "test4",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test4",
|
|
Farhaan Bukhsh |
02f421 |
"namespace": None,
|
|
Farhaan Bukhsh |
02f421 |
"parent": None,
|
|
Farhaan Bukhsh |
02f421 |
"priorities": {},
|
|
Farhaan Bukhsh |
02f421 |
"tags": [],
|
|
Farhaan Bukhsh |
02f421 |
"user": {
|
|
Farhaan Bukhsh |
02f421 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
02f421 |
"name": "pingou"
|
|
Farhaan Bukhsh |
02f421 |
}
|
|
Farhaan Bukhsh |
02f421 |
},
|
|
Farhaan Bukhsh |
02f421 |
"remote_git": None,
|
|
Farhaan Bukhsh |
02f421 |
"repo_from": {
|
|
Farhaan Bukhsh |
6ccd40 |
"access_groups": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
6ccd40 |
"access_users": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"owner": [
|
|
Farhaan Bukhsh |
6ccd40 |
"pingou"
|
|
Farhaan Bukhsh |
6ccd40 |
],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
02f421 |
"close_status": [],
|
|
Farhaan Bukhsh |
02f421 |
"custom_keys": [],
|
|
Farhaan Bukhsh |
02f421 |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"description": "test project description",
|
|
Farhaan Bukhsh |
02f421 |
"id": 1,
|
|
Farhaan Bukhsh |
02f421 |
"milestones": {},
|
|
Farhaan Bukhsh |
7c4229 |
"fullname": "test4",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test4",
|
|
Farhaan Bukhsh |
02f421 |
"name": "test4",
|
|
Farhaan Bukhsh |
02f421 |
"namespace": None,
|
|
Farhaan Bukhsh |
02f421 |
"parent": None,
|
|
Farhaan Bukhsh |
02f421 |
"priorities": {},
|
|
Farhaan Bukhsh |
02f421 |
"tags": [],
|
|
Farhaan Bukhsh |
02f421 |
"user": {
|
|
Farhaan Bukhsh |
02f421 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
02f421 |
"name": "pingou"
|
|
Farhaan Bukhsh |
02f421 |
}
|
|
Farhaan Bukhsh |
02f421 |
},
|
|
Farhaan Bukhsh |
02f421 |
"status": "Open",
|
|
Farhaan Bukhsh |
02f421 |
"title": "test pull-request",
|
|
Farhaan Bukhsh |
02f421 |
"uid": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"updated_on": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"user": {
|
|
Farhaan Bukhsh |
02f421 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
02f421 |
"name": "pingou"
|
|
Farhaan Bukhsh |
02f421 |
}
|
|
Farhaan Bukhsh |
02f421 |
}
|
|
Farhaan Bukhsh |
02f421 |
],
|
|
Farhaan Bukhsh |
02f421 |
"total_requests": 1
|
|
Farhaan Bukhsh |
65b71a |
}
|
|
farhaanbukhsh |
44a97a |
)
|
|
farhaanbukhsh |
44a97a |
headers = {'Authorization': 'token foobar_token'}
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
44a97a |
# Access Pull-Request authenticated
|
|
farhaanbukhsh |
e3c47c |
output = self.app.get(
|
|
farhaanbukhsh |
e3c47c |
'/api/0/test4/pull-requests', headers=headers)
|
|
farhaanbukhsh |
44a97a |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data2 = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
44a97a |
data2['requests'][0]['date_created'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data2['requests'][0]['updated_on'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data2['requests'][0]['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['requests'][0]['project']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data2['requests'][0]['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['requests'][0]['repo_from']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
44a97a |
data2['requests'][0]['uid'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data2['requests'][0]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
dd03b1 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
dd03b1 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
dd03b1 |
data2['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
dd03b1 |
|
|
farhaanbukhsh |
44a97a |
self.assertDictEqual(data, data2)
|
|
farhaanbukhsh |
44a97a |
|
|
farhaanbukhsh |
fd8d2a |
# For single PR
|
|
farhaanbukhsh |
f693ef |
output = self.app.get('/api/0/test4/pull-request/1')
|
|
farhaanbukhsh |
f693ef |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
f693ef |
data['date_created'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data['updated_on'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['project']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['repo_from']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data['uid'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
self.assertDictEqual(
|
|
farhaanbukhsh |
f693ef |
data,
|
|
Farhaan Bukhsh |
02f421 |
{
|
|
Farhaan Bukhsh |
02f421 |
"assignee": None,
|
|
Farhaan Bukhsh |
02f421 |
"branch": "master",
|
|
Farhaan Bukhsh |
02f421 |
"branch_from": "master",
|
|
Pierre-Yves Chibon |
f21734 |
"cached_merge_status": "unknown",
|
|
Farhaan Bukhsh |
02f421 |
"closed_at": None,
|
|
Farhaan Bukhsh |
02f421 |
"closed_by": None,
|
|
Farhaan Bukhsh |
02f421 |
"comments": [],
|
|
Farhaan Bukhsh |
02f421 |
"commit_start": None,
|
|
Farhaan Bukhsh |
02f421 |
"commit_stop": None,
|
|
Farhaan Bukhsh |
02f421 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"id": 1,
|
|
Farhaan Bukhsh |
02f421 |
"initial_comment": None,
|
|
Farhaan Bukhsh |
02f421 |
"project": {
|
|
Farhaan Bukhsh |
6ccd40 |
"access_groups": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
6ccd40 |
"access_users": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"owner": [
|
|
Farhaan Bukhsh |
6ccd40 |
"pingou"
|
|
Farhaan Bukhsh |
6ccd40 |
],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
02f421 |
"close_status": [],
|
|
Farhaan Bukhsh |
02f421 |
"custom_keys": [],
|
|
Farhaan Bukhsh |
02f421 |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"description": "test project description",
|
|
Farhaan Bukhsh |
02f421 |
"id": 1,
|
|
Farhaan Bukhsh |
02f421 |
"milestones": {},
|
|
Farhaan Bukhsh |
02f421 |
"name": "test4",
|
|
Farhaan Bukhsh |
7c4229 |
"fullname": "test4",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test4",
|
|
Farhaan Bukhsh |
02f421 |
"namespace": None,
|
|
Farhaan Bukhsh |
02f421 |
"parent": None,
|
|
Farhaan Bukhsh |
02f421 |
"priorities": {},
|
|
Farhaan Bukhsh |
02f421 |
"tags": [],
|
|
Farhaan Bukhsh |
02f421 |
"user": {
|
|
Farhaan Bukhsh |
02f421 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
02f421 |
"name": "pingou"
|
|
Farhaan Bukhsh |
02f421 |
}
|
|
Farhaan Bukhsh |
02f421 |
},
|
|
Farhaan Bukhsh |
02f421 |
"remote_git": None,
|
|
Farhaan Bukhsh |
02f421 |
"repo_from": {
|
|
Farhaan Bukhsh |
6ccd40 |
"access_groups": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
6ccd40 |
"access_users": {
|
|
Farhaan Bukhsh |
6ccd40 |
"admin": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"commit": [],
|
|
Farhaan Bukhsh |
6ccd40 |
"owner": [
|
|
Farhaan Bukhsh |
6ccd40 |
"pingou"
|
|
Farhaan Bukhsh |
6ccd40 |
],
|
|
Farhaan Bukhsh |
6ccd40 |
"ticket": []
|
|
Farhaan Bukhsh |
6ccd40 |
},
|
|
Farhaan Bukhsh |
02f421 |
"close_status": [],
|
|
Farhaan Bukhsh |
02f421 |
"custom_keys": [],
|
|
Farhaan Bukhsh |
02f421 |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"description": "test project description",
|
|
Farhaan Bukhsh |
02f421 |
"id": 1,
|
|
Farhaan Bukhsh |
02f421 |
"milestones": {},
|
|
Farhaan Bukhsh |
02f421 |
"name": "test4",
|
|
Farhaan Bukhsh |
7c4229 |
"fullname": "test4",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test4",
|
|
Farhaan Bukhsh |
02f421 |
"namespace": None,
|
|
Farhaan Bukhsh |
02f421 |
"parent": None,
|
|
Farhaan Bukhsh |
02f421 |
"priorities": {},
|
|
Farhaan Bukhsh |
02f421 |
"tags": [],
|
|
Farhaan Bukhsh |
02f421 |
"user": {
|
|
Farhaan Bukhsh |
02f421 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
02f421 |
"name": "pingou"
|
|
Farhaan Bukhsh |
02f421 |
}
|
|
Farhaan Bukhsh |
02f421 |
},
|
|
Farhaan Bukhsh |
02f421 |
"status": "Open",
|
|
Farhaan Bukhsh |
02f421 |
"title": "test pull-request",
|
|
Farhaan Bukhsh |
02f421 |
"uid": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"updated_on": "1431414800",
|
|
Farhaan Bukhsh |
02f421 |
"user": {
|
|
Farhaan Bukhsh |
02f421 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
02f421 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
dd03b1 |
},
|
|
Farhaan Bukhsh |
65b71a |
}
|
|
Farhaan Bukhsh |
65b71a |
|
|
farhaanbukhsh |
f693ef |
)
|
|
farhaanbukhsh |
f693ef |
|
|
farhaanbukhsh |
f693ef |
# Access Pull-Request authenticated
|
|
farhaanbukhsh |
e3c47c |
output = self.app.get(
|
|
farhaanbukhsh |
e3c47c |
'/api/0/test4/pull-request/1', headers=headers)
|
|
farhaanbukhsh |
f693ef |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data2 = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
f693ef |
data2['date_created'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data2['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['project']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data2['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['repo_from']['date_modified'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data2['uid'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data2['date_created'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
data2['updated_on'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data2['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
f693ef |
self.assertDictEqual(data, data2)
|
|
farhaanbukhsh |
f693ef |
|
|
farhaanbukhsh |
fd8d2a |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
fd8d2a |
def test_api_pr_private_repo_add_comment(self, mockemail):
|
|
farhaanbukhsh |
fd8d2a |
""" Test the api_pull_request_add_comment method of the flask api. """
|
|
farhaanbukhsh |
fd8d2a |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['REQUESTS_FOLDER'] = None
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# Add private repo
|
|
farhaanbukhsh |
fd8d2a |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
fd8d2a |
user_id=1, # pingou
|
|
farhaanbukhsh |
fd8d2a |
name='test4',
|
|
farhaanbukhsh |
fd8d2a |
description='test project description',
|
|
farhaanbukhsh |
fd8d2a |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
fd8d2a |
private=True,
|
|
farhaanbukhsh |
fd8d2a |
)
|
|
farhaanbukhsh |
fd8d2a |
self.session.add(item)
|
|
farhaanbukhsh |
fd8d2a |
self.session.commit()
|
|
farhaanbukhsh |
fd8d2a |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
fd8d2a |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
fd8d2a |
# Create a pull-request
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Farhaan Bukhsh |
839011 |
forked_repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
fd8d2a |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
fd8d2a |
session=self.session,
|
|
farhaanbukhsh |
fd8d2a |
repo_from=forked_repo,
|
|
farhaanbukhsh |
fd8d2a |
branch_from='master',
|
|
farhaanbukhsh |
fd8d2a |
repo_to=repo,
|
|
farhaanbukhsh |
fd8d2a |
branch_to='master',
|
|
farhaanbukhsh |
fd8d2a |
title='test pull-request',
|
|
farhaanbukhsh |
fd8d2a |
user='pingou',
|
|
farhaanbukhsh |
fd8d2a |
)
|
|
farhaanbukhsh |
fd8d2a |
self.session.commit()
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(req.title, 'test pull-request')
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# Check comments before
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
fd8d2a |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
fd8d2a |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(len(request.comments), 0)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
data = {
|
|
farhaanbukhsh |
fd8d2a |
'title': 'test issue',
|
|
farhaanbukhsh |
fd8d2a |
}
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# Incomplete request
|
|
farhaanbukhsh |
fd8d2a |
output = self.app.post(
|
|
farhaanbukhsh |
fd8d2a |
'/api/0/test4/pull-request/1/comment', data=data, headers=headers)
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(output.status_code, 400)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
fd8d2a |
self.assertDictEqual(
|
|
farhaanbukhsh |
fd8d2a |
data,
|
|
farhaanbukhsh |
fd8d2a |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "EINVALIDREQ",
|
|
Farhaan Bukhsh |
8aa0f5 |
"errors": {"comment": ["This field is required."]}
|
|
farhaanbukhsh |
fd8d2a |
}
|
|
farhaanbukhsh |
fd8d2a |
)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# No change
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
fd8d2a |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
fd8d2a |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(len(request.comments), 0)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
data = {
|
|
farhaanbukhsh |
fd8d2a |
'comment': 'This is a very interesting question',
|
|
farhaanbukhsh |
fd8d2a |
}
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# Valid request
|
|
farhaanbukhsh |
fd8d2a |
output = self.app.post(
|
|
farhaanbukhsh |
fd8d2a |
'/api/0/test4/pull-request/1/comment', data=data, headers=headers)
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
fd8d2a |
self.assertDictEqual(
|
|
farhaanbukhsh |
fd8d2a |
data,
|
|
farhaanbukhsh |
fd8d2a |
{'message': 'Comment added'}
|
|
farhaanbukhsh |
fd8d2a |
)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
fd8d2a |
# One comment added
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
fd8d2a |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
fd8d2a |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
fd8d2a |
self.assertEqual(len(request.comments), 1)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
a0d3dc |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
a0d3dc |
def test_api_private_repo_pr_add_flag(self, mockemail):
|
|
farhaanbukhsh |
a0d3dc |
""" Test the api_pull_request_add_flag method of the flask api. """
|
|
farhaanbukhsh |
a0d3dc |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['REQUESTS_FOLDER'] = None
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Add private repo
|
|
farhaanbukhsh |
a0d3dc |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
a0d3dc |
user_id=1, # pingou
|
|
farhaanbukhsh |
a0d3dc |
name='test4',
|
|
farhaanbukhsh |
a0d3dc |
description='test project description',
|
|
farhaanbukhsh |
a0d3dc |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
a0d3dc |
private=True,
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
self.session.add(item)
|
|
farhaanbukhsh |
a0d3dc |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Add private repo
|
|
farhaanbukhsh |
a0d3dc |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
a0d3dc |
user_id=1, # pingou
|
|
farhaanbukhsh |
a0d3dc |
name='test2',
|
|
farhaanbukhsh |
a0d3dc |
description='test project description',
|
|
farhaanbukhsh |
a0d3dc |
hook_token='foo_bar',
|
|
farhaanbukhsh |
a0d3dc |
private=True,
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
self.session.add(item)
|
|
farhaanbukhsh |
a0d3dc |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
a0d3dc |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Invalid project
|
|
farhaanbukhsh |
a0d3dc |
output = self.app.post(
|
|
farhaanbukhsh |
a0d3dc |
'/api/0/foo/pull-request/1/flag', headers=headers)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
a0d3dc |
self.assertDictEqual(
|
|
farhaanbukhsh |
a0d3dc |
data,
|
|
farhaanbukhsh |
a0d3dc |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
a0d3dc |
}
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Valid token, wrong project
|
|
farhaanbukhsh |
a0d3dc |
output = self.app.post(
|
|
farhaanbukhsh |
a0d3dc |
'/api/0/test2/pull-request/1/flag', headers=headers)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# No input
|
|
farhaanbukhsh |
a0d3dc |
output = self.app.post(
|
|
farhaanbukhsh |
a0d3dc |
'/api/0/test4/pull-request/1/flag', headers=headers)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
a0d3dc |
self.assertDictEqual(
|
|
farhaanbukhsh |
a0d3dc |
data,
|
|
farhaanbukhsh |
a0d3dc |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Pull-Request not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOREQ",
|
|
farhaanbukhsh |
a0d3dc |
}
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Create a pull-request
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Farhaan Bukhsh |
839011 |
forked_repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
a0d3dc |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
a0d3dc |
session=self.session,
|
|
farhaanbukhsh |
a0d3dc |
repo_from=forked_repo,
|
|
farhaanbukhsh |
a0d3dc |
branch_from='master',
|
|
farhaanbukhsh |
a0d3dc |
repo_to=repo,
|
|
farhaanbukhsh |
a0d3dc |
branch_to='master',
|
|
farhaanbukhsh |
a0d3dc |
title='test pull-request',
|
|
farhaanbukhsh |
a0d3dc |
user='pingou',
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(req.title, 'test pull-request')
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Check comments before
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
a0d3dc |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(len(request.flags), 0)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
data = {
|
|
farhaanbukhsh |
a0d3dc |
'username': 'Jenkins',
|
|
farhaanbukhsh |
a0d3dc |
'percent': 100,
|
|
farhaanbukhsh |
a0d3dc |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
farhaanbukhsh |
a0d3dc |
'uid': 'jenkins_build_pagure_100+seed',
|
|
farhaanbukhsh |
a0d3dc |
}
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Incomplete request
|
|
farhaanbukhsh |
a0d3dc |
output = self.app.post(
|
|
farhaanbukhsh |
a0d3dc |
'/api/0/test4/pull-request/1/flag', data=data, headers=headers)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(output.status_code, 400)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
a0d3dc |
self.assertDictEqual(
|
|
farhaanbukhsh |
a0d3dc |
data,
|
|
farhaanbukhsh |
a0d3dc |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "EINVALIDREQ",
|
|
Farhaan Bukhsh |
8aa0f5 |
"errors": {"comment": ["This field is required."]}
|
|
farhaanbukhsh |
a0d3dc |
}
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# No change
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
a0d3dc |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(len(request.flags), 0)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
data = {
|
|
farhaanbukhsh |
a0d3dc |
'username': 'Jenkins',
|
|
farhaanbukhsh |
a0d3dc |
'percent': 0,
|
|
farhaanbukhsh |
a0d3dc |
'comment': 'Tests failed',
|
|
farhaanbukhsh |
a0d3dc |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
farhaanbukhsh |
a0d3dc |
'uid': 'jenkins_build_pagure_100+seed',
|
|
farhaanbukhsh |
a0d3dc |
}
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Valid request
|
|
farhaanbukhsh |
a0d3dc |
output = self.app.post(
|
|
farhaanbukhsh |
a0d3dc |
'/api/0/test4/pull-request/1/flag', data=data, headers=headers)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Aurélien Bompard |
626417 |
data['flag']['date_created'] = '1510742565'
|
|
Aurélien Bompard |
626417 |
data['flag']['pull_request_uid'] = '62b49f00d489452994de5010565fab81'
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
farhaanbukhsh |
a0d3dc |
self.assertDictEqual(
|
|
farhaanbukhsh |
a0d3dc |
data,
|
|
Pierre-Yves Chibon |
c27d61 |
{
|
|
Aurélien Bompard |
626417 |
'flag': {
|
|
Aurélien Bompard |
626417 |
'comment': 'Tests failed',
|
|
Aurélien Bompard |
626417 |
'date_created': '1510742565',
|
|
Aurélien Bompard |
626417 |
'percent': 0,
|
|
Aurélien Bompard |
626417 |
'pull_request_uid': '62b49f00d489452994de5010565fab81',
|
|
Aurélien Bompard |
626417 |
'status': 'failure',
|
|
Aurélien Bompard |
626417 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Aurélien Bompard |
626417 |
'user': {
|
|
Aurélien Bompard |
626417 |
'default_email': 'bar@pingou.com',
|
|
Aurélien Bompard |
626417 |
'emails': ['bar@pingou.com', 'foo@pingou.com'],
|
|
Aurélien Bompard |
626417 |
'fullname': 'PY C',
|
|
Aurélien Bompard |
626417 |
'name': 'pingou'},
|
|
Aurélien Bompard |
626417 |
'username': 'Jenkins'},
|
|
Aurélien Bompard |
626417 |
'message': 'Flag added',
|
|
Pierre-Yves Chibon |
e2c468 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
e2c468 |
'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
|
|
Pierre-Yves Chibon |
e2c468 |
'user': 'pingou'
|
|
Pierre-Yves Chibon |
c27d61 |
}
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# One flag added
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
a0d3dc |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(len(request.flags), 1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(request.flags[0].comment, 'Tests failed')
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(request.flags[0].percent, 0)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# Update flag
|
|
farhaanbukhsh |
a0d3dc |
data = {
|
|
farhaanbukhsh |
a0d3dc |
'username': 'Jenkins',
|
|
farhaanbukhsh |
a0d3dc |
'percent': 100,
|
|
farhaanbukhsh |
a0d3dc |
'comment': 'Tests passed',
|
|
farhaanbukhsh |
a0d3dc |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
farhaanbukhsh |
a0d3dc |
'uid': 'jenkins_build_pagure_100+seed',
|
|
farhaanbukhsh |
a0d3dc |
}
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
output = self.app.post(
|
|
farhaanbukhsh |
a0d3dc |
'/api/0/test4/pull-request/1/flag', data=data, headers=headers)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Aurélien Bompard |
626417 |
data['flag']['date_created'] = '1510742565'
|
|
Aurélien Bompard |
626417 |
data['flag']['pull_request_uid'] = '62b49f00d489452994de5010565fab81'
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
farhaanbukhsh |
a0d3dc |
self.assertDictEqual(
|
|
farhaanbukhsh |
a0d3dc |
data,
|
|
Pierre-Yves Chibon |
c27d61 |
{
|
|
Aurélien Bompard |
626417 |
'flag': {
|
|
Aurélien Bompard |
626417 |
'comment': 'Tests passed',
|
|
Aurélien Bompard |
626417 |
'date_created': '1510742565',
|
|
Aurélien Bompard |
626417 |
'percent': 100,
|
|
Aurélien Bompard |
626417 |
'pull_request_uid': '62b49f00d489452994de5010565fab81',
|
|
Aurélien Bompard |
626417 |
'status': 'success',
|
|
Aurélien Bompard |
626417 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Aurélien Bompard |
626417 |
'user': {
|
|
Aurélien Bompard |
626417 |
'default_email': 'bar@pingou.com',
|
|
Aurélien Bompard |
626417 |
'emails': ['bar@pingou.com', 'foo@pingou.com'],
|
|
Aurélien Bompard |
626417 |
'fullname': 'PY C',
|
|
Aurélien Bompard |
626417 |
'name': 'pingou'},
|
|
Aurélien Bompard |
626417 |
'username': 'Jenkins'},
|
|
Aurélien Bompard |
626417 |
'message': 'Flag updated',
|
|
Pierre-Yves Chibon |
e2c468 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
e2c468 |
'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
|
|
Pierre-Yves Chibon |
e2c468 |
'user': 'pingou'
|
|
Pierre-Yves Chibon |
c27d61 |
}
|
|
farhaanbukhsh |
a0d3dc |
)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
a0d3dc |
# One flag added
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
farhaanbukhsh |
a0d3dc |
request = pagure.lib.search_pull_requests(
|
|
farhaanbukhsh |
a0d3dc |
self.session, project_id=1, requestid=1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(len(request.flags), 1)
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(request.flags[0].comment, 'Tests passed')
|
|
farhaanbukhsh |
a0d3dc |
self.assertEqual(request.flags[0].percent, 100)
|
|
farhaanbukhsh |
a0d3dc |
|
|
farhaanbukhsh |
6d10ff |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
6d10ff |
def test_api_private_repo_pr_close(self, send_email):
|
|
farhaanbukhsh |
6d10ff |
""" Test the api_pull_request_close method of the flask api. """
|
|
farhaanbukhsh |
6d10ff |
send_email.return_value = True
|
|
farhaanbukhsh |
6d10ff |
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['REQUESTS_FOLDER'] = None
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Add private repo
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
6d10ff |
user_id=1, # pingou
|
|
farhaanbukhsh |
6d10ff |
name='test4',
|
|
farhaanbukhsh |
6d10ff |
description='test project description',
|
|
farhaanbukhsh |
6d10ff |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
6d10ff |
private=True,
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
6d10ff |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Add private repo
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
6d10ff |
user_id=1, # pingou
|
|
farhaanbukhsh |
6d10ff |
name='test2',
|
|
farhaanbukhsh |
6d10ff |
description='test project description',
|
|
farhaanbukhsh |
6d10ff |
hook_token='foo_bar',
|
|
farhaanbukhsh |
6d10ff |
private=True,
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Create the pull-request to close
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Farhaan Bukhsh |
839011 |
forked_repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
6d10ff |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
6d10ff |
session=self.session,
|
|
farhaanbukhsh |
6d10ff |
repo_from=forked_repo,
|
|
farhaanbukhsh |
6d10ff |
branch_from='master',
|
|
farhaanbukhsh |
6d10ff |
repo_to=repo,
|
|
farhaanbukhsh |
6d10ff |
branch_to='master',
|
|
farhaanbukhsh |
6d10ff |
title='test pull-request',
|
|
farhaanbukhsh |
6d10ff |
user='pingou',
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(req.title, 'test pull-request')
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Invalid project
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/foo/pull-request/1/close', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
6d10ff |
}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Valid token, wrong project
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test2/pull-request/1/close', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Invalid PR
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test4/pull-request/2/close', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Create a token for foo for this project
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.Token(
|
|
farhaanbukhsh |
6d10ff |
id='foobar_token',
|
|
farhaanbukhsh |
6d10ff |
user_id=2,
|
|
farhaanbukhsh |
6d10ff |
project_id=1,
|
|
farhaanbukhsh |
6d10ff |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
farhaanbukhsh |
6d10ff |
days=30)
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
Farhaan Bukhsh |
5d8713 |
# Allow the token to close PR
|
|
Farhaan Bukhsh |
5d8713 |
acls = pagure.lib.get_acls(self.session)
|
|
Farhaan Bukhsh |
5d8713 |
acl = None
|
|
Farhaan Bukhsh |
5d8713 |
for acl in acls:
|
|
Farhaan Bukhsh |
5d8713 |
if acl.name == 'pull_request_close':
|
|
Farhaan Bukhsh |
5d8713 |
break
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.TokenAcl(
|
|
farhaanbukhsh |
6d10ff |
token_id='foobar_token',
|
|
Farhaan Bukhsh |
5d8713 |
acl_id=acl.id,
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
headers = {'Authorization': 'token foobar_token'}
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# User not admin
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test4/pull-request/1/close', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
6d10ff |
}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Close PR
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test4/pull-request/1/close', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{"message": "Pull-request closed!"}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
@patch('pagure.lib.notify.send_email')
|
|
Patrick Uiterwijk |
02a7cc |
def test_api_private_repo_pr_merge(self, send_email):
|
|
farhaanbukhsh |
6d10ff |
""" Test the api_pull_request_merge method of the flask api. """
|
|
farhaanbukhsh |
6d10ff |
send_email.return_value = True
|
|
farhaanbukhsh |
6d10ff |
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['REQUESTS_FOLDER'] = None
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Add private repo
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
6d10ff |
user_id=1, # pingou
|
|
farhaanbukhsh |
6d10ff |
name='test4',
|
|
farhaanbukhsh |
6d10ff |
description='test project description',
|
|
farhaanbukhsh |
6d10ff |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
6d10ff |
private=True,
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
|
|
Patrick Uiterwijk |
02a7cc |
tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
|
Patrick Uiterwijk |
02a7cc |
tests.create_projects_git(os.path.join(self.path, 'requests'),
|
|
Patrick Uiterwijk |
02a7cc |
bare=True)
|
|
Patrick Uiterwijk |
02a7cc |
tests.add_readme_git_repo(os.path.join(self.path, 'repos',
|
|
Patrick Uiterwijk |
02a7cc |
'test4.git'))
|
|
Patrick Uiterwijk |
02a7cc |
tests.add_commit_git_repo(os.path.join(self.path, 'repos',
|
|
Patrick Uiterwijk |
02a7cc |
'test4.git'),
|
|
Patrick Uiterwijk |
02a7cc |
branch='test')
|
|
farhaanbukhsh |
6d10ff |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
6d10ff |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Add private repo
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
6d10ff |
user_id=1, # pingou
|
|
farhaanbukhsh |
6d10ff |
name='test2',
|
|
farhaanbukhsh |
6d10ff |
description='test project description',
|
|
farhaanbukhsh |
6d10ff |
hook_token='foo_bar',
|
|
farhaanbukhsh |
6d10ff |
private=True,
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Create the pull-request to close
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
Farhaan Bukhsh |
839011 |
forked_repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
6d10ff |
req = pagure.lib.new_pull_request(
|
|
farhaanbukhsh |
6d10ff |
session=self.session,
|
|
farhaanbukhsh |
6d10ff |
repo_from=forked_repo,
|
|
Patrick Uiterwijk |
02a7cc |
branch_from='test',
|
|
farhaanbukhsh |
6d10ff |
repo_to=repo,
|
|
farhaanbukhsh |
6d10ff |
branch_to='master',
|
|
farhaanbukhsh |
6d10ff |
title='test pull-request',
|
|
farhaanbukhsh |
6d10ff |
user='pingou',
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(req.id, 1)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(req.title, 'test pull-request')
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Invalid project
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/foo/pull-request/1/merge', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
6d10ff |
}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Valid token, wrong project
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test2/pull-request/1/merge', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Invalid PR
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test4/pull-request/2/merge', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Create a token for foo for this project
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.Token(
|
|
farhaanbukhsh |
6d10ff |
id='foobar_token',
|
|
farhaanbukhsh |
6d10ff |
user_id=2,
|
|
farhaanbukhsh |
6d10ff |
project_id=1,
|
|
farhaanbukhsh |
6d10ff |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
farhaanbukhsh |
6d10ff |
days=30)
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
Farhaan Bukhsh |
5d8713 |
|
|
Farhaan Bukhsh |
5d8713 |
# Allow the token to merge PR
|
|
Farhaan Bukhsh |
5d8713 |
acls = pagure.lib.get_acls(self.session)
|
|
Farhaan Bukhsh |
5d8713 |
acl = None
|
|
Farhaan Bukhsh |
5d8713 |
for acl in acls:
|
|
Farhaan Bukhsh |
5d8713 |
if acl.name == 'pull_request_merge':
|
|
Farhaan Bukhsh |
5d8713 |
break
|
|
farhaanbukhsh |
6d10ff |
item = pagure.lib.model.TokenAcl(
|
|
farhaanbukhsh |
6d10ff |
token_id='foobar_token',
|
|
Farhaan Bukhsh |
5d8713 |
acl_id=acl.id,
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
self.session.add(item)
|
|
farhaanbukhsh |
6d10ff |
self.session.commit()
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
headers = {'Authorization': 'token foobar_token'}
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# User not admin
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test4/pull-request/1/merge', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
6d10ff |
}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
6d10ff |
|
|
farhaanbukhsh |
6d10ff |
# Merge PR
|
|
farhaanbukhsh |
6d10ff |
output = self.app.post(
|
|
farhaanbukhsh |
6d10ff |
'/api/0/test4/pull-request/1/merge', headers=headers)
|
|
farhaanbukhsh |
6d10ff |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
6d10ff |
self.assertDictEqual(
|
|
farhaanbukhsh |
6d10ff |
data,
|
|
farhaanbukhsh |
6d10ff |
{"message": "Changes merged!"}
|
|
farhaanbukhsh |
6d10ff |
)
|
|
farhaanbukhsh |
fd8d2a |
|
|
farhaanbukhsh |
48869c |
def test_api_private_repo_new_issue(self):
|
|
farhaanbukhsh |
48869c |
""" Test the api_new_issue method of the flask api. """
|
|
farhaanbukhsh |
48869c |
# Add private repo
|
|
farhaanbukhsh |
48869c |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
48869c |
user_id=1, # pingou
|
|
farhaanbukhsh |
48869c |
name='test4',
|
|
farhaanbukhsh |
48869c |
description='test project description',
|
|
farhaanbukhsh |
48869c |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
48869c |
private=True,
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
self.session.add(item)
|
|
farhaanbukhsh |
48869c |
self.session.commit()
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
for repo in ['GIT_FOLDER', 'TICKETS_FOLDER']:
|
|
farhaanbukhsh |
48869c |
# Add a git repo
|
|
farhaanbukhsh |
48869c |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get(repo), 'test4.git')
|
|
farhaanbukhsh |
48869c |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
48869c |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
48869c |
pygit2.init_repository(repo_path, bare=True)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
48869c |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Add private repo
|
|
farhaanbukhsh |
48869c |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
48869c |
user_id=1, # pingou
|
|
farhaanbukhsh |
48869c |
name='test2',
|
|
farhaanbukhsh |
48869c |
description='test project description',
|
|
farhaanbukhsh |
48869c |
hook_token='foo_bar',
|
|
farhaanbukhsh |
48869c |
private=True,
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
self.session.add(item)
|
|
farhaanbukhsh |
48869c |
self.session.commit()
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Valid token, wrong project
|
|
farhaanbukhsh |
48869c |
output = self.app.post('/api/0/test2/new_issue', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# No input
|
|
farhaanbukhsh |
48869c |
output = self.app.post('/api/0/test4/new_issue', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 400)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "EINVALIDREQ",
|
|
Farhaan Bukhsh |
8aa0f5 |
"errors": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"issue_content": ["This field is required."],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": ["This field is required."]
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
})
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
data = {
|
|
farhaanbukhsh |
48869c |
'title': 'test issue',
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Invalid repo
|
|
farhaanbukhsh |
48869c |
output = self.app.post(
|
|
farhaanbukhsh |
48869c |
'/api/0/foo/new_issue', data=data, headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Incomplete request
|
|
farhaanbukhsh |
48869c |
output = self.app.post(
|
|
farhaanbukhsh |
48869c |
'/api/0/test4/new_issue', data=data, headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 400)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "EINVALIDREQ",
|
|
Farhaan Bukhsh |
8aa0f5 |
"errors": {
|
|
Farhaan Bukhsh |
8aa0f5 |
"issue_content": ["This field is required."],
|
|
Farhaan Bukhsh |
8aa0f5 |
"title": ["This field is required."]
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
data = {
|
|
farhaanbukhsh |
48869c |
'title': 'test issue',
|
|
farhaanbukhsh |
48869c |
'issue_content': 'This issue needs attention',
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Valid request
|
|
farhaanbukhsh |
48869c |
output = self.app.post(
|
|
farhaanbukhsh |
48869c |
'/api/0/test4/new_issue', data=data, headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issue']['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issue']['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
Farhaan Bukhsh |
8aa0f5 |
{
|
|
Farhaan Bukhsh |
8aa0f5 |
'issue': FULL_ISSUE_LIST[7],
|
|
Farhaan Bukhsh |
8aa0f5 |
'message': 'Issue created'
|
|
Farhaan Bukhsh |
8aa0f5 |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
Matt Prahl |
47b044 |
def test_api_private_repo_view_issues(self):
|
|
farhaanbukhsh |
48869c |
""" Test the api_view_issues method of the flask api. """
|
|
farhaanbukhsh |
48869c |
self.test_api_private_repo_new_issue()
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Invalid repo
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/foo/issues')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# List all opened issues
|
|
farhaanbukhsh |
48869c |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issues')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
data['issues'][0]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][0]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
610db7 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
610db7 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
610db7 |
data['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
610db7 |
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"args": {
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"author": None,
|
|
Farhaan Bukhsh |
e498a1 |
"milestones": [],
|
|
Farhaan Bukhsh |
e498a1 |
"no_stones": None,
|
|
Matt Prahl |
47b044 |
"order": None,
|
|
Farhaan Bukhsh |
e498a1 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"since": None,
|
|
farhaanbukhsh |
e3c47c |
"status": None,
|
|
farhaanbukhsh |
e3c47c |
"tags": []
|
|
farhaanbukhsh |
e3c47c |
},
|
|
farhaanbukhsh |
e3c47c |
"total_issues": 1,
|
|
farhaanbukhsh |
e3c47c |
"issues": [
|
|
farhaanbukhsh |
e3c47c |
{
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
farhaanbukhsh |
87bf09 |
"closed_at": None,
|
|
farhaanbukhsh |
e3c47c |
"comments": [],
|
|
farhaanbukhsh |
e3c47c |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
farhaanbukhsh |
e3c47c |
"depends": [],
|
|
farhaanbukhsh |
e3c47c |
"id": 1,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
e3c47c |
"priority": None,
|
|
farhaanbukhsh |
e3c47c |
"private": False,
|
|
farhaanbukhsh |
e3c47c |
"status": "Open",
|
|
farhaanbukhsh |
e3c47c |
"tags": [],
|
|
farhaanbukhsh |
e3c47c |
"title": "test issue",
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
Farhaan Bukhsh |
8c7649 |
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
e3c47c |
}
|
|
Pierre-Yves Chibon |
6eccc3 |
],
|
|
Pierre-Yves Chibon |
6eccc3 |
'pagination': {
|
|
Pierre-Yves Chibon |
610db7 |
u'first': u'http://localhost...',
|
|
Pierre-Yves Chibon |
610db7 |
u'last': u'http://localhost...',
|
|
Pierre-Yves Chibon |
6eccc3 |
u'next': None,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'page': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'pages': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'per_page': 20,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'prev': None
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Create private issue
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
48869c |
msg = pagure.lib.new_issue(
|
|
farhaanbukhsh |
48869c |
session=self.session,
|
|
farhaanbukhsh |
48869c |
repo=repo,
|
|
farhaanbukhsh |
48869c |
title='Test issue',
|
|
farhaanbukhsh |
48869c |
content='We should work on this',
|
|
farhaanbukhsh |
48869c |
user='pingou',
|
|
farhaanbukhsh |
48869c |
private=True,
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
self.session.commit()
|
|
farhaanbukhsh |
48869c |
self.assertEqual(msg.title, 'Test issue')
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Private issues are retrieved
|
|
farhaanbukhsh |
48869c |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issues')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
data['issues'][0]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][0]['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
48869c |
data['issues'][1]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][1]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
610db7 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
610db7 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
610db7 |
data['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
610db7 |
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
Farhaan Bukhsh |
8c7649 |
{
|
|
Farhaan Bukhsh |
8c7649 |
"args": {
|
|
Farhaan Bukhsh |
8c7649 |
"assignee": None,
|
|
Farhaan Bukhsh |
8c7649 |
"author": None,
|
|
Farhaan Bukhsh |
e498a1 |
"milestones": [],
|
|
Farhaan Bukhsh |
e498a1 |
"no_stones": None,
|
|
Matt Prahl |
47b044 |
"order": None,
|
|
Farhaan Bukhsh |
e498a1 |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"since": None,
|
|
Farhaan Bukhsh |
8c7649 |
"tags": []
|
|
Farhaan Bukhsh |
8c7649 |
},
|
|
Farhaan Bukhsh |
8c7649 |
"issues": [
|
|
Farhaan Bukhsh |
8c7649 |
{
|
|
Farhaan Bukhsh |
8c7649 |
"assignee": None,
|
|
Farhaan Bukhsh |
8c7649 |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
Farhaan Bukhsh |
8c7649 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8c7649 |
"comments": [],
|
|
Farhaan Bukhsh |
8c7649 |
"content": "We should work on this",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8c7649 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Farhaan Bukhsh |
8c7649 |
"depends": [],
|
|
Farhaan Bukhsh |
8c7649 |
"id": 2,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8c7649 |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"private": True,
|
|
Farhaan Bukhsh |
8c7649 |
"status": "Open",
|
|
Farhaan Bukhsh |
8c7649 |
"tags": [],
|
|
Farhaan Bukhsh |
8c7649 |
"title": "Test issue",
|
|
Farhaan Bukhsh |
8c7649 |
"user": {
|
|
Farhaan Bukhsh |
8c7649 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8c7649 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8c7649 |
}
|
|
Farhaan Bukhsh |
8c7649 |
},
|
|
Farhaan Bukhsh |
8c7649 |
{
|
|
Farhaan Bukhsh |
8c7649 |
"assignee": None,
|
|
Farhaan Bukhsh |
8c7649 |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
Farhaan Bukhsh |
8c7649 |
"closed_at": None,
|
|
Farhaan Bukhsh |
8c7649 |
"comments": [],
|
|
Farhaan Bukhsh |
8c7649 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
Farhaan Bukhsh |
8c7649 |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Farhaan Bukhsh |
8c7649 |
"depends": [],
|
|
Farhaan Bukhsh |
8c7649 |
"id": 1,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
Farhaan Bukhsh |
8c7649 |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"private": False,
|
|
Farhaan Bukhsh |
8c7649 |
"status": "Open",
|
|
Farhaan Bukhsh |
8c7649 |
"tags": [],
|
|
Farhaan Bukhsh |
8c7649 |
"title": "test issue",
|
|
Farhaan Bukhsh |
8c7649 |
"user": {
|
|
Farhaan Bukhsh |
8c7649 |
"fullname": "PY C",
|
|
Farhaan Bukhsh |
8c7649 |
"name": "pingou"
|
|
Farhaan Bukhsh |
8c7649 |
}
|
|
Farhaan Bukhsh |
8c7649 |
}
|
|
Farhaan Bukhsh |
8c7649 |
],
|
|
Pierre-Yves Chibon |
6eccc3 |
'pagination': {
|
|
Pierre-Yves Chibon |
610db7 |
u'first': u'http://localhost...',
|
|
Pierre-Yves Chibon |
610db7 |
u'last': u'http://localhost...',
|
|
Pierre-Yves Chibon |
6eccc3 |
u'next': None,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'page': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'pages': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'per_page': 20,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'prev': None
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
Farhaan Bukhsh |
8c7649 |
"total_issues": 2
|
|
Farhaan Bukhsh |
8c7649 |
}
|
|
Farhaan Bukhsh |
8c7649 |
|
|
farhaanbukhsh |
e3c47c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Access issues authenticated but non-existing token
|
|
farhaanbukhsh |
48869c |
headers = {'Authorization': 'token aaabbbccc'}
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issues', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Access issues authenticated correctly
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issues', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
data['issues'][0]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][0]['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
48869c |
data['issues'][1]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][1]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
610db7 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
610db7 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
610db7 |
data['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
610db7 |
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"args": {
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"author": None,
|
|
Farhaan Bukhsh |
e498a1 |
"milestones": [],
|
|
Farhaan Bukhsh |
e498a1 |
"no_stones": None,
|
|
Matt Prahl |
47b044 |
"order": None,
|
|
Farhaan Bukhsh |
e498a1 |
"priority": None,
|
|
farhaanbukhsh |
e3c47c |
"status": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"since": None,
|
|
farhaanbukhsh |
e3c47c |
"tags": []
|
|
farhaanbukhsh |
48869c |
},
|
|
farhaanbukhsh |
e3c47c |
"issues": [
|
|
farhaanbukhsh |
e3c47c |
{
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
farhaanbukhsh |
87bf09 |
"closed_at": None,
|
|
farhaanbukhsh |
e3c47c |
"comments": [],
|
|
Farhaan Bukhsh |
8c7649 |
"content": "We should work on this",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
farhaanbukhsh |
e3c47c |
"depends": [],
|
|
Farhaan Bukhsh |
8c7649 |
"id": 2,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
e3c47c |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"private": True,
|
|
farhaanbukhsh |
e3c47c |
"status": "Open",
|
|
farhaanbukhsh |
e3c47c |
"tags": [],
|
|
Farhaan Bukhsh |
8c7649 |
"title": "Test issue",
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
e3c47c |
},
|
|
farhaanbukhsh |
e3c47c |
{
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
farhaanbukhsh |
87bf09 |
"closed_at": None,
|
|
farhaanbukhsh |
e3c47c |
"comments": [],
|
|
Farhaan Bukhsh |
8c7649 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
farhaanbukhsh |
e3c47c |
"depends": [],
|
|
Farhaan Bukhsh |
8c7649 |
"id": 1,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
e3c47c |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"private": False,
|
|
farhaanbukhsh |
e3c47c |
"status": "Open",
|
|
farhaanbukhsh |
e3c47c |
"tags": [],
|
|
Farhaan Bukhsh |
8c7649 |
"title": "test issue",
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
e3c47c |
}
|
|
Farhaan Bukhsh |
8c7649 |
],
|
|
Pierre-Yves Chibon |
6eccc3 |
'pagination': {
|
|
Pierre-Yves Chibon |
610db7 |
u'first': u'http://localhost...',
|
|
Pierre-Yves Chibon |
610db7 |
u'last': u'http://localhost...',
|
|
Pierre-Yves Chibon |
6eccc3 |
u'next': None,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'page': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'pages': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'per_page': 20,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'prev': None
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
Farhaan Bukhsh |
8c7649 |
"total_issues": 2
|
|
farhaanbukhsh |
48869c |
}
|
|
Farhaan Bukhsh |
8c7649 |
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# List closed issue
|
|
farhaanbukhsh |
e3c47c |
output = self.app.get(
|
|
farhaanbukhsh |
e3c47c |
'/api/0/test4/issues?status=Closed', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
610db7 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
610db7 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
610db7 |
data['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
610db7 |
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"args": {
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"author": None,
|
|
Farhaan Bukhsh |
e498a1 |
"milestones": [],
|
|
Farhaan Bukhsh |
e498a1 |
"no_stones": None,
|
|
Matt Prahl |
47b044 |
"order": None,
|
|
Farhaan Bukhsh |
e498a1 |
"priority": None,
|
|
farhaanbukhsh |
e3c47c |
"status": "Closed",
|
|
Farhaan Bukhsh |
8aa0f5 |
"since": None,
|
|
farhaanbukhsh |
e3c47c |
"tags": []
|
|
farhaanbukhsh |
e3c47c |
},
|
|
Pierre-Yves Chibon |
6eccc3 |
"issues": [],
|
|
Pierre-Yves Chibon |
6eccc3 |
'pagination': {
|
|
Pierre-Yves Chibon |
610db7 |
u'first': u'http://localhost...',
|
|
Pierre-Yves Chibon |
610db7 |
u'last': u'http://localhost...',
|
|
Pierre-Yves Chibon |
6eccc3 |
u'next': None,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'page': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'pages': 0,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'per_page': 20,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'prev': None
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
farhaanbukhsh |
e3c47c |
"total_issues": 0,
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# List closed issue
|
|
farhaanbukhsh |
e3c47c |
output = self.app.get(
|
|
farhaanbukhsh |
e3c47c |
'/api/0/test4/issues?status=Invalid', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
610db7 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
610db7 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
610db7 |
data['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
610db7 |
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"args": {
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"author": None,
|
|
Farhaan Bukhsh |
e498a1 |
"milestones": [],
|
|
Farhaan Bukhsh |
e498a1 |
"no_stones": None,
|
|
Matt Prahl |
47b044 |
"order": None,
|
|
Farhaan Bukhsh |
e498a1 |
"priority": None,
|
|
farhaanbukhsh |
e3c47c |
"status": "Invalid",
|
|
Farhaan Bukhsh |
8aa0f5 |
"since": None,
|
|
farhaanbukhsh |
e3c47c |
"tags": []
|
|
farhaanbukhsh |
e3c47c |
},
|
|
Pierre-Yves Chibon |
6eccc3 |
"issues": [],
|
|
Pierre-Yves Chibon |
6eccc3 |
'pagination': {
|
|
Pierre-Yves Chibon |
610db7 |
u'first': u'http://localhost...',
|
|
Pierre-Yves Chibon |
610db7 |
u'last': u'http://localhost...',
|
|
Pierre-Yves Chibon |
6eccc3 |
u'next': None,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'page': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'pages': 0,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'per_page': 20,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'prev': None
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
farhaanbukhsh |
e3c47c |
"total_issues": 0,
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# List all issues
|
|
farhaanbukhsh |
e3c47c |
output = self.app.get(
|
|
farhaanbukhsh |
e3c47c |
'/api/0/test4/issues?status=All', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
data['issues'][0]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][0]['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
48869c |
data['issues'][1]['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['issues'][1]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
610db7 |
for k in ['first', 'last']:
|
|
Pierre-Yves Chibon |
610db7 |
self.assertIsNotNone(data['pagination'][k])
|
|
Pierre-Yves Chibon |
610db7 |
data['pagination'][k] = 'http://localhost...'
|
|
Pierre-Yves Chibon |
610db7 |
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
48869c |
"args": {
|
|
farhaanbukhsh |
48869c |
"assignee": None,
|
|
farhaanbukhsh |
48869c |
"author": None,
|
|
Farhaan Bukhsh |
e498a1 |
"milestones": [],
|
|
Farhaan Bukhsh |
e498a1 |
"no_stones": None,
|
|
Matt Prahl |
47b044 |
"order": None,
|
|
Farhaan Bukhsh |
e498a1 |
"priority": None,
|
|
Farhaan Bukhsh |
8aa0f5 |
"since": None,
|
|
farhaanbukhsh |
48869c |
"status": "All",
|
|
farhaanbukhsh |
48869c |
"tags": []
|
|
farhaanbukhsh |
48869c |
},
|
|
farhaanbukhsh |
48869c |
"issues": [
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
48869c |
"assignee": None,
|
|
farhaanbukhsh |
48869c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
farhaanbukhsh |
87bf09 |
"closed_at": None,
|
|
farhaanbukhsh |
48869c |
"comments": [],
|
|
Farhaan Bukhsh |
8c7649 |
"content": "We should work on this",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
48869c |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
farhaanbukhsh |
48869c |
"depends": [],
|
|
Farhaan Bukhsh |
8c7649 |
"id": 2,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
48869c |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"private": True,
|
|
farhaanbukhsh |
48869c |
"status": "Open",
|
|
farhaanbukhsh |
48869c |
"tags": [],
|
|
Farhaan Bukhsh |
8c7649 |
"title": "Test issue",
|
|
farhaanbukhsh |
48869c |
"user": {
|
|
farhaanbukhsh |
48869c |
"fullname": "PY C",
|
|
farhaanbukhsh |
48869c |
"name": "pingou"
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
},
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
48869c |
"assignee": None,
|
|
farhaanbukhsh |
48869c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
farhaanbukhsh |
87bf09 |
"closed_at": None,
|
|
farhaanbukhsh |
48869c |
"comments": [],
|
|
Farhaan Bukhsh |
8c7649 |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
48869c |
"date_created": "1431414800",
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
farhaanbukhsh |
48869c |
"depends": [],
|
|
Farhaan Bukhsh |
8c7649 |
"id": 1,
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
48869c |
"priority": None,
|
|
Farhaan Bukhsh |
8c7649 |
"private": False,
|
|
farhaanbukhsh |
48869c |
"status": "Open",
|
|
farhaanbukhsh |
48869c |
"tags": [],
|
|
Farhaan Bukhsh |
8c7649 |
"title": "test issue",
|
|
farhaanbukhsh |
48869c |
"user": {
|
|
farhaanbukhsh |
48869c |
"fullname": "PY C",
|
|
farhaanbukhsh |
48869c |
"name": "pingou"
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
],
|
|
Pierre-Yves Chibon |
6eccc3 |
'pagination': {
|
|
Pierre-Yves Chibon |
610db7 |
u'first': u'http://localhost...',
|
|
Pierre-Yves Chibon |
610db7 |
u'last': u'http://localhost...',
|
|
Pierre-Yves Chibon |
6eccc3 |
u'next': None,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'page': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'pages': 1,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'per_page': 20,
|
|
Pierre-Yves Chibon |
6eccc3 |
u'prev': None
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
Farhaan Bukhsh |
8c7649 |
"total_issues": 2
|
|
farhaanbukhsh |
48869c |
}
|
|
Farhaan Bukhsh |
8c7649 |
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
def test_api_pivate_repo_view_issue(self):
|
|
farhaanbukhsh |
48869c |
""" Test the api_view_issue method of the flask api. """
|
|
farhaanbukhsh |
48869c |
self.test_api_private_repo_new_issue()
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Invalid repo
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/foo/issue/1')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Invalid issue for this repo
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issue/1')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Un-authorized user
|
|
farhaanbukhsh |
48869c |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issue/1')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Valid issue
|
|
farhaanbukhsh |
48869c |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issue/1')
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
data['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
Farhaan Bukhsh |
8c7649 |
"closed_at": None,
|
|
farhaanbukhsh |
e3c47c |
"comments": [],
|
|
farhaanbukhsh |
e3c47c |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1431414800",
|
|
farhaanbukhsh |
e3c47c |
"depends": [],
|
|
farhaanbukhsh |
e3c47c |
"id": 1,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
e3c47c |
"priority": None,
|
|
farhaanbukhsh |
e3c47c |
"private": False,
|
|
farhaanbukhsh |
e3c47c |
"status": "Open",
|
|
farhaanbukhsh |
e3c47c |
"tags": [],
|
|
farhaanbukhsh |
e3c47c |
"title": "test issue",
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
48869c |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
headers = {'Authorization': 'token aaabbbccc'}
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Access issue authenticated but non-existing token
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issue/1', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
48869c |
|
|
farhaanbukhsh |
48869c |
# Access issue authenticated correctly
|
|
farhaanbukhsh |
48869c |
output = self.app.get('/api/0/test4/issue/1', headers=headers)
|
|
farhaanbukhsh |
48869c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
48869c |
data['date_created'] = '1431414800'
|
|
Farhaan Bukhsh |
8aa0f5 |
data['last_updated'] = '1431414800'
|
|
farhaanbukhsh |
48869c |
self.assertDictEqual(
|
|
farhaanbukhsh |
48869c |
data,
|
|
farhaanbukhsh |
48869c |
{
|
|
farhaanbukhsh |
e3c47c |
"assignee": None,
|
|
farhaanbukhsh |
e3c47c |
"blocks": [],
|
|
Farhaan Bukhsh |
8c7649 |
"close_status": None,
|
|
Farhaan Bukhsh |
8c7649 |
"closed_at": None,
|
|
farhaanbukhsh |
e3c47c |
"comments": [],
|
|
farhaanbukhsh |
e3c47c |
"content": "This issue needs attention",
|
|
Farhaan Bukhsh |
8c7649 |
"custom_fields": [],
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1431414800",
|
|
farhaanbukhsh |
e3c47c |
"depends": [],
|
|
farhaanbukhsh |
e3c47c |
"id": 1,
|
|
Farhaan Bukhsh |
8aa0f5 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
2521db |
"milestone": None,
|
|
farhaanbukhsh |
e3c47c |
"priority": None,
|
|
farhaanbukhsh |
e3c47c |
"private": False,
|
|
farhaanbukhsh |
e3c47c |
"status": "Open",
|
|
farhaanbukhsh |
e3c47c |
"tags": [],
|
|
farhaanbukhsh |
e3c47c |
"title": "test issue",
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
farhaanbukhsh |
e3c47c |
}
|
|
Farhaan Bukhsh |
8aa0f5 |
|
|
farhaanbukhsh |
48869c |
}
|
|
farhaanbukhsh |
48869c |
)
|
|
farhaanbukhsh |
fd8d2a |
|
|
Aurélien Bompard |
626417 |
@patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
|
|
farhaanbukhsh |
f15bdf |
def test_api_private_repo_change_status_issue(self):
|
|
farhaanbukhsh |
bf482e |
""" Test the api_change_status_issue method of the flask api. """
|
|
farhaanbukhsh |
bf482e |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
bf482e |
user_id=1, # pingou
|
|
farhaanbukhsh |
bf482e |
name='test4',
|
|
farhaanbukhsh |
bf482e |
description='test project description',
|
|
farhaanbukhsh |
bf482e |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
bf482e |
private=True,
|
|
farhaanbukhsh |
bf482e |
)
|
|
Farhaan Bukhsh |
77ab9e |
item.close_status = ['Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
|
|
farhaanbukhsh |
bf482e |
self.session.add(item)
|
|
farhaanbukhsh |
bf482e |
self.session.commit()
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
for repo in ['GIT_FOLDER', 'TICKETS_FOLDER']:
|
|
farhaanbukhsh |
bf482e |
# Add a git repo
|
|
farhaanbukhsh |
bf482e |
repo_path = os.path.join(
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config.get(repo), 'test4.git')
|
|
farhaanbukhsh |
bf482e |
if not os.path.exists(repo_path):
|
|
farhaanbukhsh |
bf482e |
os.makedirs(repo_path)
|
|
farhaanbukhsh |
bf482e |
pygit2.init_repository(repo_path, bare=True)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
bf482e |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# Invalid project
|
|
farhaanbukhsh |
bf482e |
output = self.app.post('/api/0/foo/issue/1/status', headers=headers)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
bf482e |
self.assertDictEqual(
|
|
farhaanbukhsh |
bf482e |
data,
|
|
farhaanbukhsh |
bf482e |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# Valid token, wrong project
|
|
farhaanbukhsh |
bf482e |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
e3c47c |
output = self.app.post(
|
|
farhaanbukhsh |
e3c47c |
'/api/0/test2/issue/1/status', headers=headers)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
bf482e |
self.assertDictEqual(
|
|
farhaanbukhsh |
bf482e |
data,
|
|
farhaanbukhsh |
bf482e |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# No input
|
|
farhaanbukhsh |
bf482e |
output = self.app.post('/api/0/test4/issue/1/status', headers=headers)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
bf482e |
self.assertDictEqual(
|
|
farhaanbukhsh |
bf482e |
data,
|
|
farhaanbukhsh |
bf482e |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Issue not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOISSUE",
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# Create normal issue
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
bf482e |
msg = pagure.lib.new_issue(
|
|
farhaanbukhsh |
bf482e |
session=self.session,
|
|
farhaanbukhsh |
bf482e |
repo=repo,
|
|
farhaanbukhsh |
bf482e |
title='Test issue #1',
|
|
farhaanbukhsh |
bf482e |
content='We should work on this',
|
|
farhaanbukhsh |
bf482e |
user='pingou',
|
|
farhaanbukhsh |
bf482e |
private=False,
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
self.session.commit()
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(msg.title, 'Test issue #1')
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# Check status before
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
bf482e |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(issue.status, 'Open')
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
data = {
|
|
farhaanbukhsh |
bf482e |
'title': 'test issue',
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
bf482e |
# Incomplete request
|
|
farhaanbukhsh |
bf482e |
output = self.app.post(
|
|
farhaanbukhsh |
bf482e |
'/api/0/test4/issue/1/status', data=data, headers=headers)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(output.status_code, 400)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
bf482e |
self.assertDictEqual(
|
|
farhaanbukhsh |
bf482e |
data,
|
|
farhaanbukhsh |
bf482e |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "EINVALIDREQ",
|
|
Farhaan Bukhsh |
8aa0f5 |
"errors": {"status": ["Not a valid choice"]}
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# No change
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
bf482e |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(issue.status, 'Open')
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
data = {
|
|
farhaanbukhsh |
bf482e |
'status': 'Open',
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# Valid request but no change
|
|
farhaanbukhsh |
bf482e |
output = self.app.post(
|
|
farhaanbukhsh |
bf482e |
'/api/0/test4/issue/1/status', data=data, headers=headers)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
bf482e |
self.assertDictEqual(
|
|
farhaanbukhsh |
bf482e |
data,
|
|
farhaanbukhsh |
bf482e |
{'message': 'No changes'}
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# No change
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
bf482e |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(issue.status, 'Open')
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
data = {
|
|
farhaanbukhsh |
bf482e |
'status': 'Fixed',
|
|
farhaanbukhsh |
bf482e |
}
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
bf482e |
# Valid request
|
|
farhaanbukhsh |
bf482e |
output = self.app.post(
|
|
farhaanbukhsh |
bf482e |
'/api/0/test4/issue/1/status', data=data, headers=headers)
|
|
farhaanbukhsh |
bf482e |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
bf482e |
self.assertDictEqual(
|
|
farhaanbukhsh |
bf482e |
data,
|
|
Farhaan Bukhsh |
40e9bd |
{'message':[
|
|
Farhaan Bukhsh |
40e9bd |
'Issue status updated to: Closed (was: Open)',
|
|
Farhaan Bukhsh |
40e9bd |
'Issue close_status updated to: Fixed'
|
|
Farhaan Bukhsh |
40e9bd |
]}
|
|
farhaanbukhsh |
bf482e |
)
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
f15bdf |
@patch('pagure.lib.git.update_git')
|
|
farhaanbukhsh |
f15bdf |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
f15bdf |
def test_api_private_repo_comment_issue(self, p_send_email, p_ugt):
|
|
farhaanbukhsh |
f15bdf |
""" Test the api_comment_issue method of the flask api. """
|
|
farhaanbukhsh |
f15bdf |
p_send_email.return_value = True
|
|
farhaanbukhsh |
f15bdf |
p_ugt.return_value = True
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
item = pagure.lib.model.Project(
|
|
farhaanbukhsh |
f15bdf |
user_id=1, # pingou
|
|
farhaanbukhsh |
f15bdf |
name='test4',
|
|
farhaanbukhsh |
f15bdf |
description='test project description',
|
|
farhaanbukhsh |
f15bdf |
hook_token='aaabbbeeeceee',
|
|
farhaanbukhsh |
f15bdf |
private=True,
|
|
farhaanbukhsh |
f15bdf |
)
|
|
farhaanbukhsh |
f15bdf |
self.session.add(item)
|
|
farhaanbukhsh |
f15bdf |
self.session.commit()
|
|
farhaanbukhsh |
f15bdf |
tests.create_tokens(self.session)
|
|
farhaanbukhsh |
f15bdf |
tests.create_tokens_acl(self.session)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# Invalid project
|
|
farhaanbukhsh |
f15bdf |
output = self.app.post('/api/0/foo/issue/1/comment', headers=headers)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
f15bdf |
self.assertDictEqual(
|
|
farhaanbukhsh |
f15bdf |
data,
|
|
farhaanbukhsh |
f15bdf |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Project not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOPROJECT",
|
|
farhaanbukhsh |
f15bdf |
}
|
|
farhaanbukhsh |
f15bdf |
)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# Invalid token, right project
|
|
farhaanbukhsh |
f15bdf |
headers = {'Authorization': 'token aaabbbccc'}
|
|
farhaanbukhsh |
f15bdf |
output = self.app.post('/api/0/test4/issue/1/comment', headers=headers)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(output.status_code, 401)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
20753d |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
farhaanbukhsh |
f15bdf |
# No input
|
|
farhaanbukhsh |
f15bdf |
output = self.app.post('/api/0/test4/issue/1/comment', headers=headers)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
f15bdf |
self.assertDictEqual(
|
|
farhaanbukhsh |
f15bdf |
data,
|
|
farhaanbukhsh |
f15bdf |
{
|
|
farhaanbukhsh |
e3c47c |
"error": "Issue not found",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "ENOISSUE",
|
|
farhaanbukhsh |
f15bdf |
}
|
|
farhaanbukhsh |
f15bdf |
)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# Create normal issue
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
f15bdf |
msg = pagure.lib.new_issue(
|
|
farhaanbukhsh |
f15bdf |
session=self.session,
|
|
farhaanbukhsh |
f15bdf |
repo=repo,
|
|
farhaanbukhsh |
f15bdf |
title='Test issue #1',
|
|
farhaanbukhsh |
f15bdf |
content='We should work on this',
|
|
farhaanbukhsh |
f15bdf |
user='pingou',
|
|
farhaanbukhsh |
f15bdf |
private=False,
|
|
Pierre-Yves Chibon |
0fb13b |
issue_uid='aaabbbccc1',
|
|
farhaanbukhsh |
f15bdf |
)
|
|
farhaanbukhsh |
f15bdf |
self.session.commit()
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(msg.title, 'Test issue #1')
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# Check comments before
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
f15bdf |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(len(issue.comments), 0)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
data = {
|
|
farhaanbukhsh |
f15bdf |
'title': 'test issue',
|
|
farhaanbukhsh |
f15bdf |
}
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# Incomplete request
|
|
farhaanbukhsh |
f15bdf |
output = self.app.post(
|
|
farhaanbukhsh |
f15bdf |
'/api/0/test4/issue/1/comment', data=data, headers=headers)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(output.status_code, 400)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
f15bdf |
self.assertDictEqual(
|
|
farhaanbukhsh |
f15bdf |
data,
|
|
farhaanbukhsh |
f15bdf |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
farhaanbukhsh |
e3c47c |
"error_code": "EINVALIDREQ",
|
|
Farhaan Bukhsh |
8aa0f5 |
"errors": {"comment": ["This field is required."]}
|
|
farhaanbukhsh |
f15bdf |
}
|
|
farhaanbukhsh |
f15bdf |
)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# No change
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
f15bdf |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(issue.status, 'Open')
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
data = {
|
|
farhaanbukhsh |
f15bdf |
'comment': 'This is a very interesting question',
|
|
farhaanbukhsh |
f15bdf |
}
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# Valid request
|
|
farhaanbukhsh |
f15bdf |
output = self.app.post(
|
|
farhaanbukhsh |
f15bdf |
'/api/0/test4/issue/1/comment', data=data, headers=headers)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
farhaanbukhsh |
f15bdf |
self.assertDictEqual(
|
|
farhaanbukhsh |
f15bdf |
data,
|
|
Pierre-Yves Chibon |
e2c468 |
{'message': 'Comment added',
|
|
Pierre-Yves Chibon |
e2c468 |
'avatar_url': 'https://seccdn.libravatar.org/avatar/...',
|
|
Pierre-Yves Chibon |
e2c468 |
'user': 'pingou'}
|
|
farhaanbukhsh |
f15bdf |
)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
f15bdf |
# One comment added
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Farhaan Bukhsh |
839011 |
repo = pagure.lib._get_project(self.session, 'test4')
|
|
farhaanbukhsh |
f15bdf |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
farhaanbukhsh |
f15bdf |
self.assertEqual(len(issue.comments), 1)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
d9fa21 |
@patch('pagure.lib.git.update_git')
|
|
farhaanbukhsh |
d9fa21 |
@patch('pagure.lib.notify.send_email')
|
|
farhaanbukhsh |
d9fa21 |
def test_api_view_issue_comment(self, p_send_email, p_ugt):
|
|
farhaanbukhsh |
d9fa21 |
""" Test the api_view_issue_comment endpoint. """
|
|
farhaanbukhsh |
d9fa21 |
p_send_email.return_value = True
|
|
farhaanbukhsh |
d9fa21 |
p_ugt.return_value = True
|
|
farhaanbukhsh |
d9fa21 |
|
|
farhaanbukhsh |
d9fa21 |
self.test_api_private_repo_comment_issue()
|
|
farhaanbukhsh |
d9fa21 |
|
|
farhaanbukhsh |
d9fa21 |
# View a comment that does not exist
|
|
farhaanbukhsh |
d9fa21 |
output = self.app.get('/api/0/foo/issue/100/comment/2')
|
|
farhaanbukhsh |
d9fa21 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
d9fa21 |
|
|
farhaanbukhsh |
d9fa21 |
# Issue exists but not the comment
|
|
farhaanbukhsh |
d9fa21 |
output = self.app.get('/api/0/test/issue/1/comment/2')
|
|
farhaanbukhsh |
d9fa21 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
d9fa21 |
|
|
farhaanbukhsh |
d9fa21 |
# Issue and comment exists
|
|
farhaanbukhsh |
d9fa21 |
output = self.app.get('/api/0/test/issue/1/comment/1')
|
|
farhaanbukhsh |
d9fa21 |
self.assertEqual(output.status_code, 404)
|
|
farhaanbukhsh |
d9fa21 |
|
|
farhaanbukhsh |
d9fa21 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
farhaanbukhsh |
e3c47c |
output = self.app.get('/api/0/test4/issue/1/comment/1')
|
|
farhaanbukhsh |
d9fa21 |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
d9fa21 |
data['date_created'] = '1435821770'
|
|
farhaanbukhsh |
d9fa21 |
data["comment_date"] = "2015-07-02 09:22"
|
|
farhaanbukhsh |
d9fa21 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
farhaanbukhsh |
d9fa21 |
self.assertDictEqual(
|
|
farhaanbukhsh |
d9fa21 |
data,
|
|
farhaanbukhsh |
d9fa21 |
{
|
|
farhaanbukhsh |
e3c47c |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
farhaanbukhsh |
e3c47c |
"comment": "This is a very interesting question",
|
|
farhaanbukhsh |
e3c47c |
"comment_date": "2015-07-02 09:22",
|
|
Farhaan Bukhsh |
8aa0f5 |
"notification": False,
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1435821770",
|
|
farhaanbukhsh |
e3c47c |
"edited_on": None,
|
|
farhaanbukhsh |
e3c47c |
"editor": None,
|
|
farhaanbukhsh |
e3c47c |
"id": 1,
|
|
farhaanbukhsh |
e3c47c |
"parent": None,
|
|
Lubomír Sedlář |
59889e |
"reactions": {},
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
d9fa21 |
}
|
|
farhaanbukhsh |
d9fa21 |
)
|
|
farhaanbukhsh |
d9fa21 |
|
|
farhaanbukhsh |
e3c47c |
# Issue and comment exists, using UID
|
|
Pierre-Yves Chibon |
0fb13b |
output = self.app.get('/api/0/test4/issue/aaabbbccc1/comment/1')
|
|
farhaanbukhsh |
e3c47c |
self.assertEqual(output.status_code, 200)
|
|
farhaanbukhsh |
c87985 |
data = json.loads(output.get_data(as_text=True))
|
|
farhaanbukhsh |
e3c47c |
data['date_created'] = '1435821770'
|
|
farhaanbukhsh |
e3c47c |
data["comment_date"] = "2015-07-02 09:22"
|
|
farhaanbukhsh |
e3c47c |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
farhaanbukhsh |
e3c47c |
self.assertDictEqual(
|
|
farhaanbukhsh |
e3c47c |
data,
|
|
farhaanbukhsh |
e3c47c |
{
|
|
farhaanbukhsh |
e3c47c |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
farhaanbukhsh |
e3c47c |
"comment": "This is a very interesting question",
|
|
farhaanbukhsh |
e3c47c |
"comment_date": "2015-07-02 09:22",
|
|
Farhaan Bukhsh |
8aa0f5 |
"notification": False,
|
|
farhaanbukhsh |
e3c47c |
"date_created": "1435821770",
|
|
farhaanbukhsh |
e3c47c |
"edited_on": None,
|
|
farhaanbukhsh |
e3c47c |
"editor": None,
|
|
farhaanbukhsh |
e3c47c |
"id": 1,
|
|
farhaanbukhsh |
e3c47c |
"parent": None,
|
|
Lubomír Sedlář |
59889e |
"reactions": {},
|
|
farhaanbukhsh |
e3c47c |
"user": {
|
|
farhaanbukhsh |
e3c47c |
"fullname": "PY C",
|
|
farhaanbukhsh |
e3c47c |
"name": "pingou"
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
e3c47c |
}
|
|
farhaanbukhsh |
e3c47c |
)
|
|
farhaanbukhsh |
f15bdf |
|
|
farhaanbukhsh |
bf482e |
|
|
farhaanbukhsh |
1df65f |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|