|
Pierre-Yves Chibon |
f15f18 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
"""
|
|
Pierre-Yves Chibon |
6882b8 |
(c) 2015-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
Authors:
|
|
Pierre-Yves Chibon |
f15f18 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Karsten Hopp |
be01e8 |
Karsten Hopp <karsten@redhat.com></karsten@redhat.com>
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
"""
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Aurélien Bompard |
626417 |
from __future__ import unicode_literals
|
|
Aurélien Bompard |
626417 |
|
|
Pierre-Yves Chibon |
f15f18 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
f15f18 |
import pkg_resources
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
6ffde7 |
import datetime
|
|
Pierre-Yves Chibon |
f15f18 |
import json
|
|
Pierre-Yves Chibon |
f15f18 |
import unittest
|
|
Pierre-Yves Chibon |
f15f18 |
import shutil
|
|
Pierre-Yves Chibon |
f15f18 |
import sys
|
|
Pierre-Yves Chibon |
f15f18 |
import tempfile
|
|
Pierre-Yves Chibon |
f15f18 |
import os
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
import pygit2
|
|
Aurélien Bompard |
00115d |
from celery.result import EagerResult
|
|
Matt Prahl |
489ad1 |
from mock import patch, Mock
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
f15f18 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
b130e5 |
import pagure.flask_app
|
|
Pierre-Yves Chibon |
f15f18 |
import pagure.lib
|
|
Pierre-Yves Chibon |
f15f18 |
import tests
|
|
Pierre-Yves Chibon |
27a73d |
from pagure.lib.repo import PagureRepo
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
class PagureFlaskApiProjecttests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
f15f18 |
""" Tests for the flask API of pagure for issue """
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Aurélien Bompard |
24a837 |
def setUp(self):
|
|
Aurélien Bompard |
24a837 |
super(PagureFlaskApiProjecttests, self).setUp()
|
|
Aurélien Bompard |
24a837 |
self.gga_patcher = patch(
|
|
Aurélien Bompard |
24a837 |
'pagure.lib.tasks.generate_gitolite_acls.delay')
|
|
Aurélien Bompard |
24a837 |
self.mock_gen_acls = self.gga_patcher.start()
|
|
Aurélien Bompard |
00115d |
task_result = EagerResult('abc-1234', True, "SUCCESS")
|
|
Aurélien Bompard |
24a837 |
self.mock_gen_acls.return_value = task_result
|
|
Aurélien Bompard |
24a837 |
|
|
Aurélien Bompard |
24a837 |
def tearDown(self):
|
|
Aurélien Bompard |
24a837 |
self.gga_patcher.stop()
|
|
Aurélien Bompard |
24a837 |
super(PagureFlaskApiProjecttests, self).tearDown()
|
|
Aurélien Bompard |
24a837 |
|
|
Pierre-Yves Chibon |
f15f18 |
def test_api_git_tags(self):
|
|
Pierre-Yves Chibon |
f15f18 |
""" Test the api_git_tags method of the flask api. """
|
|
Pierre-Yves Chibon |
f15f18 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
# Create a git repo to play with
|
|
Jeremy Cline |
20109f |
gitrepo = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
f15f18 |
repo = pygit2.init_repository(gitrepo, bare=True)
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
newpath = tempfile.mkdtemp(prefix='pagure-fork-test')
|
|
Pierre-Yves Chibon |
f15f18 |
repopath = os.path.join(newpath, 'test')
|
|
Pierre-Yves Chibon |
f15f18 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
# Create a file in that git repo
|
|
Pierre-Yves Chibon |
f15f18 |
with open(os.path.join(repopath, 'sources'), 'w') as stream:
|
|
Pierre-Yves Chibon |
f15f18 |
stream.write('foo\n bar')
|
|
Pierre-Yves Chibon |
f15f18 |
clone_repo.index.add('sources')
|
|
Pierre-Yves Chibon |
f15f18 |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
# Commits the files added
|
|
Pierre-Yves Chibon |
f15f18 |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
f15f18 |
author = pygit2.Signature(
|
|
Pierre-Yves Chibon |
f15f18 |
'Alice Author', 'alice@authors.tld')
|
|
Pierre-Yves Chibon |
f15f18 |
committer = pygit2.Signature(
|
|
Pierre-Yves Chibon |
f15f18 |
'Cecil Committer', 'cecil@committers.tld')
|
|
Pierre-Yves Chibon |
f15f18 |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
f15f18 |
'refs/heads/master', # the name of the reference to update
|
|
Pierre-Yves Chibon |
f15f18 |
author,
|
|
Pierre-Yves Chibon |
f15f18 |
committer,
|
|
Pierre-Yves Chibon |
f15f18 |
'Add sources file for testing',
|
|
Pierre-Yves Chibon |
f15f18 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
f15f18 |
tree,
|
|
Pierre-Yves Chibon |
f15f18 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
f15f18 |
[]
|
|
Pierre-Yves Chibon |
f15f18 |
)
|
|
Pierre-Yves Chibon |
f15f18 |
refname = 'refs/heads/master:refs/heads/master'
|
|
Pierre-Yves Chibon |
f15f18 |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
27a73d |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
# Tag our first commit
|
|
Pierre-Yves Chibon |
f15f18 |
first_commit = repo.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
f15f18 |
tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0)
|
|
Pierre-Yves Chibon |
f15f18 |
repo.create_tag(
|
|
Pierre-Yves Chibon |
f15f18 |
"0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
|
|
Pierre-Yves Chibon |
f15f18 |
"Release 0.0.1")
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
0197ec |
# Check tags
|
|
Pierre-Yves Chibon |
f15f18 |
output = self.app.get('/api/0/test/git/tags')
|
|
Pierre-Yves Chibon |
f15f18 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f15f18 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f15f18 |
data,
|
|
Pierre-Yves Chibon |
226628 |
{'tags': ['0.0.1'], 'total_tags': 1}
|
|
Pierre-Yves Chibon |
f15f18 |
)
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
06f5ad |
# Check tags with commits
|
|
Pierre-Yves Chibon |
06f5ad |
output = self.app.get('/api/0/test/git/tags?with_commits=True')
|
|
Pierre-Yves Chibon |
06f5ad |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
06f5ad |
data['tags']['0.0.1'] = 'bb8fa2aa199da08d6085e1c9badc3d83d188d38c'
|
|
Pierre-Yves Chibon |
06f5ad |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
06f5ad |
data,
|
|
Pierre-Yves Chibon |
06f5ad |
{
|
|
Aurélien Bompard |
626417 |
'tags': {'0.0.1': 'bb8fa2aa199da08d6085e1c9badc3d83d188d38c'},
|
|
Aurélien Bompard |
626417 |
'total_tags': 1}
|
|
Pierre-Yves Chibon |
06f5ad |
)
|
|
Pierre-Yves Chibon |
06f5ad |
|
|
Pierre-Yves Chibon |
62ffe0 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
62ffe0 |
|
|
Matt Prahl |
cd940d |
def test_api_git_branches(self):
|
|
Matt Prahl |
cd940d |
""" Test the api_git_branches method of the flask api. """
|
|
Matt Prahl |
cd940d |
# Create a git repo to add branches to
|
|
Matt Prahl |
cd940d |
tests.create_projects(self.session)
|
|
Matt Prahl |
cd940d |
repo_path = os.path.join(self.path, 'repos', 'test.git')
|
|
Matt Prahl |
cd940d |
tests.add_content_git_repo(repo_path)
|
|
Matt Prahl |
cd940d |
new_repo_path = tempfile.mkdtemp(prefix='pagure-api-git-branches-test')
|
|
Matt Prahl |
cd940d |
clone_repo = pygit2.clone_repository(repo_path, new_repo_path)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
cd940d |
# Create two other branches based on master
|
|
Matt Prahl |
cd940d |
for branch in ['pats-win-49', 'pats-win-51']:
|
|
Matt Prahl |
cd940d |
clone_repo.create_branch(branch, clone_repo.head.get_object())
|
|
Matt Prahl |
cd940d |
refname = 'refs/heads/{0}:refs/heads/{0}'.format(branch)
|
|
Matt Prahl |
cd940d |
PagureRepo.push(clone_repo.remotes[0], refname)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
cd940d |
# Check that the branches show up on the API
|
|
Matt Prahl |
cd940d |
output = self.app.get('/api/0/test/git/branches')
|
|
Matt Prahl |
cd940d |
# Delete the cloned git repo after the API call
|
|
Matt Prahl |
cd940d |
shutil.rmtree(new_repo_path)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
cd940d |
# Verify the API data
|
|
Matt Prahl |
cd940d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
cd940d |
self.assertDictEqual(
|
|
Matt Prahl |
cd940d |
data,
|
|
Matt Prahl |
cd940d |
{
|
|
Matt Prahl |
cd940d |
'branches': ['master', 'pats-win-49', 'pats-win-51'],
|
|
Matt Prahl |
cd940d |
'total_branches': 3
|
|
Matt Prahl |
cd940d |
}
|
|
Matt Prahl |
cd940d |
)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
cd940d |
def test_api_git_branches_empty_repo(self):
|
|
Matt Prahl |
cd940d |
""" Test the api_git_branches method of the flask api when the repo is
|
|
Matt Prahl |
cd940d |
empty.
|
|
Matt Prahl |
cd940d |
"""
|
|
Matt Prahl |
cd940d |
# Create a git repo without any branches
|
|
Matt Prahl |
cd940d |
tests.create_projects(self.session)
|
|
Matt Prahl |
cd940d |
repo_base_path = os.path.join(self.path, 'repos')
|
|
Matt Prahl |
cd940d |
tests.create_projects_git(repo_base_path)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
cd940d |
# Check that no branches show up on the API
|
|
Matt Prahl |
cd940d |
output = self.app.get('/api/0/test/git/branches')
|
|
Matt Prahl |
cd940d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
cd940d |
self.assertDictEqual(
|
|
Matt Prahl |
cd940d |
data,
|
|
Matt Prahl |
cd940d |
{
|
|
Matt Prahl |
cd940d |
'branches': [],
|
|
Matt Prahl |
cd940d |
'total_branches': 0
|
|
Matt Prahl |
cd940d |
}
|
|
Matt Prahl |
cd940d |
)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
cd940d |
def test_api_git_branches_no_repo(self):
|
|
Matt Prahl |
cd940d |
""" Test the api_git_branches method of the flask api when there is no
|
|
Matt Prahl |
cd940d |
repo on a project.
|
|
Matt Prahl |
cd940d |
"""
|
|
Matt Prahl |
cd940d |
tests.create_projects(self.session)
|
|
Matt Prahl |
cd940d |
output = self.app.get('/api/0/test/git/branches')
|
|
Matt Prahl |
cd940d |
self.assertEqual(output.status_code, 404)
|
|
Matt Prahl |
cd940d |
|
|
Matt Prahl |
ad5147 |
def test_api_git_urls(self):
|
|
Matt Prahl |
ad5147 |
""" Test the api_project_git_urls method of the flask api.
|
|
Matt Prahl |
ad5147 |
"""
|
|
Matt Prahl |
ad5147 |
tests.create_projects(self.session)
|
|
Matt Prahl |
ad5147 |
output = self.app.get('/api/0/test/git/urls')
|
|
Matt Prahl |
ad5147 |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
ad5147 |
expected_rv = {
|
|
Matt Prahl |
ad5147 |
'urls': {
|
|
Neal Gompa |
9c34c4 |
'git': 'git://localhost.localdomain/test.git',
|
|
Neal Gompa |
9c34c4 |
'ssh': 'ssh://git@localhost.localdomain/test.git'
|
|
Matt Prahl |
ad5147 |
},
|
|
Matt Prahl |
ad5147 |
'total_urls': 2
|
|
Matt Prahl |
ad5147 |
}
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
ad5147 |
self.assertDictEqual(data, expected_rv)
|
|
Matt Prahl |
ad5147 |
|
|
Matt Prahl |
ad5147 |
def test_api_git_urls_no_project(self):
|
|
Matt Prahl |
ad5147 |
""" Test the api_project_git_urls method of the flask api when there is
|
|
Matt Prahl |
ad5147 |
no project.
|
|
Matt Prahl |
ad5147 |
"""
|
|
Matt Prahl |
ad5147 |
output = self.app.get('/api/0/test1234/git/urls')
|
|
Matt Prahl |
ad5147 |
self.assertEqual(output.status_code, 404)
|
|
Matt Prahl |
ad5147 |
expected_rv = {
|
|
Matt Prahl |
ad5147 |
'error': 'Project not found',
|
|
Matt Prahl |
ad5147 |
'error_code': 'ENOPROJECT'
|
|
Matt Prahl |
ad5147 |
}
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
ad5147 |
self.assertDictEqual(data, expected_rv)
|
|
Matt Prahl |
ad5147 |
|
|
Pierre-Yves Chibon |
b130e5 |
@patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
|
|
Matt Prahl |
ad5147 |
def test_api_git_urls_private_project(self):
|
|
Matt Prahl |
ad5147 |
""" Test the api_project_git_urls method of the flask api when the
|
|
Matt Prahl |
ad5147 |
project is private.
|
|
Matt Prahl |
ad5147 |
"""
|
|
Matt Prahl |
ad5147 |
tests.create_projects(self.session)
|
|
Matt Prahl |
ad5147 |
tests.create_tokens(self.session)
|
|
Matt Prahl |
ad5147 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd')
|
|
Matt Prahl |
ad5147 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Matt Prahl |
ad5147 |
|
|
Matt Prahl |
ad5147 |
test_project = pagure.lib._get_project(self.session, 'test')
|
|
Matt Prahl |
ad5147 |
test_project.private = True
|
|
Matt Prahl |
ad5147 |
self.session.add(test_project)
|
|
Matt Prahl |
ad5147 |
self.session.commit()
|
|
Matt Prahl |
ad5147 |
|
|
Matt Prahl |
ad5147 |
output = self.app.get('/api/0/test/git/urls', headers=headers)
|
|
Matt Prahl |
ad5147 |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
ad5147 |
expected_rv = {
|
|
Matt Prahl |
ad5147 |
'urls': {
|
|
Neal Gompa |
9c34c4 |
'git': 'git://localhost.localdomain/test.git',
|
|
Neal Gompa |
9c34c4 |
'ssh': 'ssh://git@localhost.localdomain/test.git'
|
|
Matt Prahl |
ad5147 |
},
|
|
Matt Prahl |
ad5147 |
'total_urls': 2
|
|
Matt Prahl |
ad5147 |
}
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
ad5147 |
self.assertDictEqual(data, expected_rv)
|
|
Matt Prahl |
ad5147 |
|
|
Pierre-Yves Chibon |
b130e5 |
@patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
|
|
Matt Prahl |
ad5147 |
def test_api_git_urls_private_project_no_login(self):
|
|
Matt Prahl |
ad5147 |
""" Test the api_project_git_urls method of the flask api when the
|
|
Matt Prahl |
ad5147 |
project is private and the user is not logged in.
|
|
Matt Prahl |
ad5147 |
"""
|
|
Matt Prahl |
ad5147 |
tests.create_projects(self.session)
|
|
Matt Prahl |
ad5147 |
test_project = pagure.lib._get_project(self.session, 'test')
|
|
Matt Prahl |
ad5147 |
test_project.private = True
|
|
Matt Prahl |
ad5147 |
self.session.add(test_project)
|
|
Matt Prahl |
ad5147 |
self.session.commit()
|
|
Matt Prahl |
ad5147 |
|
|
Matt Prahl |
ad5147 |
output = self.app.get('/api/0/test/git/urls')
|
|
Matt Prahl |
ad5147 |
self.assertEqual(output.status_code, 404)
|
|
Matt Prahl |
ad5147 |
expected_rv = {
|
|
Matt Prahl |
ad5147 |
'error': 'Project not found',
|
|
Matt Prahl |
ad5147 |
'error_code': 'ENOPROJECT'
|
|
Matt Prahl |
ad5147 |
}
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
ad5147 |
self.assertDictEqual(data, expected_rv)
|
|
Matt Prahl |
ad5147 |
|
|
Pierre-Yves Chibon |
1ca90b |
def test_api_projects_pattern(self):
|
|
Pierre-Yves Chibon |
1ca90b |
""" Test the api_projects method of the flask api. """
|
|
Pierre-Yves Chibon |
1ca90b |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
1ca90b |
|
|
Pierre-Yves Chibon |
1ca90b |
output = self.app.get('/api/0/projects?pattern=test')
|
|
Pierre-Yves Chibon |
1ca90b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1ca90b |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Pierre-Yves Chibon |
1ca90b |
expected_data = {
|
|
Pierre-Yves Chibon |
1ca90b |
"args": {
|
|
Pierre-Yves Chibon |
1ca90b |
"fork": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"namespace": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Pierre-Yves Chibon |
1ca90b |
"pattern": "test",
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": False,
|
|
Pierre-Yves Chibon |
1ca90b |
"tags": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"username": None
|
|
Pierre-Yves Chibon |
1ca90b |
},
|
|
Pierre-Yves Chibon |
1ca90b |
"projects": [
|
|
Pierre-Yves Chibon |
1ca90b |
{
|
|
Pierre-Yves Chibon |
1ca90b |
"access_groups": {
|
|
Pierre-Yves Chibon |
1ca90b |
"admin": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"commit": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"ticket": []
|
|
Pierre-Yves Chibon |
1ca90b |
},
|
|
Pierre-Yves Chibon |
1ca90b |
"access_users": {
|
|
Pierre-Yves Chibon |
1ca90b |
"admin": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"commit": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"owner": [
|
|
Pierre-Yves Chibon |
1ca90b |
"pingou"
|
|
Pierre-Yves Chibon |
1ca90b |
],
|
|
Pierre-Yves Chibon |
1ca90b |
"ticket": []
|
|
Pierre-Yves Chibon |
1ca90b |
},
|
|
Pierre-Yves Chibon |
1ca90b |
"close_status": [
|
|
Pierre-Yves Chibon |
1ca90b |
"Invalid",
|
|
Pierre-Yves Chibon |
1ca90b |
"Insufficient data",
|
|
Pierre-Yves Chibon |
1ca90b |
"Fixed",
|
|
Pierre-Yves Chibon |
1ca90b |
"Duplicate"
|
|
Pierre-Yves Chibon |
1ca90b |
],
|
|
Pierre-Yves Chibon |
1ca90b |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Pierre-Yves Chibon |
1ca90b |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
1ca90b |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
1ca90b |
"id": 1,
|
|
Pierre-Yves Chibon |
1ca90b |
"milestones": {},
|
|
Pierre-Yves Chibon |
1ca90b |
"name": "test",
|
|
Pierre-Yves Chibon |
1ca90b |
"namespace": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"parent": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"priorities": {},
|
|
Pierre-Yves Chibon |
1ca90b |
"tags": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"user": {
|
|
Pierre-Yves Chibon |
1ca90b |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
1ca90b |
"name": "pingou"
|
|
Pierre-Yves Chibon |
1ca90b |
}
|
|
Pierre-Yves Chibon |
1ca90b |
}
|
|
Pierre-Yves Chibon |
1ca90b |
],
|
|
Pierre-Yves Chibon |
1ca90b |
"total_projects": 1
|
|
Pierre-Yves Chibon |
1ca90b |
}
|
|
Pierre-Yves Chibon |
1ca90b |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
1ca90b |
|
|
Pierre-Yves Chibon |
1ca90b |
def test_api_projects_pattern_short(self):
|
|
Pierre-Yves Chibon |
1ca90b |
""" Test the api_projects method of the flask api. """
|
|
Pierre-Yves Chibon |
1ca90b |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
1ca90b |
|
|
Pierre-Yves Chibon |
1ca90b |
output = self.app.get('/api/0/projects?pattern=te*&short=1')
|
|
Pierre-Yves Chibon |
1ca90b |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Pierre-Yves Chibon |
1ca90b |
expected_data = {
|
|
Pierre-Yves Chibon |
1ca90b |
"args": {
|
|
Pierre-Yves Chibon |
1ca90b |
"fork": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"namespace": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Pierre-Yves Chibon |
1ca90b |
"pattern": "te*",
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": True,
|
|
Pierre-Yves Chibon |
1ca90b |
"tags": [],
|
|
Pierre-Yves Chibon |
1ca90b |
"username": None
|
|
Pierre-Yves Chibon |
1ca90b |
},
|
|
Pierre-Yves Chibon |
1ca90b |
"projects": [
|
|
Pierre-Yves Chibon |
1ca90b |
{
|
|
Pierre-Yves Chibon |
1ca90b |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
1ca90b |
"fullname": "test",
|
|
Pierre-Yves Chibon |
1ca90b |
"name": "test",
|
|
Pierre-Yves Chibon |
1ca90b |
"namespace": None
|
|
Pierre-Yves Chibon |
1ca90b |
},
|
|
Pierre-Yves Chibon |
1ca90b |
{
|
|
Pierre-Yves Chibon |
1ca90b |
"description": "test project #2",
|
|
Pierre-Yves Chibon |
1ca90b |
"fullname": "test2",
|
|
Pierre-Yves Chibon |
1ca90b |
"name": "test2",
|
|
Pierre-Yves Chibon |
1ca90b |
"namespace": None
|
|
Pierre-Yves Chibon |
1ca90b |
},
|
|
Pierre-Yves Chibon |
1ca90b |
{
|
|
Pierre-Yves Chibon |
1ca90b |
"description": "namespaced test project",
|
|
Pierre-Yves Chibon |
1ca90b |
"fullname": "somenamespace/test3",
|
|
Pierre-Yves Chibon |
1ca90b |
"name": "test3",
|
|
Pierre-Yves Chibon |
1ca90b |
"namespace": "somenamespace"
|
|
Pierre-Yves Chibon |
1ca90b |
}
|
|
Pierre-Yves Chibon |
1ca90b |
],
|
|
Pierre-Yves Chibon |
1ca90b |
"total_projects": 3
|
|
Pierre-Yves Chibon |
1ca90b |
}
|
|
Karsten Hopp |
a5d5f1 |
self.maxDiff = None
|
|
Pierre-Yves Chibon |
1ca90b |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
1ca90b |
|
|
Pierre-Yves Chibon |
ceb262 |
def test_api_projects(self):
|
|
Pierre-Yves Chibon |
ceb262 |
""" Test the api_projects method of the flask api. """
|
|
Pierre-Yves Chibon |
ceb262 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
ceb262 |
|
|
Pierre-Yves Chibon |
ceb262 |
# Check before adding
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertEqual(repo.tags, [])
|
|
Pierre-Yves Chibon |
ceb262 |
|
|
Pierre-Yves Chibon |
ceb262 |
# Adding a tag
|
|
Mark Reynolds |
eabdc8 |
output = pagure.lib.update_tags(
|
|
Patrick Uiterwijk |
3f97f6 |
self.session, repo, 'infra', 'pingou')
|
|
Pierre-Yves Chibon |
ef1fe1 |
self.assertEqual(output, ['Project tagged with: infra'])
|
|
Pierre-Yves Chibon |
ceb262 |
|
|
Pierre-Yves Chibon |
ceb262 |
# Check after adding
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertEqual(len(repo.tags), 1)
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertEqual(repo.tags_text, ['infra'])
|
|
Pierre-Yves Chibon |
ceb262 |
|
|
Pierre-Yves Chibon |
ceb262 |
# Check the API
|
|
Pierre-Yves Chibon |
ceb262 |
output = self.app.get('/api/0/projects?tags=inf')
|
|
Vivek Anand |
dfe82f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
a5d5f1 |
null = None
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
ceb262 |
data,
|
|
Vivek Anand |
dfe82f |
{
|
|
Vivek Anand |
dfe82f |
"total_projects": 0,
|
|
Vivek Anand |
dfe82f |
"projects": [],
|
|
Vivek Anand |
dfe82f |
"args": {
|
|
Vivek Anand |
dfe82f |
"fork": None,
|
|
Vivek Anand |
dfe82f |
"namespace": None,
|
|
Vivek Anand |
dfe82f |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Vivek Anand |
dfe82f |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Vivek Anand |
dfe82f |
"short": False,
|
|
Vivek Anand |
dfe82f |
"tags": ["inf"],
|
|
Vivek Anand |
dfe82f |
"username": None
|
|
Karsten Hopp |
a5d5f1 |
},
|
|
Vivek Anand |
dfe82f |
}
|
|
Pierre-Yves Chibon |
ceb262 |
)
|
|
Pierre-Yves Chibon |
ceb262 |
output = self.app.get('/api/0/projects?tags=infra')
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
ada420 |
"args": {
|
|
Matt Prahl |
ada420 |
"fork": None,
|
|
Matt Prahl |
ada420 |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Matt Prahl |
ada420 |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": False,
|
|
Matt Prahl |
ada420 |
"tags": ["infra"],
|
|
Matt Prahl |
ada420 |
"username": None
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
ada420 |
"projects": [{
|
|
Matt Prahl |
ada420 |
"access_groups": {
|
|
Matt Prahl |
ada420 |
"admin": [],
|
|
Matt Prahl |
ada420 |
"commit": [],
|
|
Matt Prahl |
ada420 |
"ticket": []},
|
|
Matt Prahl |
ada420 |
"access_users": {
|
|
Matt Prahl |
ada420 |
"admin": [],
|
|
Matt Prahl |
ada420 |
"commit": [],
|
|
Matt Prahl |
ada420 |
"owner": ["pingou"],
|
|
Matt Prahl |
ada420 |
"ticket": []},
|
|
Matt Prahl |
ada420 |
"close_status": [
|
|
Matt Prahl |
ada420 |
"Invalid",
|
|
Matt Prahl |
ada420 |
"Insufficient data",
|
|
Matt Prahl |
ada420 |
"Fixed",
|
|
Matt Prahl |
ada420 |
"Duplicate"
|
|
Pierre-Yves Chibon |
e33592 |
],
|
|
Matt Prahl |
ada420 |
"custom_keys": [],
|
|
Matt Prahl |
ada420 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
ada420 |
"description": "test project #1",
|
|
Matt Prahl |
ada420 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Matt Prahl |
ada420 |
"id": 1,
|
|
Matt Prahl |
ada420 |
"milestones": {},
|
|
Matt Prahl |
ada420 |
"name": "test",
|
|
Matt Prahl |
ada420 |
"namespace": None,
|
|
Matt Prahl |
ada420 |
"parent": None,
|
|
Matt Prahl |
ada420 |
"priorities": {},
|
|
Matt Prahl |
ada420 |
"tags": ["infra"],
|
|
Matt Prahl |
ada420 |
"user": {
|
|
Matt Prahl |
ada420 |
"fullname": "PY C",
|
|
Matt Prahl |
ada420 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
07a462 |
}
|
|
Matt Prahl |
6bf79a |
}],
|
|
Matt Prahl |
ada420 |
"total_projects": 1
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
self.assertDictEqual(data, expected_data)
|
|
Matt Prahl |
6bf79a |
|
|
Matt Prahl |
7403a2 |
output = self.app.get('/api/0/projects?owner=pingou')
|
|
Matt Prahl |
7403a2 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
7403a2 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Matt Prahl |
7403a2 |
data['projects'][1]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][1]['date_modified'] = "1436527638"
|
|
Matt Prahl |
7403a2 |
data['projects'][2]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][2]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Matt Prahl |
7403a2 |
expected_data = {
|
|
Matt Prahl |
7403a2 |
"args": {
|
|
Matt Prahl |
7403a2 |
"fork": None,
|
|
Matt Prahl |
7403a2 |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"owner": "pingou",
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Matt Prahl |
7403a2 |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": False,
|
|
Matt Prahl |
7403a2 |
"tags": [],
|
|
Matt Prahl |
7403a2 |
"username": None
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"projects": [
|
|
Matt Prahl |
7403a2 |
{
|
|
Matt Prahl |
7403a2 |
"access_groups": {
|
|
Matt Prahl |
7403a2 |
"admin": [],
|
|
Matt Prahl |
7403a2 |
"commit": [],
|
|
Matt Prahl |
7403a2 |
"ticket": []
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"access_users": {
|
|
Matt Prahl |
7403a2 |
"admin": [],
|
|
Matt Prahl |
7403a2 |
"commit": [],
|
|
Matt Prahl |
7403a2 |
"owner": ["pingou"],
|
|
Matt Prahl |
7403a2 |
"ticket": []
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"close_status": [
|
|
Matt Prahl |
7403a2 |
"Invalid",
|
|
Matt Prahl |
7403a2 |
"Insufficient data",
|
|
Matt Prahl |
7403a2 |
"Fixed",
|
|
Matt Prahl |
7403a2 |
"Duplicate"
|
|
Matt Prahl |
7403a2 |
],
|
|
Matt Prahl |
7403a2 |
"custom_keys": [],
|
|
Matt Prahl |
7403a2 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
7403a2 |
"description": "test project #1",
|
|
Matt Prahl |
7403a2 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Matt Prahl |
7403a2 |
"id": 1,
|
|
Matt Prahl |
7403a2 |
"milestones": {},
|
|
Matt Prahl |
7403a2 |
"name": "test",
|
|
Matt Prahl |
7403a2 |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"parent": None,
|
|
Matt Prahl |
7403a2 |
"priorities": {},
|
|
Matt Prahl |
7403a2 |
"tags": ["infra"],
|
|
Matt Prahl |
7403a2 |
"user": {
|
|
Matt Prahl |
7403a2 |
"fullname": "PY C",
|
|
Matt Prahl |
7403a2 |
"name": "pingou"
|
|
Matt Prahl |
7403a2 |
}
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
{
|
|
Matt Prahl |
7403a2 |
"access_groups": {
|
|
Matt Prahl |
7403a2 |
"admin": [],
|
|
Matt Prahl |
7403a2 |
"commit": [],
|
|
Matt Prahl |
7403a2 |
"ticket": []
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"access_users": {
|
|
Matt Prahl |
7403a2 |
"admin": [],
|
|
Matt Prahl |
7403a2 |
"commit": [],
|
|
Matt Prahl |
7403a2 |
"owner": ["pingou"],
|
|
Matt Prahl |
7403a2 |
"ticket": []
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"close_status": [
|
|
Matt Prahl |
7403a2 |
"Invalid",
|
|
Matt Prahl |
7403a2 |
"Insufficient data",
|
|
Matt Prahl |
7403a2 |
"Fixed",
|
|
Matt Prahl |
7403a2 |
"Duplicate"
|
|
Matt Prahl |
7403a2 |
],
|
|
Matt Prahl |
7403a2 |
"custom_keys": [],
|
|
Matt Prahl |
7403a2 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
7403a2 |
"description": "test project #2",
|
|
Matt Prahl |
7403a2 |
"fullname": "test2",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test2",
|
|
Matt Prahl |
7403a2 |
"id": 2,
|
|
Matt Prahl |
7403a2 |
"milestones": {},
|
|
Matt Prahl |
7403a2 |
"name": "test2",
|
|
Matt Prahl |
7403a2 |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"parent": None,
|
|
Matt Prahl |
7403a2 |
"priorities": {},
|
|
Matt Prahl |
7403a2 |
"tags": [],
|
|
Matt Prahl |
7403a2 |
"user": {
|
|
Matt Prahl |
7403a2 |
"fullname": "PY C",
|
|
Matt Prahl |
7403a2 |
"name": "pingou"
|
|
Matt Prahl |
7403a2 |
}
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
{
|
|
Matt Prahl |
7403a2 |
"access_groups": {
|
|
Matt Prahl |
7403a2 |
"admin": [],
|
|
Matt Prahl |
7403a2 |
"commit": [],
|
|
Matt Prahl |
7403a2 |
"ticket": []
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"access_users": {
|
|
Matt Prahl |
7403a2 |
"admin": [],
|
|
Matt Prahl |
7403a2 |
"commit": [],
|
|
Matt Prahl |
7403a2 |
"owner": ["pingou"],
|
|
Matt Prahl |
7403a2 |
"ticket": []
|
|
Matt Prahl |
7403a2 |
},
|
|
Matt Prahl |
7403a2 |
"close_status": [
|
|
Matt Prahl |
7403a2 |
"Invalid",
|
|
Matt Prahl |
7403a2 |
"Insufficient data",
|
|
Matt Prahl |
7403a2 |
"Fixed",
|
|
Matt Prahl |
7403a2 |
"Duplicate"
|
|
Matt Prahl |
7403a2 |
],
|
|
Matt Prahl |
7403a2 |
"custom_keys": [],
|
|
Matt Prahl |
7403a2 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
7403a2 |
"description": "namespaced test project",
|
|
Matt Prahl |
7403a2 |
"fullname": "somenamespace/test3",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "somenamespace/test3",
|
|
Matt Prahl |
7403a2 |
"id": 3,
|
|
Matt Prahl |
7403a2 |
"milestones": {},
|
|
Matt Prahl |
7403a2 |
"name": "test3",
|
|
Matt Prahl |
7403a2 |
"namespace": "somenamespace",
|
|
Matt Prahl |
7403a2 |
"parent": None,
|
|
Matt Prahl |
7403a2 |
"priorities": {},
|
|
Matt Prahl |
7403a2 |
"tags": [],
|
|
Matt Prahl |
7403a2 |
"user": {
|
|
Matt Prahl |
7403a2 |
"fullname": "PY C",
|
|
Matt Prahl |
7403a2 |
"name": "pingou"
|
|
Matt Prahl |
7403a2 |
}
|
|
Matt Prahl |
7403a2 |
}
|
|
Matt Prahl |
7403a2 |
],
|
|
Matt Prahl |
7403a2 |
"total_projects": 3
|
|
Matt Prahl |
7403a2 |
}
|
|
Matt Prahl |
7403a2 |
self.assertDictEqual(data, expected_data)
|
|
Matt Prahl |
7403a2 |
|
|
Pierre-Yves Chibon |
7485e2 |
output = self.app.get('/api/0/projects?username=pingou')
|
|
Pierre-Yves Chibon |
7485e2 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][1]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][1]['date_modified'] = "1436527638"
|
|
clime |
afed57 |
data['projects'][2]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][2]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
"args": {
|
|
Pierre-Yves Chibon |
e33592 |
"fork": None,
|
|
Matt Prahl |
ada420 |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Pierre-Yves Chibon |
e33592 |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": False,
|
|
Pierre-Yves Chibon |
e33592 |
"tags": [],
|
|
Matt Prahl |
6bf79a |
"username": "pingou"
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"projects": [
|
|
Pierre-Yves Chibon |
07a462 |
{
|
|
Matt Prahl |
6bf79a |
"access_groups": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"ticket": []},
|
|
Matt Prahl |
6bf79a |
"access_users": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"owner": ["pingou"],
|
|
Matt Prahl |
6bf79a |
"ticket": []
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"
|
|
Pierre-Yves Chibon |
f254bf |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Matt Prahl |
6bf79a |
"id": 1,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test",
|
|
Matt Prahl |
6bf79a |
"namespace": None,
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"tags": ["infra"],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
Pierre-Yves Chibon |
07a462 |
},
|
|
Pierre-Yves Chibon |
07a462 |
{
|
|
Matt Prahl |
6bf79a |
"access_groups": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"ticket": []
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"access_users": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"owner": ["pingou"],
|
|
Matt Prahl |
6bf79a |
"ticket": []
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"
|
|
Pierre-Yves Chibon |
f254bf |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
6bf79a |
"description": "test project #2",
|
|
Matt Prahl |
6bf79a |
"fullname": "test2",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test2",
|
|
Matt Prahl |
6bf79a |
"id": 2,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test2",
|
|
Matt Prahl |
6bf79a |
"namespace": None,
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"tags": [],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
clime |
afed57 |
},
|
|
clime |
afed57 |
{
|
|
Matt Prahl |
6bf79a |
"access_groups": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"ticket": []},
|
|
Matt Prahl |
6bf79a |
"access_users": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"owner": ["pingou"],
|
|
Matt Prahl |
6bf79a |
"ticket": []},
|
|
Matt Prahl |
6bf79a |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"
|
|
clime |
afed57 |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
6bf79a |
"description": "namespaced test project",
|
|
Matt Prahl |
6bf79a |
"fullname": "somenamespace/test3",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "somenamespace/test3",
|
|
Matt Prahl |
6bf79a |
"id": 3,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test3",
|
|
Matt Prahl |
6bf79a |
"namespace": "somenamespace",
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"tags": [],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
Pierre-Yves Chibon |
07a462 |
}
|
|
Matt Prahl |
6bf79a |
],
|
|
Matt Prahl |
6bf79a |
"total_projects": 3
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
self.assertDictEqual(data, expected_data)
|
|
Matt Prahl |
6bf79a |
|
|
Pierre-Yves Chibon |
7485e2 |
output = self.app.get('/api/0/projects?username=pingou&tags=infra')
|
|
Pierre-Yves Chibon |
7485e2 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
"args": {
|
|
Pierre-Yves Chibon |
e33592 |
"fork": None,
|
|
Matt Prahl |
ada420 |
"namespace": None,
|
|
Matt Prahl |
7403a2 |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Pierre-Yves Chibon |
e33592 |
"pattern": None,
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": False,
|
|
Matt Prahl |
6bf79a |
"tags": ["infra"],
|
|
Matt Prahl |
6c3d54 |
"username": "pingou",
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"projects": [{
|
|
Matt Prahl |
6bf79a |
"access_groups": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"ticket": []
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"access_users": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"owner": ["pingou"],
|
|
Matt Prahl |
6bf79a |
"ticket": []},
|
|
Matt Prahl |
6bf79a |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Matt Prahl |
6bf79a |
"id": 1,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test",
|
|
Matt Prahl |
6bf79a |
"namespace": None,
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"tags": ["infra"],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Pierre-Yves Chibon |
07a462 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
07a462 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
07a462 |
}
|
|
Matt Prahl |
6bf79a |
}],
|
|
Matt Prahl |
6bf79a |
"total_projects": 1
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
ceb262 |
|
|
Matt Prahl |
6c3d54 |
output = self.app.get('/api/0/projects?namespace=somenamespace')
|
|
Matt Prahl |
6c3d54 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
6c3d54 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Karsten Hopp |
a5d5f1 |
del data['pagination']
|
|
Matt Prahl |
6c3d54 |
expected_data = {
|
|
Matt Prahl |
6c3d54 |
"args": {
|
|
Matt Prahl |
6c3d54 |
"fork": None,
|
|
Matt Prahl |
7403a2 |
"owner": None,
|
|
Karsten Hopp |
a5d5f1 |
"page": 1,
|
|
Matt Prahl |
ada420 |
"namespace": "somenamespace",
|
|
Karsten Hopp |
a5d5f1 |
"per_page": 20,
|
|
Matt Prahl |
6c3d54 |
"pattern": None,
|
|
Pierre-Yves Chibon |
1ca90b |
"short": False,
|
|
Matt Prahl |
6c3d54 |
"tags": [],
|
|
Matt Prahl |
6c3d54 |
"username": None
|
|
Matt Prahl |
6c3d54 |
},
|
|
Matt Prahl |
6c3d54 |
"projects": [
|
|
Matt Prahl |
6c3d54 |
{
|
|
Matt Prahl |
6c3d54 |
"access_groups": {
|
|
Matt Prahl |
6c3d54 |
"admin": [],
|
|
Matt Prahl |
6c3d54 |
"commit": [],
|
|
Matt Prahl |
6c3d54 |
"ticket": []},
|
|
Matt Prahl |
6c3d54 |
"access_users": {
|
|
Matt Prahl |
6c3d54 |
"admin": [],
|
|
Matt Prahl |
6c3d54 |
"commit": [],
|
|
Matt Prahl |
6c3d54 |
"owner": ["pingou"],
|
|
Matt Prahl |
6c3d54 |
"ticket": []},
|
|
Matt Prahl |
6c3d54 |
"close_status": [
|
|
Matt Prahl |
6c3d54 |
"Invalid",
|
|
Matt Prahl |
6c3d54 |
"Insufficient data",
|
|
Matt Prahl |
6c3d54 |
"Fixed",
|
|
Matt Prahl |
6c3d54 |
"Duplicate"
|
|
Matt Prahl |
6c3d54 |
],
|
|
Matt Prahl |
6c3d54 |
"custom_keys": [],
|
|
Matt Prahl |
6c3d54 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
6c3d54 |
"description": "namespaced test project",
|
|
Matt Prahl |
6c3d54 |
"fullname": "somenamespace/test3",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "somenamespace/test3",
|
|
Matt Prahl |
6c3d54 |
"id": 3,
|
|
Matt Prahl |
6c3d54 |
"milestones": {},
|
|
Matt Prahl |
6c3d54 |
"name": "test3",
|
|
Matt Prahl |
6c3d54 |
"namespace": "somenamespace",
|
|
Matt Prahl |
6c3d54 |
"parent": None,
|
|
Matt Prahl |
6c3d54 |
"priorities": {},
|
|
Matt Prahl |
6c3d54 |
"tags": [],
|
|
Matt Prahl |
6c3d54 |
"user": {
|
|
Matt Prahl |
6c3d54 |
"fullname": "PY C",
|
|
Matt Prahl |
6c3d54 |
"name": "pingou"
|
|
Matt Prahl |
6c3d54 |
}
|
|
Matt Prahl |
6c3d54 |
}
|
|
Matt Prahl |
6c3d54 |
],
|
|
Matt Prahl |
6c3d54 |
"total_projects": 1
|
|
Matt Prahl |
6c3d54 |
}
|
|
Matt Prahl |
6c3d54 |
self.assertDictEqual(data, expected_data)
|
|
Matt Prahl |
6c3d54 |
|
|
Pierre-Yves Chibon |
b42ba1 |
def test_api_project(self):
|
|
Pierre-Yves Chibon |
b42ba1 |
""" Test the api_project method of the flask api. """
|
|
Pierre-Yves Chibon |
b42ba1 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Check before adding
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b42ba1 |
self.assertEqual(repo.tags, [])
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Adding a tag
|
|
Mark Reynolds |
eabdc8 |
output = pagure.lib.update_tags(
|
|
Patrick Uiterwijk |
3f97f6 |
self.session, repo, 'infra', 'pingou')
|
|
Pierre-Yves Chibon |
ef1fe1 |
self.assertEqual(output, ['Project tagged with: infra'])
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Check after adding
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
b42ba1 |
self.assertEqual(len(repo.tags), 1)
|
|
Pierre-Yves Chibon |
b42ba1 |
self.assertEqual(repo.tags_text, ['infra'])
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Check the API
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Non-existing project
|
|
Pierre-Yves Chibon |
b42ba1 |
output = self.app.get('/api/0/random')
|
|
Pierre-Yves Chibon |
b42ba1 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
b42ba1 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
b42ba1 |
data,
|
|
Pierre-Yves Chibon |
b42ba1 |
{'error_code': 'ENOPROJECT', 'error': 'Project not found'}
|
|
Pierre-Yves Chibon |
b42ba1 |
)
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Existing project
|
|
Pierre-Yves Chibon |
b42ba1 |
output = self.app.get('/api/0/test')
|
|
Pierre-Yves Chibon |
b42ba1 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
b42ba1 |
data['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['date_modified'] = "1436527638"
|
|
Matt Prahl |
6bf79a |
expected_data ={
|
|
Matt Prahl |
6bf79a |
"access_groups": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"ticket": []
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"access_users": {
|
|
Matt Prahl |
6bf79a |
"admin": [],
|
|
Matt Prahl |
6bf79a |
"commit": [],
|
|
Matt Prahl |
6bf79a |
"owner": ["pingou"],
|
|
Pierre-Yves Chibon |
fd3701 |
"ticket": []},
|
|
Pierre-Yves Chibon |
fd3701 |
"close_status": [
|
|
Pierre-Yves Chibon |
fd3701 |
"Invalid",
|
|
Pierre-Yves Chibon |
fd3701 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
fd3701 |
"Fixed",
|
|
Pierre-Yves Chibon |
fd3701 |
"Duplicate"
|
|
Pierre-Yves Chibon |
fd3701 |
],
|
|
Pierre-Yves Chibon |
fd3701 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"date_created": "1436527638",
|
|
Pierre-Yves Chibon |
fd3701 |
"date_modified": "1436527638",
|
|
Pierre-Yves Chibon |
fd3701 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
fd3701 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
fd3701 |
"id": 1,
|
|
Pierre-Yves Chibon |
fd3701 |
"milestones": {},
|
|
Pierre-Yves Chibon |
fd3701 |
"name": "test",
|
|
Pierre-Yves Chibon |
fd3701 |
"namespace": None,
|
|
Pierre-Yves Chibon |
fd3701 |
"parent": None,
|
|
Pierre-Yves Chibon |
fd3701 |
"priorities": {},
|
|
Pierre-Yves Chibon |
fd3701 |
"tags": ["infra"],
|
|
Pierre-Yves Chibon |
fd3701 |
"user": {
|
|
Pierre-Yves Chibon |
fd3701 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
fd3701 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
fd3701 |
}
|
|
Pierre-Yves Chibon |
fd3701 |
}
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
def test_api_project_group(self):
|
|
Pierre-Yves Chibon |
fd3701 |
""" Test the api_project method of the flask api. """
|
|
Pierre-Yves Chibon |
fd3701 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Adding a tag
|
|
Pierre-Yves Chibon |
fd3701 |
output = pagure.lib.update_tags(
|
|
Patrick Uiterwijk |
3f97f6 |
self.session, repo, 'infra', 'pingou')
|
|
Pierre-Yves Chibon |
ef1fe1 |
self.assertEqual(output, ['Project tagged with: infra'])
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Check after adding
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertEqual(len(repo.tags), 1)
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertEqual(repo.tags_text, ['infra'])
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Add a group to the project
|
|
Pierre-Yves Chibon |
fd3701 |
msg = pagure.lib.add_group(
|
|
Pierre-Yves Chibon |
fd3701 |
self.session,
|
|
Pierre-Yves Chibon |
fd3701 |
group_name='some_group',
|
|
Pierre-Yves Chibon |
fd3701 |
display_name='Some Group',
|
|
Pierre-Yves Chibon |
fd3701 |
description=None,
|
|
Pierre-Yves Chibon |
fd3701 |
group_type='bar',
|
|
Pierre-Yves Chibon |
fd3701 |
user='foo',
|
|
Pierre-Yves Chibon |
fd3701 |
is_admin=False,
|
|
Pierre-Yves Chibon |
fd3701 |
blacklist=[],
|
|
Pierre-Yves Chibon |
fd3701 |
)
|
|
Pierre-Yves Chibon |
fd3701 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fd3701 |
group = pagure.lib.search_groups(
|
|
Pierre-Yves Chibon |
fd3701 |
self.session, group_name='some_group')
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
pagure.lib.add_group_to_project(
|
|
Pierre-Yves Chibon |
fd3701 |
self.session,
|
|
Pierre-Yves Chibon |
fd3701 |
project,
|
|
Pierre-Yves Chibon |
fd3701 |
new_group='some_group',
|
|
Pierre-Yves Chibon |
fd3701 |
user='pingou',
|
|
Pierre-Yves Chibon |
fd3701 |
access='commit',
|
|
Pierre-Yves Chibon |
fd3701 |
create=False,
|
|
Pierre-Yves Chibon |
fd3701 |
is_admin=True
|
|
Pierre-Yves Chibon |
fd3701 |
)
|
|
Pierre-Yves Chibon |
fd3701 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Check the API
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Existing project
|
|
Pierre-Yves Chibon |
fd3701 |
output = self.app.get('/api/0/test?expand_group=1')
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
fd3701 |
data['date_created'] = "1436527638"
|
|
Pierre-Yves Chibon |
fd3701 |
data['date_modified'] = "1436527638"
|
|
Pierre-Yves Chibon |
fd3701 |
expected_data ={
|
|
Pierre-Yves Chibon |
fd3701 |
"access_groups": {
|
|
Pierre-Yves Chibon |
fd3701 |
"admin": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"commit": ["some_group"],
|
|
Pierre-Yves Chibon |
fd3701 |
"ticket": []
|
|
Pierre-Yves Chibon |
fd3701 |
},
|
|
Pierre-Yves Chibon |
fd3701 |
"access_users": {
|
|
Pierre-Yves Chibon |
fd3701 |
"admin": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"commit": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"owner": ["pingou"],
|
|
Pierre-Yves Chibon |
fd3701 |
"ticket": []},
|
|
Pierre-Yves Chibon |
fd3701 |
"close_status": [
|
|
Pierre-Yves Chibon |
fd3701 |
"Invalid",
|
|
Pierre-Yves Chibon |
fd3701 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
fd3701 |
"Fixed",
|
|
Pierre-Yves Chibon |
fd3701 |
"Duplicate"
|
|
Pierre-Yves Chibon |
fd3701 |
],
|
|
Pierre-Yves Chibon |
fd3701 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"date_created": "1436527638",
|
|
Pierre-Yves Chibon |
fd3701 |
"date_modified": "1436527638",
|
|
Pierre-Yves Chibon |
fd3701 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
fd3701 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
fd3701 |
"group_details": {
|
|
Pierre-Yves Chibon |
fd3701 |
"some_group": [
|
|
Pierre-Yves Chibon |
fd3701 |
"foo"
|
|
Pierre-Yves Chibon |
fd3701 |
]
|
|
Pierre-Yves Chibon |
fd3701 |
},
|
|
Pierre-Yves Chibon |
fd3701 |
"id": 1,
|
|
Pierre-Yves Chibon |
fd3701 |
"milestones": {},
|
|
Pierre-Yves Chibon |
fd3701 |
"name": "test",
|
|
Pierre-Yves Chibon |
fd3701 |
"namespace": None,
|
|
Pierre-Yves Chibon |
fd3701 |
"parent": None,
|
|
Pierre-Yves Chibon |
fd3701 |
"priorities": {},
|
|
Pierre-Yves Chibon |
fd3701 |
"tags": ["infra"],
|
|
Pierre-Yves Chibon |
fd3701 |
"user": {
|
|
Pierre-Yves Chibon |
fd3701 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
fd3701 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
fd3701 |
}
|
|
Pierre-Yves Chibon |
fd3701 |
}
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
def test_api_project_group_but_no_group(self):
|
|
Pierre-Yves Chibon |
fd3701 |
""" Test the api_project method of the flask api when asking for
|
|
Pierre-Yves Chibon |
fd3701 |
group details while there are none associated.
|
|
Pierre-Yves Chibon |
fd3701 |
"""
|
|
Pierre-Yves Chibon |
fd3701 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Adding a tag
|
|
Pierre-Yves Chibon |
fd3701 |
output = pagure.lib.update_tags(
|
|
Patrick Uiterwijk |
3f97f6 |
self.session, repo, 'infra', 'pingou')
|
|
Pierre-Yves Chibon |
ef1fe1 |
self.assertEqual(output, ['Project tagged with: infra'])
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Check after adding
|
|
Pierre-Yves Chibon |
b130e5 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertEqual(len(repo.tags), 1)
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertEqual(repo.tags_text, ['infra'])
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Check the API
|
|
Pierre-Yves Chibon |
fd3701 |
|
|
Pierre-Yves Chibon |
fd3701 |
# Existing project
|
|
Pierre-Yves Chibon |
fd3701 |
output = self.app.get('/api/0/test?expand_group=0')
|
|
Pierre-Yves Chibon |
fd3701 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
fd3701 |
data['date_created'] = "1436527638"
|
|
Pierre-Yves Chibon |
fd3701 |
data['date_modified'] = "1436527638"
|
|
Pierre-Yves Chibon |
fd3701 |
expected_data ={
|
|
Pierre-Yves Chibon |
fd3701 |
"access_groups": {
|
|
Pierre-Yves Chibon |
fd3701 |
"admin": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"commit": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"ticket": []
|
|
Pierre-Yves Chibon |
fd3701 |
},
|
|
Pierre-Yves Chibon |
fd3701 |
"access_users": {
|
|
Pierre-Yves Chibon |
fd3701 |
"admin": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"commit": [],
|
|
Pierre-Yves Chibon |
fd3701 |
"owner": ["pingou"],
|
|
Matt Prahl |
6bf79a |
"ticket": []},
|
|
Matt Prahl |
6bf79a |
"close_status": [
|
|
Pierre-Yves Chibon |
b42ba1 |
"Invalid",
|
|
Pierre-Yves Chibon |
b42ba1 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
b42ba1 |
"Fixed",
|
|
Pierre-Yves Chibon |
b42ba1 |
"Duplicate"
|
|
Matt Prahl |
6bf79a |
],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Matt Prahl |
6bf79a |
"id": 1,
|
|
Matt Prahl |
6bf79a |
"milestones": {},
|
|
Matt Prahl |
6bf79a |
"name": "test",
|
|
Matt Prahl |
6bf79a |
"namespace": None,
|
|
Matt Prahl |
6bf79a |
"parent": None,
|
|
Matt Prahl |
6bf79a |
"priorities": {},
|
|
Matt Prahl |
6bf79a |
"tags": ["infra"],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Pierre-Yves Chibon |
b42ba1 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
b42ba1 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
b42ba1 |
}
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api with pagination. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=1')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Clement Verna |
cd6e30 |
for i in range(3):
|
|
Clement Verna |
cd6e30 |
data['projects'][i]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][i]['date_modified'] = "1436527638"
|
|
Matt Prahl |
a01c25 |
expected_data = {
|
|
Matt Prahl |
a01c25 |
"args": {
|
|
Matt Prahl |
a01c25 |
"fork": None,
|
|
Matt Prahl |
a01c25 |
"namespace": None,
|
|
Matt Prahl |
a01c25 |
"owner": None,
|
|
Matt Prahl |
a01c25 |
"page": 1,
|
|
Matt Prahl |
a01c25 |
"per_page": 20,
|
|
Matt Prahl |
a01c25 |
"pattern": None,
|
|
Matt Prahl |
a01c25 |
"short": False,
|
|
Matt Prahl |
a01c25 |
"tags": [],
|
|
Matt Prahl |
a01c25 |
"username": None
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"pagination": {
|
|
Matt Prahl |
a01c25 |
"next": None,
|
|
Matt Prahl |
a01c25 |
"page": 1,
|
|
Matt Prahl |
a01c25 |
"pages": 1,
|
|
Matt Prahl |
a01c25 |
"per_page": 20,
|
|
Matt Prahl |
a01c25 |
"prev": None
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"projects": [
|
|
Matt Prahl |
a01c25 |
{
|
|
Matt Prahl |
a01c25 |
"access_groups": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"ticket": []},
|
|
Matt Prahl |
a01c25 |
"access_users": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"owner": ["pingou"],
|
|
Matt Prahl |
a01c25 |
"ticket": []
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"close_status": [
|
|
Matt Prahl |
a01c25 |
"Invalid",
|
|
Matt Prahl |
a01c25 |
"Insufficient data",
|
|
Matt Prahl |
a01c25 |
"Fixed",
|
|
Matt Prahl |
a01c25 |
"Duplicate"
|
|
Matt Prahl |
a01c25 |
],
|
|
Matt Prahl |
a01c25 |
"custom_keys": [],
|
|
Matt Prahl |
a01c25 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
a01c25 |
"description": "test project #1",
|
|
Matt Prahl |
a01c25 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test",
|
|
Matt Prahl |
a01c25 |
"id": 1,
|
|
Matt Prahl |
a01c25 |
"milestones": {},
|
|
Matt Prahl |
a01c25 |
"name": "test",
|
|
Matt Prahl |
a01c25 |
"namespace": None,
|
|
Matt Prahl |
a01c25 |
"parent": None,
|
|
Matt Prahl |
a01c25 |
"priorities": {},
|
|
Matt Prahl |
a01c25 |
"tags": [],
|
|
Matt Prahl |
a01c25 |
"user": {
|
|
Matt Prahl |
a01c25 |
"fullname": "PY C",
|
|
Matt Prahl |
a01c25 |
"name": "pingou"
|
|
Matt Prahl |
a01c25 |
}
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
{
|
|
Matt Prahl |
a01c25 |
"access_groups": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"ticket": []
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"access_users": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"owner": ["pingou"],
|
|
Matt Prahl |
a01c25 |
"ticket": []
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"close_status": [
|
|
Matt Prahl |
a01c25 |
"Invalid",
|
|
Matt Prahl |
a01c25 |
"Insufficient data",
|
|
Matt Prahl |
a01c25 |
"Fixed",
|
|
Matt Prahl |
a01c25 |
"Duplicate"
|
|
Matt Prahl |
a01c25 |
],
|
|
Matt Prahl |
a01c25 |
"custom_keys": [],
|
|
Matt Prahl |
a01c25 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
a01c25 |
"description": "test project #2",
|
|
Matt Prahl |
a01c25 |
"fullname": "test2",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "test2",
|
|
Matt Prahl |
a01c25 |
"id": 2,
|
|
Matt Prahl |
a01c25 |
"milestones": {},
|
|
Matt Prahl |
a01c25 |
"name": "test2",
|
|
Matt Prahl |
a01c25 |
"namespace": None,
|
|
Matt Prahl |
a01c25 |
"parent": None,
|
|
Matt Prahl |
a01c25 |
"priorities": {},
|
|
Matt Prahl |
a01c25 |
"tags": [],
|
|
Matt Prahl |
a01c25 |
"user": {
|
|
Matt Prahl |
a01c25 |
"fullname": "PY C",
|
|
Matt Prahl |
a01c25 |
"name": "pingou"
|
|
Matt Prahl |
a01c25 |
}
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
{
|
|
Matt Prahl |
a01c25 |
"access_groups": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"ticket": []},
|
|
Matt Prahl |
a01c25 |
"access_users": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"owner": ["pingou"],
|
|
Matt Prahl |
a01c25 |
"ticket": []},
|
|
Matt Prahl |
a01c25 |
"close_status": [
|
|
Matt Prahl |
a01c25 |
"Invalid",
|
|
Matt Prahl |
a01c25 |
"Insufficient data",
|
|
Matt Prahl |
a01c25 |
"Fixed",
|
|
Matt Prahl |
a01c25 |
"Duplicate"
|
|
Matt Prahl |
a01c25 |
],
|
|
Matt Prahl |
a01c25 |
"custom_keys": [],
|
|
Matt Prahl |
a01c25 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
a01c25 |
"description": "namespaced test project",
|
|
Matt Prahl |
a01c25 |
"fullname": "somenamespace/test3",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "somenamespace/test3",
|
|
Matt Prahl |
a01c25 |
"id": 3,
|
|
Matt Prahl |
a01c25 |
"milestones": {},
|
|
Matt Prahl |
a01c25 |
"name": "test3",
|
|
Matt Prahl |
a01c25 |
"namespace": "somenamespace",
|
|
Matt Prahl |
a01c25 |
"parent": None,
|
|
Matt Prahl |
a01c25 |
"priorities": {},
|
|
Matt Prahl |
a01c25 |
"tags": [],
|
|
Matt Prahl |
a01c25 |
"user": {
|
|
Matt Prahl |
a01c25 |
"fullname": "PY C",
|
|
Matt Prahl |
a01c25 |
"name": "pingou"
|
|
Matt Prahl |
a01c25 |
}
|
|
Matt Prahl |
a01c25 |
}
|
|
Matt Prahl |
a01c25 |
],
|
|
Matt Prahl |
a01c25 |
"total_projects": 3
|
|
Matt Prahl |
a01c25 |
}
|
|
Aurélien Bompard |
f61bb3 |
# Test URLs
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("first"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=20&page=1",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("last"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=20&page=1",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Matt Prahl |
a01c25 |
self.assertDictEqual(data, expected_data)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_per_page(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api with pagination and
|
|
Matt Prahl |
a01c25 |
the `per_page` argument set. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=2&per_page=2')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
a01c25 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Clement Verna |
cd6e30 |
data['projects'][0]['date_modified'] = "1436527638"
|
|
Matt Prahl |
a01c25 |
expected_data = {
|
|
Matt Prahl |
a01c25 |
"args": {
|
|
Matt Prahl |
a01c25 |
"fork": None,
|
|
Matt Prahl |
a01c25 |
"namespace": None,
|
|
Matt Prahl |
a01c25 |
"owner": None,
|
|
Matt Prahl |
a01c25 |
"page": 2,
|
|
Matt Prahl |
a01c25 |
"per_page": 2,
|
|
Matt Prahl |
a01c25 |
"pattern": None,
|
|
Matt Prahl |
a01c25 |
"short": False,
|
|
Matt Prahl |
a01c25 |
"tags": [],
|
|
Matt Prahl |
a01c25 |
"username": None
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"pagination": {
|
|
Matt Prahl |
a01c25 |
"next": None,
|
|
Matt Prahl |
a01c25 |
"page": 2,
|
|
Matt Prahl |
a01c25 |
"pages": 2,
|
|
Matt Prahl |
a01c25 |
"per_page": 2,
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"projects": [
|
|
Matt Prahl |
a01c25 |
{
|
|
Matt Prahl |
a01c25 |
"access_groups": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"ticket": []
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"access_users": {
|
|
Matt Prahl |
a01c25 |
"admin": [],
|
|
Matt Prahl |
a01c25 |
"commit": [],
|
|
Matt Prahl |
a01c25 |
"owner": ["pingou"],
|
|
Matt Prahl |
a01c25 |
"ticket": []
|
|
Matt Prahl |
a01c25 |
},
|
|
Matt Prahl |
a01c25 |
"close_status": [
|
|
Matt Prahl |
a01c25 |
"Invalid",
|
|
Matt Prahl |
a01c25 |
"Insufficient data",
|
|
Matt Prahl |
a01c25 |
"Fixed",
|
|
Matt Prahl |
a01c25 |
"Duplicate"
|
|
Matt Prahl |
a01c25 |
],
|
|
Matt Prahl |
a01c25 |
"custom_keys": [],
|
|
Matt Prahl |
a01c25 |
"date_created": "1436527638",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1436527638",
|
|
Matt Prahl |
a01c25 |
"description": "namespaced test project",
|
|
Matt Prahl |
a01c25 |
"fullname": "somenamespace/test3",
|
|
Pierre-Yves Chibon |
469e24 |
"url_path": "somenamespace/test3",
|
|
Matt Prahl |
a01c25 |
"id": 3,
|
|
Matt Prahl |
a01c25 |
"milestones": {},
|
|
Matt Prahl |
a01c25 |
"name": "test3",
|
|
Matt Prahl |
a01c25 |
"namespace": "somenamespace",
|
|
Matt Prahl |
a01c25 |
"parent": None,
|
|
Matt Prahl |
a01c25 |
"priorities": {},
|
|
Matt Prahl |
a01c25 |
"tags": [],
|
|
Matt Prahl |
a01c25 |
"user": {
|
|
Matt Prahl |
a01c25 |
"fullname": "PY C",
|
|
Matt Prahl |
a01c25 |
"name": "pingou"
|
|
Matt Prahl |
a01c25 |
}
|
|
Matt Prahl |
a01c25 |
}
|
|
Matt Prahl |
a01c25 |
],
|
|
Matt Prahl |
a01c25 |
"total_projects": 3
|
|
Matt Prahl |
a01c25 |
}
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("first"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=2&page=1",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("prev"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=2&page=1",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("last"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=2&page=2",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Matt Prahl |
a01c25 |
self.assertDictEqual(data, expected_data)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_invalid_page(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api when an invalid page
|
|
Matt Prahl |
a01c25 |
value is entered. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=-3')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 400)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_invalid_page_str(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api when an invalid type
|
|
Matt Prahl |
a01c25 |
for the page value is entered. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=abcd')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 400)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_invalid_per_page_too_low(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api when a per_page
|
|
Matt Prahl |
a01c25 |
value is below 1. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=1&per_page=0')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
error = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
a01c25 |
self.assertEqual(
|
|
Matt Prahl |
a01c25 |
error['error'], 'The per_page value must be between 1 and 100')
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_invalid_per_page_too_high(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api when a per_page
|
|
Matt Prahl |
a01c25 |
value is above 100. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=1&per_page=101')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
error = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
a01c25 |
self.assertEqual(
|
|
Matt Prahl |
a01c25 |
error['error'], 'The per_page value must be between 1 and 100')
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_invalid_per_page_str(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api when an invalid type
|
|
Matt Prahl |
a01c25 |
for the per_page value is entered. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=1&per_page=abcd')
|
|
Matt Prahl |
a01c25 |
self.assertEqual(output.status_code, 400)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
def test_api_projects_pagination_beyond_last_page(self):
|
|
Matt Prahl |
a01c25 |
""" Test the api_projects method of the flask api when a page value
|
|
Matt Prahl |
a01c25 |
that is larger than the last page is entered. """
|
|
Matt Prahl |
a01c25 |
tests.create_projects(self.session)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
a01c25 |
output = self.app.get('/api/0/projects?page=99999')
|
|
Vivek Anand |
dfe82f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("first"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=20&page=1",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("last"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=20&page=1",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Aurélien Bompard |
f61bb3 |
self.assertURLEqual(
|
|
Aurélien Bompard |
f61bb3 |
data["pagination"].pop("prev"),
|
|
Aurélien Bompard |
f61bb3 |
"http://localhost/api/0/projects?per_page=20&page=99998",
|
|
Aurélien Bompard |
f61bb3 |
)
|
|
Pierre-Yves Chibon |
b13c25 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
b13c25 |
data,
|
|
Pierre-Yves Chibon |
b13c25 |
{
|
|
Pierre-Yves Chibon |
b13c25 |
"args": {
|
|
Pierre-Yves Chibon |
b13c25 |
"fork": None,
|
|
Pierre-Yves Chibon |
b13c25 |
"namespace": None,
|
|
Pierre-Yves Chibon |
b13c25 |
"owner": None,
|
|
Pierre-Yves Chibon |
b13c25 |
"page": 99999,
|
|
Pierre-Yves Chibon |
b13c25 |
"pattern": None,
|
|
Pierre-Yves Chibon |
b13c25 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
b13c25 |
"short": False,
|
|
Pierre-Yves Chibon |
b13c25 |
"tags": [],
|
|
Pierre-Yves Chibon |
b13c25 |
"username": None
|
|
Pierre-Yves Chibon |
b13c25 |
},
|
|
Pierre-Yves Chibon |
b13c25 |
"pagination": {
|
|
Pierre-Yves Chibon |
b13c25 |
"next": None,
|
|
Pierre-Yves Chibon |
b13c25 |
"page": 99999,
|
|
Pierre-Yves Chibon |
b13c25 |
"pages": 1,
|
|
Pierre-Yves Chibon |
b13c25 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
b13c25 |
},
|
|
Pierre-Yves Chibon |
b13c25 |
"projects": [],
|
|
Pierre-Yves Chibon |
b13c25 |
"total_projects": 3
|
|
Pierre-Yves Chibon |
b13c25 |
}
|
|
Pierre-Yves Chibon |
b13c25 |
)
|
|
Matt Prahl |
a01c25 |
|
|
Matt Prahl |
30f8b1 |
def test_api_modify_project_main_admin(self):
|
|
Matt Prahl |
ab0f46 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
ab0f46 |
request is to change the main_admin of the project. """
|
|
Matt Prahl |
30f8b1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
30f8b1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'foo'})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_created'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_modified'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_groups": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_users": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"owner": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo"
|
|
mprahl |
0f9ac5 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"close_status": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"Invalid",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Fixed",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Duplicate"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_created": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_modified": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"id": 1,
|
|
Pierre-Yves Chibon |
ae22c6 |
"milestones": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"namespace": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"parent": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"priorities": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"tags": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"user": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"default_email": "foo@bar.com",
|
|
Pierre-Yves Chibon |
ae22c6 |
"emails": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo@bar.com"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "foo"
|
|
mprahl |
0f9ac5 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
mprahl |
8f40ee |
|
|
mprahl |
8f40ee |
def test_api_modify_project_main_admin_retain_access(self):
|
|
mprahl |
8f40ee |
""" Test the api_modify_project method of the flask api when the
|
|
mprahl |
8f40ee |
request is to change the main_admin of the project and retain_access
|
|
mprahl |
8f40ee |
is true. """
|
|
mprahl |
8f40ee |
tests.create_projects(self.session)
|
|
mprahl |
8f40ee |
tests.create_tokens(self.session, project_id=None)
|
|
mprahl |
8f40ee |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
mprahl |
8f40ee |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
mprahl |
8f40ee |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'foo', 'retain_access': True})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_created'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_modified'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_groups": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_users": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"pingou"
|
|
mprahl |
10dcea |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"owner": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"close_status": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"Invalid",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Fixed",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Duplicate"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_created": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_modified": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"id": 1,
|
|
Pierre-Yves Chibon |
ae22c6 |
"milestones": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"namespace": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"parent": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"priorities": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"tags": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"user": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"default_email": "foo@bar.com",
|
|
Pierre-Yves Chibon |
ae22c6 |
"emails": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo@bar.com"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "foo"
|
|
mprahl |
10dcea |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
mprahl |
10dcea |
|
|
mprahl |
10dcea |
def test_api_modify_project_main_admin_retain_access_already_user(self):
|
|
mprahl |
10dcea |
""" Test the api_modify_project method of the flask api when the
|
|
mprahl |
10dcea |
request is to change the main_admin of the project and retain_access
|
|
mprahl |
10dcea |
is true and the user becoming the main_admin already has access. """
|
|
mprahl |
10dcea |
tests.create_projects(self.session)
|
|
mprahl |
10dcea |
tests.create_tokens(self.session, project_id=None)
|
|
mprahl |
10dcea |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
mprahl |
10dcea |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
mprahl |
10dcea |
|
|
mprahl |
10dcea |
project = pagure.lib._get_project(self.session, 'test')
|
|
mprahl |
10dcea |
pagure.lib.add_user_to_project(
|
|
mprahl |
10dcea |
self.session, project,
|
|
mprahl |
10dcea |
new_user='foo',
|
|
mprahl |
10dcea |
user='pingou',
|
|
mprahl |
10dcea |
access='commit'
|
|
mprahl |
10dcea |
)
|
|
mprahl |
10dcea |
self.session.commit()
|
|
mprahl |
10dcea |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'foo', 'retain_access': True})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_created'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_modified'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_groups": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_users": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"pingou"
|
|
mprahl |
8f40ee |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"owner": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"close_status": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"Invalid",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Fixed",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Duplicate"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_created": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_modified": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"id": 1,
|
|
Pierre-Yves Chibon |
ae22c6 |
"milestones": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"namespace": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"parent": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"priorities": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"tags": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"user": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"default_email": "foo@bar.com",
|
|
Pierre-Yves Chibon |
ae22c6 |
"emails": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo@bar.com"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "foo"
|
|
mprahl |
8f40ee |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
mprahl |
8f40ee |
|
|
mprahl |
0f9ac5 |
def test_api_modify_project_main_admin_json(self):
|
|
mprahl |
0f9ac5 |
""" Test the api_modify_project method of the flask api when the
|
|
mprahl |
0f9ac5 |
request is to change the main_admin of the project using JSON. """
|
|
mprahl |
0f9ac5 |
tests.create_projects(self.session)
|
|
mprahl |
0f9ac5 |
tests.create_tokens(self.session, project_id=None)
|
|
mprahl |
0f9ac5 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
mprahl |
0f9ac5 |
headers = {'Authorization': 'token aaabbbcccddd',
|
|
mprahl |
0f9ac5 |
'Content-Type': 'application/json'}
|
|
mprahl |
0f9ac5 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data=json.dumps({'main_admin': 'foo'}))
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_created'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_modified'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_groups": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_users": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"owner": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo"
|
|
Matt Prahl |
ab0f46 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"close_status": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"Invalid",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Fixed",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Duplicate"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_created": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_modified": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"id": 1,
|
|
Pierre-Yves Chibon |
ae22c6 |
"milestones": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"namespace": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"parent": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"priorities": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"tags": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"user": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"default_email": "foo@bar.com",
|
|
Pierre-Yves Chibon |
ae22c6 |
"emails": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo@bar.com"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "foo"
|
|
Matt Prahl |
ab0f46 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
Matt Prahl |
ab0f46 |
|
|
Pierre-Yves Chibon |
b130e5 |
@patch.dict('pagure.config.config', {'PAGURE_ADMIN_USERS': 'foo'})
|
|
Matt Prahl |
ab0f46 |
def test_api_modify_project_main_admin_as_site_admin(self):
|
|
Matt Prahl |
ab0f46 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
ab0f46 |
request is to change the main_admin of the project and the user is a
|
|
Matt Prahl |
ab0f46 |
Pagure site admin. """
|
|
Matt Prahl |
ab0f46 |
tests.create_projects(self.session)
|
|
Matt Prahl |
ab0f46 |
tests.create_tokens(self.session, user_id=2, project_id=None)
|
|
Matt Prahl |
ab0f46 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
ab0f46 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Matt Prahl |
ab0f46 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'foo'})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_created'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
data['date_modified'] = '1496338274'
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_groups": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"access_users": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"admin": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"commit": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"owner": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo"
|
|
Matt Prahl |
30f8b1 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"ticket": []
|
|
Pierre-Yves Chibon |
ae22c6 |
},
|
|
Pierre-Yves Chibon |
ae22c6 |
"close_status": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"Invalid",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Fixed",
|
|
Pierre-Yves Chibon |
ae22c6 |
"Duplicate"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_created": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"date_modified": "1496338274",
|
|
Pierre-Yves Chibon |
ae22c6 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"id": 1,
|
|
Pierre-Yves Chibon |
ae22c6 |
"milestones": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "test",
|
|
Pierre-Yves Chibon |
ae22c6 |
"namespace": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"parent": None,
|
|
Pierre-Yves Chibon |
ae22c6 |
"priorities": {},
|
|
Pierre-Yves Chibon |
ae22c6 |
"tags": [],
|
|
Pierre-Yves Chibon |
ae22c6 |
"user": {
|
|
Pierre-Yves Chibon |
ae22c6 |
"default_email": "foo@bar.com",
|
|
Pierre-Yves Chibon |
ae22c6 |
"emails": [
|
|
Pierre-Yves Chibon |
ae22c6 |
"foo@bar.com"
|
|
Pierre-Yves Chibon |
ae22c6 |
],
|
|
Pierre-Yves Chibon |
ae22c6 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
ae22c6 |
"name": "foo"
|
|
Matt Prahl |
30f8b1 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
Matt Prahl |
30f8b1 |
|
|
Matt Prahl |
30f8b1 |
def test_api_modify_project_main_admin_not_main_admin(self):
|
|
Matt Prahl |
30f8b1 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
30f8b1 |
requester is not the main_admin of the project and requests to change
|
|
Matt Prahl |
30f8b1 |
the main_admin.
|
|
Matt Prahl |
30f8b1 |
"""
|
|
Matt Prahl |
30f8b1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
30f8b1 |
project_user = pagure.lib.model.ProjectUser(
|
|
Matt Prahl |
30f8b1 |
project_id=1,
|
|
Matt Prahl |
30f8b1 |
user_id=2,
|
|
Matt Prahl |
30f8b1 |
access='admin',
|
|
Matt Prahl |
30f8b1 |
)
|
|
Matt Prahl |
30f8b1 |
self.session.add(project_user)
|
|
Matt Prahl |
30f8b1 |
self.session.commit()
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens(self.session, project_id=None, user_id=2)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
30f8b1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'foo'})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_error = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'error': ('Only the main admin can set the main admin of a '
|
|
Pierre-Yves Chibon |
ae22c6 |
'project'),
|
|
Pierre-Yves Chibon |
ae22c6 |
'error_code': 'ENOTMAINADMIN'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ae22c6 |
json.loads(output.get_data(as_text=True)), expected_error)
|
|
Matt Prahl |
30f8b1 |
|
|
Matt Prahl |
30f8b1 |
def test_api_modify_project_not_admin(self):
|
|
Matt Prahl |
30f8b1 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
30f8b1 |
requester is not an admin of the project.
|
|
Matt Prahl |
30f8b1 |
"""
|
|
Matt Prahl |
30f8b1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens(self.session, project_id=None, user_id=2)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
30f8b1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'foo'})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_error = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'error': 'You are not allowed to modify this project',
|
|
Pierre-Yves Chibon |
ae22c6 |
'error_code': 'EMODIFYPROJECTNOTALLOWED'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ae22c6 |
json.loads(output.get_data(as_text=True)), expected_error)
|
|
Matt Prahl |
30f8b1 |
|
|
Matt Prahl |
30f8b1 |
def test_api_modify_project_invalid_request(self):
|
|
Matt Prahl |
30f8b1 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
30f8b1 |
request data is invalid.
|
|
Matt Prahl |
30f8b1 |
"""
|
|
Matt Prahl |
30f8b1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
30f8b1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data='invalid')
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_error = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'error': 'Invalid or incomplete input submitted',
|
|
Pierre-Yves Chibon |
ae22c6 |
'error_code': 'EINVALIDREQ'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ae22c6 |
json.loads(output.get_data(as_text=True)), expected_error)
|
|
Matt Prahl |
30f8b1 |
|
|
Matt Prahl |
30f8b1 |
def test_api_modify_project_invalid_keys(self):
|
|
Matt Prahl |
30f8b1 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
30f8b1 |
request data contains an invalid key.
|
|
Matt Prahl |
30f8b1 |
"""
|
|
Matt Prahl |
30f8b1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
30f8b1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'invalid': 'invalid'})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_error = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'error': 'Invalid or incomplete input submitted',
|
|
Pierre-Yves Chibon |
ae22c6 |
'error_code': 'EINVALIDREQ'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ae22c6 |
json.loads(output.get_data(as_text=True)), expected_error)
|
|
Matt Prahl |
30f8b1 |
|
|
Matt Prahl |
30f8b1 |
def test_api_modify_project_invalid_new_main_admin(self):
|
|
Matt Prahl |
30f8b1 |
""" Test the api_modify_project method of the flask api when the
|
|
Matt Prahl |
30f8b1 |
request is to change the main_admin of the project to a main_admin
|
|
Matt Prahl |
30f8b1 |
that doesn't exist.
|
|
Matt Prahl |
30f8b1 |
"""
|
|
Matt Prahl |
30f8b1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
30f8b1 |
tests.create_tokens_acl(self.session, 'aaabbbcccddd', 'modify_project')
|
|
Matt Prahl |
30f8b1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.patch(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'main_admin': 'tbrady'})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_error = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'error': 'No such user found',
|
|
Pierre-Yves Chibon |
ae22c6 |
'error_code': 'ENOUSER'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ae22c6 |
json.loads(output.get_data(as_text=True)), expected_error)
|
|
Matt Prahl |
30f8b1 |
|
|
Matt Prahl |
733eaa |
def test_api_project_watchers(self):
|
|
Matt Prahl |
733eaa |
""" Test the api_project_watchers method of the flask api. """
|
|
Matt Prahl |
733eaa |
tests.create_projects(self.session)
|
|
Matt Prahl |
733eaa |
# The user is not logged in and the owner is watching issues implicitly
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 1,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"pingou": [
|
|
Matt Prahl |
733eaa |
"issues"
|
|
Matt Prahl |
733eaa |
]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Pierre-Yves Chibon |
594b28 |
user = tests.FakeUser(username='pingou')
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Matt Prahl |
733eaa |
# Non-existing project
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/random/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Matt Prahl |
733eaa |
self.assertDictEqual(
|
|
Matt Prahl |
733eaa |
data,
|
|
Matt Prahl |
733eaa |
{'error_code': 'ENOPROJECT', 'error': 'Project not found'}
|
|
Matt Prahl |
733eaa |
)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner is watching issues implicitly
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 1,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"pingou": [
|
|
Matt Prahl |
733eaa |
"issues"
|
|
Matt Prahl |
733eaa |
]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner is watching issues and commits explicitly
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '3')
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 1,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"pingou": [
|
|
Matt Prahl |
733eaa |
"issues",
|
|
Matt Prahl |
733eaa |
"commits"
|
|
Matt Prahl |
733eaa |
]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner is watching issues explicitly
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '1')
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 1,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"pingou": [
|
|
Matt Prahl |
733eaa |
"issues"
|
|
Matt Prahl |
733eaa |
]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner is watching commits explicitly
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '2')
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 1,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"pingou": [
|
|
Matt Prahl |
733eaa |
"commits"
|
|
Matt Prahl |
733eaa |
]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner is watching commits explicitly and foo is watching
|
|
Matt Prahl |
733eaa |
# issues implicitly
|
|
Matt Prahl |
733eaa |
project_user = pagure.lib.model.ProjectUser(
|
|
Matt Prahl |
733eaa |
project_id=project.id,
|
|
Matt Prahl |
733eaa |
user_id=2,
|
|
Matt Prahl |
733eaa |
access='commit',
|
|
Matt Prahl |
733eaa |
)
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '2')
|
|
Pierre-Yves Chibon |
594b28 |
self.session.add(project_user)
|
|
Pierre-Yves Chibon |
594b28 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 2,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"foo": ["issues"],
|
|
Matt Prahl |
733eaa |
"pingou": ["commits"]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner and foo are watching issues implicitly
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '-1')
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 2,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Matt Prahl |
733eaa |
"foo": ["issues"],
|
|
Matt Prahl |
733eaa |
"pingou": ["issues"]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner and foo through group membership are watching issues
|
|
Matt Prahl |
733eaa |
# implicitly
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '-1')
|
|
Pierre-Yves Chibon |
594b28 |
project_membership = self.session.query(
|
|
Matt Prahl |
733eaa |
pagure.lib.model.ProjectUser).filter_by(
|
|
Matt Prahl |
733eaa |
user_id=2, project_id=project.id).one()
|
|
Pierre-Yves Chibon |
594b28 |
self.session.delete(project_membership)
|
|
Pierre-Yves Chibon |
594b28 |
self.session.commit()
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Matt Prahl |
733eaa |
msg = pagure.lib.add_group(
|
|
Matt Prahl |
733eaa |
self.session,
|
|
Matt Prahl |
733eaa |
group_name='some_group',
|
|
Matt Prahl |
733eaa |
display_name='Some Group',
|
|
Matt Prahl |
733eaa |
description=None,
|
|
Matt Prahl |
733eaa |
group_type='bar',
|
|
Matt Prahl |
733eaa |
user='pingou',
|
|
Matt Prahl |
733eaa |
is_admin=False,
|
|
Matt Prahl |
733eaa |
blacklist=[],
|
|
Matt Prahl |
733eaa |
)
|
|
Pierre-Yves Chibon |
594b28 |
self.session.commit()
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
b130e5 |
project = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
594b28 |
group = pagure.lib.search_groups(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, group_name='some_group')
|
|
Matt Prahl |
733eaa |
pagure.lib.add_user_to_group(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, 'foo', group, 'pingou', False)
|
|
Pierre-Yves Chibon |
594b28 |
|
|
Pierre-Yves Chibon |
594b28 |
pagure.lib.add_group_to_project(
|
|
Pierre-Yves Chibon |
594b28 |
self.session,
|
|
Pierre-Yves Chibon |
594b28 |
project,
|
|
Pierre-Yves Chibon |
594b28 |
new_group='some_group',
|
|
Pierre-Yves Chibon |
594b28 |
user='pingou',
|
|
Matt Prahl |
733eaa |
access='commit',
|
|
Pierre-Yves Chibon |
594b28 |
create=False,
|
|
Pierre-Yves Chibon |
594b28 |
is_admin=True
|
|
Matt Prahl |
733eaa |
)
|
|
Pierre-Yves Chibon |
594b28 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Matt Prahl |
733eaa |
"total_watchers": 2,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Ralph Bean |
e69883 |
"@some_group": ["issues"],
|
|
Matt Prahl |
733eaa |
"pingou": ["issues"]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
# The owner is watching issues implicitly and foo will be watching
|
|
Matt Prahl |
733eaa |
# commits explicitly but is in a group with commit access
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'pingou', '-1')
|
|
Matt Prahl |
733eaa |
pagure.lib.update_watch_status(
|
|
Pierre-Yves Chibon |
594b28 |
self.session, project, 'foo', '2')
|
|
Pierre-Yves Chibon |
fd2f36 |
self.session.commit()
|
|
Matt Prahl |
733eaa |
|
|
Matt Prahl |
733eaa |
output = self.app.get('/api/0/test/watchers')
|
|
Matt Prahl |
733eaa |
self.assertEqual(output.status_code, 200)
|
|
Matt Prahl |
733eaa |
expected_data = {
|
|
Ralph Bean |
e69883 |
"total_watchers": 3,
|
|
Matt Prahl |
733eaa |
"watchers": {
|
|
Ralph Bean |
e69883 |
"@some_group": ["issues"],
|
|
Matt Prahl |
733eaa |
"foo": ["commits"],
|
|
Matt Prahl |
733eaa |
"pingou": ["issues"]
|
|
Matt Prahl |
733eaa |
}
|
|
Matt Prahl |
733eaa |
}
|
|
Aurélien Bompard |
626417 |
self.assertDictEqual(json.loads(output.get_data(as_text=True)), expected_data)
|
|
Matt Prahl |
733eaa |
|
|
Aurélien Bompard |
24a837 |
def test_api_new_project(self):
|
|
Pierre-Yves Chibon |
1c1b5d |
""" Test the api_new_project method of the flask api. """
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
b63f28 |
tests.create_projects(self.session)
|
|
Jeremy Cline |
20109f |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
1c1b5d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
1c1b5d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
headers = {'Authorization': 'token foo_token'}
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
# Invalid token
|
|
Pierre-Yves Chibon |
1c1b5d |
output = self.app.post('/api/0/new', headers=headers)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
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'])
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
# No input
|
|
Pierre-Yves Chibon |
1c1b5d |
output = self.app.post('/api/0/new', headers=headers)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
1c1b5d |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {
|
|
Pierre-Yves Chibon |
f7fcaa |
"name": ["This field is required."],
|
|
Pierre-Yves Chibon |
f7fcaa |
"description": ["This field is required."]
|
|
Pierre-Yves Chibon |
f7fcaa |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
)
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
data = {
|
|
Pierre-Yves Chibon |
1c1b5d |
'name': 'test',
|
|
Pierre-Yves Chibon |
1c1b5d |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
# Incomplete request
|
|
Pierre-Yves Chibon |
1c1b5d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1c1b5d |
'/api/0/new', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
1c1b5d |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {"description": ["This field is required."]}
|
|
Pierre-Yves Chibon |
1c1b5d |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
)
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
data = {
|
|
Pierre-Yves Chibon |
1c1b5d |
'name': 'test',
|
|
Pierre-Yves Chibon |
1c1b5d |
'description': 'Just a small test project',
|
|
Pierre-Yves Chibon |
1c1b5d |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
# Valid request but repo already exists
|
|
Pierre-Yves Chibon |
1c1b5d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1c1b5d |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{
|
|
Pierre-Yves Chibon |
b130e5 |
"error": "It is not possible to create the repo \"test\"",
|
|
Pierre-Yves Chibon |
1c1b5d |
"error_code": "ENOCODE"
|
|
Pierre-Yves Chibon |
1c1b5d |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
)
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
data = {
|
|
Pierre-Yves Chibon |
1c1b5d |
'name': 'test_42',
|
|
Pierre-Yves Chibon |
1c1b5d |
'description': 'Just another small test project',
|
|
Pierre-Yves Chibon |
1c1b5d |
}
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
1c1b5d |
# Valid request
|
|
Pierre-Yves Chibon |
1c1b5d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1c1b5d |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{'message': 'Project "test_42" created'}
|
|
Pierre-Yves Chibon |
1c1b5d |
)
|
|
Pierre-Yves Chibon |
1c1b5d |
|
|
Pierre-Yves Chibon |
b130e5 |
@patch.dict('pagure.config.config', {'PRIVATE_PROJECTS': True})
|
|
Aurélien Bompard |
24a837 |
def test_api_new_project_private(self):
|
|
Pierre-Yves Chibon |
3a7944 |
""" Test the api_new_project method of the flask api to create
|
|
Pierre-Yves Chibon |
3a7944 |
a private project. """
|
|
Pierre-Yves Chibon |
3a7944 |
|
|
Pierre-Yves Chibon |
3a7944 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
3a7944 |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
3a7944 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
3a7944 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
3a7944 |
|
|
Pierre-Yves Chibon |
3a7944 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
3a7944 |
|
|
Pierre-Yves Chibon |
3a7944 |
data = {
|
|
Pierre-Yves Chibon |
3a7944 |
'name': 'test',
|
|
Pierre-Yves Chibon |
3a7944 |
'description': 'Just a small test project',
|
|
Pierre-Yves Chibon |
3a7944 |
'private': True,
|
|
Pierre-Yves Chibon |
3a7944 |
}
|
|
Pierre-Yves Chibon |
3a7944 |
|
|
Pierre-Yves Chibon |
3a7944 |
# Valid request
|
|
Pierre-Yves Chibon |
3a7944 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
3a7944 |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
3a7944 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
3a7944 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
3a7944 |
data,
|
|
Pierre-Yves Chibon |
3a7944 |
{'message': 'Project "pingou/test" created'}
|
|
Pierre-Yves Chibon |
3a7944 |
)
|
|
Pierre-Yves Chibon |
3a7944 |
|
|
Aurélien Bompard |
24a837 |
def test_api_new_project_user_token(self):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_new_project method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
headers = {'Authorization': 'token foo_token'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Invalid token
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post('/api/0/new', headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
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'])
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# No input
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post('/api/0/new', headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {
|
|
Pierre-Yves Chibon |
1dfd94 |
"name": ["This field is required."],
|
|
Pierre-Yves Chibon |
1dfd94 |
"description": ["This field is required."]
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'name': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Incomplete request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/new', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {"description": ["This field is required."]}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'name': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
'description': 'Just a small test project',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request but repo already exists
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
b130e5 |
"error": "It is not possible to create the repo \"test\"",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOCODE"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'name': 'test_42',
|
|
Pierre-Yves Chibon |
1dfd94 |
'description': 'Just another small test project',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{'message': 'Project "test_42" created'}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
2aa56f |
# Project with a namespace
|
|
Pierre-Yves Chibon |
b130e5 |
pagure.config.config['ALLOWED_PREFIX'] = ['rpms']
|
|
Pierre-Yves Chibon |
2aa56f |
data = {
|
|
Pierre-Yves Chibon |
2aa56f |
'name': 'test_42',
|
|
Pierre-Yves Chibon |
2aa56f |
'namespace': 'pingou',
|
|
Pierre-Yves Chibon |
2aa56f |
'description': 'Just another small test project',
|
|
Pierre-Yves Chibon |
2aa56f |
}
|
|
Pierre-Yves Chibon |
2aa56f |
|
|
Pierre-Yves Chibon |
2aa56f |
# Invalid namespace
|
|
Pierre-Yves Chibon |
2aa56f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
2aa56f |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
2aa56f |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
2aa56f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
2aa56f |
data,
|
|
Pierre-Yves Chibon |
2aa56f |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
2aa56f |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
2aa56f |
"errors": {
|
|
Pierre-Yves Chibon |
2aa56f |
"namespace": [
|
|
Pierre-Yves Chibon |
2aa56f |
"Not a valid choice"
|
|
Pierre-Yves Chibon |
2aa56f |
]
|
|
Pierre-Yves Chibon |
2aa56f |
}
|
|
Pierre-Yves Chibon |
2aa56f |
}
|
|
Pierre-Yves Chibon |
2aa56f |
)
|
|
Pierre-Yves Chibon |
2aa56f |
|
|
Pierre-Yves Chibon |
2aa56f |
data = {
|
|
Pierre-Yves Chibon |
2aa56f |
'name': 'test_42',
|
|
Pierre-Yves Chibon |
2aa56f |
'namespace': 'rpms',
|
|
Pierre-Yves Chibon |
2aa56f |
'description': 'Just another small test project',
|
|
Pierre-Yves Chibon |
2aa56f |
}
|
|
Pierre-Yves Chibon |
2aa56f |
|
|
Pierre-Yves Chibon |
2aa56f |
# All good
|
|
Pierre-Yves Chibon |
2aa56f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
2aa56f |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
2aa56f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
2aa56f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
2aa56f |
data,
|
|
Pierre-Yves Chibon |
2aa56f |
{'message': 'Project "rpms/test_42" created'}
|
|
Pierre-Yves Chibon |
2aa56f |
)
|
|
Pierre-Yves Chibon |
2aa56f |
|
|
Aurélien Bompard |
24a837 |
@patch.dict('pagure.config.config', {'USER_NAMESPACE': True})
|
|
Aurélien Bompard |
24a837 |
def test_api_new_project_user_ns(self):
|
|
Pierre-Yves Chibon |
baec09 |
""" Test the api_new_project method of the flask api. """
|
|
Pierre-Yves Chibon |
baec09 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
baec09 |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
baec09 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
baec09 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Pierre-Yves Chibon |
baec09 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Pierre-Yves Chibon |
baec09 |
# Create a project with the user namespace feature on
|
|
Pierre-Yves Chibon |
baec09 |
data = {
|
|
Pierre-Yves Chibon |
baec09 |
'name': 'testproject',
|
|
Pierre-Yves Chibon |
baec09 |
'description': 'Just another small test project',
|
|
Pierre-Yves Chibon |
baec09 |
}
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Pierre-Yves Chibon |
baec09 |
# Valid request
|
|
Pierre-Yves Chibon |
baec09 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
baec09 |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
baec09 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
baec09 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
baec09 |
data,
|
|
Pierre-Yves Chibon |
baec09 |
{'message': 'Project "pingou/testproject" created'}
|
|
Pierre-Yves Chibon |
baec09 |
)
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Pierre-Yves Chibon |
baec09 |
# Create a project with a namespace and the user namespace feature on
|
|
Pierre-Yves Chibon |
baec09 |
data = {
|
|
Pierre-Yves Chibon |
baec09 |
'name': 'testproject2',
|
|
Pierre-Yves Chibon |
baec09 |
'namespace': 'testns',
|
|
Pierre-Yves Chibon |
baec09 |
'description': 'Just another small test project',
|
|
Pierre-Yves Chibon |
baec09 |
}
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Pierre-Yves Chibon |
baec09 |
# Valid request
|
|
Aurélien Bompard |
8e7c53 |
with patch.dict('pagure.config.config', {'ALLOWED_PREFIX': ['testns']}):
|
|
Aurélien Bompard |
8e7c53 |
output = self.app.post(
|
|
Aurélien Bompard |
8e7c53 |
'/api/0/new/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
baec09 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
baec09 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
baec09 |
data,
|
|
Pierre-Yves Chibon |
baec09 |
{'message': 'Project "testns/testproject2" created'}
|
|
Pierre-Yves Chibon |
baec09 |
)
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Aurélien Bompard |
24a837 |
def test_api_fork_project(self):
|
|
Pierre-Yves Chibon |
f0e08e |
""" Test the api_fork_project method of the flask api. """
|
|
Pierre-Yves Chibon |
f0e08e |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
f0e08e |
for folder in ['docs', 'tickets', 'requests', 'repos']:
|
|
Pierre-Yves Chibon |
f0e08e |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, folder), bare=True)
|
|
Pierre-Yves Chibon |
f0e08e |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
f0e08e |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
headers = {'Authorization': 'token foo_token'}
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
# Invalid token
|
|
Pierre-Yves Chibon |
f0e08e |
output = self.app.post('/api/0/fork', headers=headers)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
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'])
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# No input
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post('/api/0/fork', headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {"repo": ["This field is required."]}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'name': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Incomplete request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/fork', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {"repo": ["This field is required."]}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Repo \"test\" cloned to \"pingou/test\""
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# project already forked
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Repo \"forks/pingou/test\" already exists",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOCODE"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Fork already exists
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Repo \"forks/pingou/test\" already exists",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOCODE"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'repo': 'test',
|
|
Pierre-Yves Chibon |
1dfd94 |
'namespace': 'pingou',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Repo does not exists
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOPROJECT"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Aurélien Bompard |
24a837 |
def test_api_fork_project_user_token(self):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_fork_project method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
1dfd94 |
for folder in ['docs', 'tickets', 'requests', 'repos']:
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
1dfd94 |
os.path.join(self.path, folder), bare=True)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
headers = {'Authorization': 'token foo_token'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Invalid token
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post('/api/0/fork', headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
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'])
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
# No input
|
|
Pierre-Yves Chibon |
f0e08e |
output = self.app.post('/api/0/fork', headers=headers)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
f0e08e |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {"repo": ["This field is required."]}
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
)
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
data = {
|
|
Pierre-Yves Chibon |
f0e08e |
'name': 'test',
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
# Incomplete request
|
|
Pierre-Yves Chibon |
f0e08e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f0e08e |
'/api/0/fork', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
f0e08e |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {"repo": ["This field is required."]}
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
)
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
data = {
|
|
Pierre-Yves Chibon |
f0e08e |
'repo': 'test',
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
# Valid request
|
|
Pierre-Yves Chibon |
f0e08e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f0e08e |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
Pierre-Yves Chibon |
f0e08e |
"message": "Repo \"test\" cloned to \"pingou/test\""
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
)
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
data = {
|
|
Pierre-Yves Chibon |
f0e08e |
'repo': 'test',
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
# project already forked
|
|
Pierre-Yves Chibon |
f0e08e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f0e08e |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
Pierre-Yves Chibon |
f0e08e |
"error": "Repo \"forks/pingou/test\" already exists",
|
|
Pierre-Yves Chibon |
f0e08e |
"error_code": "ENOCODE"
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
)
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
data = {
|
|
Pierre-Yves Chibon |
f0e08e |
'repo': 'test',
|
|
Pierre-Yves Chibon |
f0e08e |
'username': 'pingou',
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
Pierre-Yves Chibon |
f0e08e |
# Fork already exists
|
|
Pierre-Yves Chibon |
f0e08e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f0e08e |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
Pierre-Yves Chibon |
f0e08e |
"error": "Repo \"forks/pingou/test\" already exists",
|
|
Pierre-Yves Chibon |
f0e08e |
"error_code": "ENOCODE"
|
|
Pierre-Yves Chibon |
f0e08e |
}
|
|
Pierre-Yves Chibon |
f0e08e |
)
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
2c43bb |
data = {
|
|
Pierre-Yves Chibon |
2c43bb |
'repo': 'test',
|
|
Pierre-Yves Chibon |
2c43bb |
'namespace': 'pingou',
|
|
Pierre-Yves Chibon |
2c43bb |
}
|
|
Pierre-Yves Chibon |
2c43bb |
|
|
Pierre-Yves Chibon |
2c43bb |
# Repo does not exists
|
|
Pierre-Yves Chibon |
2c43bb |
output = self.app.post(
|
|
Pierre-Yves Chibon |
2c43bb |
'/api/0/fork/', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
2c43bb |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
2c43bb |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
2c43bb |
data,
|
|
Pierre-Yves Chibon |
2c43bb |
{
|
|
Pierre-Yves Chibon |
2c43bb |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
2c43bb |
"error_code": "ENOPROJECT"
|
|
Pierre-Yves Chibon |
2c43bb |
}
|
|
Pierre-Yves Chibon |
2c43bb |
)
|
|
Pierre-Yves Chibon |
2c43bb |
|
|
Aurélien Bompard |
24a837 |
def test_api_generate_acls(self):
|
|
Matt Prahl |
489ad1 |
""" Test the api_generate_acls method of the flask api """
|
|
Matt Prahl |
489ad1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
489ad1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
489ad1 |
tests.create_tokens_acl(
|
|
Matt Prahl |
489ad1 |
self.session, 'aaabbbcccddd', 'generate_acls_project')
|
|
Matt Prahl |
489ad1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Matt Prahl |
489ad1 |
|
|
Matt Prahl |
489ad1 |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test/git/generateacls', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'wait': False})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'message': 'Project ACL generation queued',
|
|
Pierre-Yves Chibon |
ae22c6 |
'taskid': 'abc-1234'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
ae22c6 |
self.mock_gen_acls.assert_called_once_with(
|
|
Pierre-Yves Chibon |
ae22c6 |
name='test', namespace=None, user=None, group=None)
|
|
mprahl |
0f9ac5 |
|
|
Aurélien Bompard |
24a837 |
def test_api_generate_acls_json(self):
|
|
mprahl |
0f9ac5 |
""" Test the api_generate_acls method of the flask api using JSON """
|
|
mprahl |
0f9ac5 |
tests.create_projects(self.session)
|
|
mprahl |
0f9ac5 |
tests.create_tokens(self.session, project_id=None)
|
|
mprahl |
0f9ac5 |
tests.create_tokens_acl(
|
|
mprahl |
0f9ac5 |
self.session, 'aaabbbcccddd', 'generate_acls_project')
|
|
mprahl |
0f9ac5 |
headers = {'Authorization': 'token aaabbbcccddd',
|
|
mprahl |
0f9ac5 |
'Content-Type': 'application/json'}
|
|
mprahl |
0f9ac5 |
|
|
mprahl |
0f9ac5 |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
ae22c6 |
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test/git/generateacls', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data=json.dumps({'wait': False}))
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'message': 'Project ACL generation queued',
|
|
Pierre-Yves Chibon |
ae22c6 |
'taskid': 'abc-1234'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
ae22c6 |
self.mock_gen_acls.assert_called_once_with(
|
|
Pierre-Yves Chibon |
ae22c6 |
name='test', namespace=None, user=None, group=None)
|
|
Matt Prahl |
489ad1 |
|
|
Aurélien Bompard |
24a837 |
def test_api_generate_acls_wait_true(self):
|
|
Matt Prahl |
489ad1 |
""" Test the api_generate_acls method of the flask api when wait is
|
|
Matt Prahl |
489ad1 |
set to True """
|
|
Matt Prahl |
489ad1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
489ad1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
489ad1 |
tests.create_tokens_acl(
|
|
Matt Prahl |
489ad1 |
self.session, 'aaabbbcccddd', 'generate_acls_project')
|
|
Matt Prahl |
489ad1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Matt Prahl |
489ad1 |
|
|
Aurélien Bompard |
24a837 |
task_result = Mock()
|
|
Aurélien Bompard |
24a837 |
task_result.id = 'abc-1234'
|
|
Aurélien Bompard |
24a837 |
self.mock_gen_acls.return_value = task_result
|
|
Matt Prahl |
489ad1 |
|
|
Matt Prahl |
489ad1 |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test/git/generateacls', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'wait': True})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'message': 'Project ACLs generated',
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
ae22c6 |
self.mock_gen_acls.assert_called_once_with(
|
|
Pierre-Yves Chibon |
ae22c6 |
name='test', namespace=None, user=None, group=None)
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertTrue(task_result.get.called)
|
|
Matt Prahl |
489ad1 |
|
|
Matt Prahl |
489ad1 |
def test_api_generate_acls_no_project(self):
|
|
Matt Prahl |
489ad1 |
""" Test the api_generate_acls method of the flask api when the project
|
|
Matt Prahl |
489ad1 |
doesn't exist """
|
|
Matt Prahl |
489ad1 |
tests.create_projects(self.session)
|
|
Matt Prahl |
489ad1 |
tests.create_tokens(self.session, project_id=None)
|
|
Matt Prahl |
489ad1 |
tests.create_tokens_acl(
|
|
Matt Prahl |
489ad1 |
self.session, 'aaabbbcccddd', 'generate_acls_project')
|
|
Matt Prahl |
489ad1 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Matt Prahl |
489ad1 |
|
|
Matt Prahl |
489ad1 |
user = pagure.lib.get_user(self.session, 'pingou')
|
|
Pierre-Yves Chibon |
ae22c6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
ae22c6 |
'/api/0/test12345123/git/generateacls', headers=headers,
|
|
Pierre-Yves Chibon |
ae22c6 |
data={'wait': False})
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ae22c6 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ae22c6 |
expected_output = {
|
|
Pierre-Yves Chibon |
ae22c6 |
'error_code': 'ENOPROJECT',
|
|
Pierre-Yves Chibon |
ae22c6 |
'error': 'Project not found'
|
|
Pierre-Yves Chibon |
ae22c6 |
}
|
|
Pierre-Yves Chibon |
ae22c6 |
self.assertEqual(data, expected_output)
|
|
Matt Prahl |
489ad1 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_new_git_branch(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_new_branch method of the flask api """
|
|
Karsten Hopp |
be01e8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_path = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects_git(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.add_content_git_repo(os.path.join(repo_path, 'test.git'))
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens(self.session, project_id=None)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'aaabbbcccddd', 'create_branch')
|
|
Karsten Hopp |
be01e8 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
args = {'branch': 'test123'}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post('/api/0/test/git/branch', headers=headers,
|
|
Pierre-Yves Chibon |
6ffde7 |
data=args)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Project branch was created',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
git_path = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertIn('test123', repo_obj.listall_branches())
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_new_git_branch_json(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_new_branch method of the flask api """
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_path = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects_git(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.add_content_git_repo(os.path.join(repo_path, 'test.git'))
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'aaabbbcccddd', 'create_branch')
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd',
|
|
Pierre-Yves Chibon |
6ffde7 |
'Content-Type': 'application/json'}
|
|
Pierre-Yves Chibon |
6ffde7 |
args = {'branch': 'test123'}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post('/api/0/test/git/branch', headers=headers,
|
|
Pierre-Yves Chibon |
6ffde7 |
data=json.dumps(args))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Project branch was created',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
git_path = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertIn('test123', repo_obj.listall_branches())
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_new_git_branch_from_branch(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_new_branch method of the flask api """
|
|
Karsten Hopp |
be01e8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_path = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects_git(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.add_content_git_repo(os.path.join(repo_path, 'test.git'))
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens(self.session, project_id=None)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'aaabbbcccddd', 'create_branch')
|
|
Pierre-Yves Chibon |
6ffde7 |
git_path = os.path.join(self.path, 'repos', 'test.git')
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
parent = pagure.lib.git.get_branch_ref(repo_obj, 'master').get_object()
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj.create_branch('dev123', parent)
|
|
Karsten Hopp |
be01e8 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
args = {'branch': 'test123', 'from_branch': 'dev123'}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post('/api/0/test/git/branch', headers=headers,
|
|
Pierre-Yves Chibon |
6ffde7 |
data=args)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Project branch was created',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertIn('test123', repo_obj.listall_branches())
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_new_git_branch_already_exists(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_new_branch method of the flask api when branch already
|
|
Pierre-Yves Chibon |
6ffde7 |
exists """
|
|
Karsten Hopp |
be01e8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_path = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects_git(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.add_content_git_repo(os.path.join(repo_path, 'test.git'))
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens(self.session, project_id=None)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'aaabbbcccddd', 'create_branch')
|
|
Karsten Hopp |
be01e8 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
args = {'branch': 'master'}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post('/api/0/test/git/branch', headers=headers,
|
|
Pierre-Yves Chibon |
6ffde7 |
data=args)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'The branch "master" already exists',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'ENOCODE'
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_new_git_branch_from_commit(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_new_branch method of the flask api """
|
|
Karsten Hopp |
be01e8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
6ffde7 |
repos_path = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects_git(repos_path, bare=True)
|
|
Pierre-Yves Chibon |
6ffde7 |
git_path = os.path.join(repos_path, 'test.git')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.add_content_git_repo(git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_tokens(self.session, project_id=None)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'aaabbbcccddd', 'create_branch')
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
from_commit = repo_obj.revparse_single('HEAD').oid.hex
|
|
Karsten Hopp |
be01e8 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
args = {'branch': 'test123', 'from_commit': from_commit}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post('/api/0/test/git/branch', headers=headers,
|
|
Pierre-Yves Chibon |
6ffde7 |
data=args)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Project branch was created',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertIn('test123', repo_obj.listall_branches())
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
class PagureFlaskApiProjectFlagtests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Tests for the flask API of pagure for flagging commit in project
|
|
Pierre-Yves Chibon |
6ffde7 |
"""
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def setUp(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
6ffde7 |
super(PagureFlaskApiProjectFlagtests, self).setUp()
|
|
Karsten Hopp |
be01e8 |
|
|
Karsten Hopp |
be01e8 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_path = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.git_path = os.path.join(repo_path, 'test.git')
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_projects_git(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.add_content_git_repo(self.git_path)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens(self.session, project_id=None)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'aaabbbcccddd', 'commit_flag')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_missing_status(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with missing precentage. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Karsten Hopp |
be01e8 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Karsten Hopp |
be01e8 |
headers=headers, data=data)
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(output.status_code, 400)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
6ffde7 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
6ffde7 |
"errors": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"status": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"Not a valid choice"
|
|
Pierre-Yves Chibon |
6ffde7 |
]
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_missing_username(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with missing username. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Karsten Hopp |
be01e8 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Karsten Hopp |
be01e8 |
headers=headers, data=data)
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(output.status_code, 400)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
6ffde7 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
6ffde7 |
"errors": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"username": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"This field is required."
|
|
Pierre-Yves Chibon |
6ffde7 |
]
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_missing_comment(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with missing comment. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Karsten Hopp |
be01e8 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Karsten Hopp |
be01e8 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
6ffde7 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
6ffde7 |
"errors": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"comment": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"This field is required."
|
|
Pierre-Yves Chibon |
6ffde7 |
]
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_missing_url(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with missing url. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
6ffde7 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
6ffde7 |
"errors": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"url": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"This field is required."
|
|
Pierre-Yves Chibon |
6ffde7 |
]
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_invalid_token(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with missing info. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token 123'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(sorted(data.keys()), ['error', 'error_code'])
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
6ffde7 |
pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
6ffde7 |
pagure.api.APIERROR.EINVALIDTOK.name, data['error_code'])
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_invalid_status(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with an invalid status. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'foobar',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
6ffde7 |
data,
|
|
Pierre-Yves Chibon |
6ffde7 |
{
|
|
Pierre-Yves Chibon |
6ffde7 |
'errors': {'status': ['Not a valid choice']},
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'EINVALIDREQ',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'Invalid or incomplete input submitted'
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_with_uid(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with provided uid. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
data['flag']['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['flag']['commit_hash'] = '62b49f00d489452994de5010565fab81'
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'flag': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'commit_hash': '62b49f00d489452994de5010565fab81',
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_created': '1510742565',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'user': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'default_email': 'bar@pingou.com',
|
|
Pierre-Yves Chibon |
6ffde7 |
'emails': ['bar@pingou.com', 'foo@pingou.com'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'fullname': 'PY C',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'pingou'},
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins'
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Flag added',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'jenkins_build_pagure_100+seed'
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_without_uid(self, mock_email):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with missing info.
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
Also ensure notifications aren't sent when they are not asked for.
|
|
Pierre-Yves Chibon |
6ffde7 |
"""
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertNotEqual(
|
|
Pierre-Yves Chibon |
6ffde7 |
data['uid'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'jenkins_build_pagure_100+seed'
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
data['flag']['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['uid'] = 'b1de8f80defd4a81afe2e09f39678087'
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'flag': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'commit_hash': commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_created': '1510742565',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'user': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'default_email': 'bar@pingou.com',
|
|
Pierre-Yves Chibon |
6ffde7 |
'emails': ['bar@pingou.com', 'foo@pingou.com'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'fullname': 'PY C',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'pingou'},
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins'
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Flag added',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'b1de8f80defd4a81afe2e09f39678087'
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
mock_email.assert_not_called()
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_with_notification(self, mock_email):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging a commit with notification enabled. """
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Enable commit notifications
|
|
Pierre-Yves Chibon |
6ffde7 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
6ffde7 |
settings['notify_on_commit_flag'] = True
|
|
Pierre-Yves Chibon |
6ffde7 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertNotEqual(
|
|
Pierre-Yves Chibon |
6ffde7 |
data['uid'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'jenkins_build_pagure_100+seed'
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
data['flag']['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['uid'] = 'b1de8f80defd4a81afe2e09f39678087'
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'flag': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'commit_hash': commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_created': '1510742565',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'success',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'user': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'default_email': 'bar@pingou.com',
|
|
Pierre-Yves Chibon |
6ffde7 |
'emails': ['bar@pingou.com', 'foo@pingou.com'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'fullname': 'PY C',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'pingou'},
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins'
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
'message': 'Flag added',
|
|
Pierre-Yves Chibon |
6ffde7 |
'uid': 'b1de8f80defd4a81afe2e09f39678087'
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
mock_email.assert_called_once_with(
|
|
Pierre-Yves Chibon |
6ffde7 |
'\nJenkins flagged the commit '
|
|
Pierre-Yves Chibon |
6ffde7 |
'`' + commit.oid.hex + '` as success: '
|
|
Pierre-Yves Chibon |
6ffde7 |
'Tests passed\n\n'
|
|
Pierre-Yves Chibon |
6ffde7 |
'http://localhost.localdomain/test/c/' + commit.oid.hex + '\n',
|
|
Pierre-Yves Chibon |
6ffde7 |
'Coommit #' + commit.oid.hex + ' - Jenkins: success',
|
|
Pierre-Yves Chibon |
6ffde7 |
'bar@pingou.com',
|
|
Pierre-Yves Chibon |
6ffde7 |
in_reply_to='test-project-1',
|
|
Pierre-Yves Chibon |
6ffde7 |
mail_id='test-commit-1-1',
|
|
Pierre-Yves Chibon |
6ffde7 |
project_name='test',
|
|
Pierre-Yves Chibon |
6ffde7 |
user_from='Jenkins'
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
@patch.dict('pagure.config.config',
|
|
Pierre-Yves Chibon |
6ffde7 |
{
|
|
Pierre-Yves Chibon |
6ffde7 |
'FLAG_STATUSES_LABELS':
|
|
Pierre-Yves Chibon |
6ffde7 |
{
|
|
Pierre-Yves Chibon |
6ffde7 |
'pend!': 'label-info',
|
|
Pierre-Yves Chibon |
6ffde7 |
'succeed!': 'label-success',
|
|
Pierre-Yves Chibon |
6ffde7 |
'fail!': 'label-danger',
|
|
Pierre-Yves Chibon |
6ffde7 |
'what?': 'label-warning',
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
'FLAG_PENDING': 'pend!',
|
|
Pierre-Yves Chibon |
6ffde7 |
'FLAG_SUCCESS': 'succeed!',
|
|
Pierre-Yves Chibon |
6ffde7 |
'FLAG_FAILURE': 'fail!',
|
|
Pierre-Yves Chibon |
6ffde7 |
})
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_flag_commit_with_custom_flags(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test flagging when custom flags are set up
|
|
Pierre-Yves Chibon |
6ffde7 |
"""
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
send_data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
6ffde7 |
'percent': 100,
|
|
Pierre-Yves Chibon |
6ffde7 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
6ffde7 |
'status': 'succeed!',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=send_data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data['flag']['status'], 'succeed!')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Try invalid flag status
|
|
Pierre-Yves Chibon |
6ffde7 |
send_data['status'] = 'nooooo....'
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/c/%s/flag' % commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=send_data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
6ffde7 |
data,
|
|
Pierre-Yves Chibon |
6ffde7 |
{
|
|
Pierre-Yves Chibon |
6ffde7 |
'errors': {'status': ['Not a valid choice']},
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'EINVALIDREQ',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'Invalid or incomplete input submitted'
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_commit_flags(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test retrieving commit flags. """
|
|
Pierre-Yves Chibon |
6ffde7 |
repo = pagure.lib.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
repo_obj = pygit2.Repository(self.git_path)
|
|
Pierre-Yves Chibon |
6ffde7 |
commit = repo_obj.revparse_single('HEAD')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# test with no flags
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.get('/api/0/test/c/%s/flag' % commit.oid.hex)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(json.loads(output.get_data(as_text=True)), {'total_flags': 0, 'flags': []})
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# add some flags and retrieve them
|
|
Pierre-Yves Chibon |
6ffde7 |
pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
6ffde7 |
session=self.session,
|
|
Pierre-Yves Chibon |
6ffde7 |
repo=repo,
|
|
Pierre-Yves Chibon |
6ffde7 |
commit_hash=commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
username='simple-koji-ci',
|
|
Pierre-Yves Chibon |
6ffde7 |
status='pending',
|
|
Pierre-Yves Chibon |
6ffde7 |
percent=None,
|
|
Pierre-Yves Chibon |
6ffde7 |
comment='Build is running',
|
|
Pierre-Yves Chibon |
6ffde7 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
6ffde7 |
uid='uid',
|
|
Pierre-Yves Chibon |
6ffde7 |
user='foo',
|
|
Pierre-Yves Chibon |
6ffde7 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
pagure.lib.add_commit_flag(
|
|
Pierre-Yves Chibon |
6ffde7 |
session=self.session,
|
|
Pierre-Yves Chibon |
6ffde7 |
repo=repo,
|
|
Pierre-Yves Chibon |
6ffde7 |
commit_hash=commit.oid.hex,
|
|
Pierre-Yves Chibon |
6ffde7 |
username='complex-koji-ci',
|
|
Pierre-Yves Chibon |
6ffde7 |
status='success',
|
|
Pierre-Yves Chibon |
6ffde7 |
percent=None,
|
|
Pierre-Yves Chibon |
6ffde7 |
comment='Build succeeded',
|
|
Pierre-Yves Chibon |
6ffde7 |
url='https://koji.fp.o/koji...',
|
|
Pierre-Yves Chibon |
6ffde7 |
uid='uid2',
|
|
Pierre-Yves Chibon |
6ffde7 |
user='foo',
|
|
Pierre-Yves Chibon |
6ffde7 |
token='aaabbbcccddd'
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.get('/api/0/test/c/%s/flag' % commit.oid.hex)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
for f in data['flags']:
|
|
Pierre-Yves Chibon |
6ffde7 |
f['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
f['commit_hash'] = '62b49f00d489452994de5010565fab81'
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"flags": [
|
|
Pierre-Yves Chibon |
6ffde7 |
{
|
|
Pierre-Yves Chibon |
6ffde7 |
"comment": "Build is running",
|
|
Pierre-Yves Chibon |
6ffde7 |
"commit_hash": "62b49f00d489452994de5010565fab81",
|
|
Pierre-Yves Chibon |
6ffde7 |
"date_created": "1510742565",
|
|
Pierre-Yves Chibon |
6ffde7 |
"percent": None,
|
|
Pierre-Yves Chibon |
6ffde7 |
"status": "pending",
|
|
Pierre-Yves Chibon |
6ffde7 |
"url": "https://koji.fp.o/koji...",
|
|
Pierre-Yves Chibon |
6ffde7 |
"user": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
6ffde7 |
"name": "foo"
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
"username": "simple-koji-ci"
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
{
|
|
Pierre-Yves Chibon |
6ffde7 |
"comment": "Build succeeded",
|
|
Pierre-Yves Chibon |
6ffde7 |
"commit_hash": "62b49f00d489452994de5010565fab81",
|
|
Pierre-Yves Chibon |
6ffde7 |
"date_created": "1510742565",
|
|
Pierre-Yves Chibon |
6ffde7 |
"percent": None,
|
|
Pierre-Yves Chibon |
6ffde7 |
"status": "success",
|
|
Pierre-Yves Chibon |
6ffde7 |
"url": "https://koji.fp.o/koji...",
|
|
Pierre-Yves Chibon |
6ffde7 |
"user": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
6ffde7 |
"name": "foo"
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
"username": "complex-koji-ci"
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
],
|
|
Pierre-Yves Chibon |
6ffde7 |
"total_flags": 2
|
|
Karsten Hopp |
be01e8 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
class PagureFlaskApiProjectModifyAclTests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Tests for the flask API of pagure for modifying ACLs in a project
|
|
Pierre-Yves Chibon |
6ffde7 |
"""
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
maxDiff = None
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def setUp(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
6ffde7 |
super(PagureFlaskApiProjectModifyAclTests, self).setUp()
|
|
Karsten Hopp |
be01e8 |
tests.create_projects(self.session)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens(self.session, project_id=None)
|
|
Karsten Hopp |
be01e8 |
tests.create_tokens_acl(
|
|
Karsten Hopp |
be01e8 |
self.session, 'aaabbbcccddd', 'modify_project')
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
project = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEquals(
|
|
Pierre-Yves Chibon |
6ffde7 |
project.access_users,
|
|
Pierre-Yves Chibon |
6ffde7 |
{u'admin': [], u'commit': [], u'ticket': []}
|
|
Karsten Hopp |
be01e8 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_no_project(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when the project
|
|
Pierre-Yves Chibon |
6ffde7 |
doesn't exist """
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Karsten Hopp |
be01e8 |
|
|
Karsten Hopp |
be01e8 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'bar',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'commit'
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test12345123/git/modifyacls',
|
|
Karsten Hopp |
be01e8 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 404)
|
|
Karsten Hopp |
be01e8 |
data = json.loads(output.get_data(as_text=True))
|
|
Karsten Hopp |
be01e8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'ENOPROJECT',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'Project not found'
|
|
Karsten Hopp |
be01e8 |
}
|
|
Karsten Hopp |
be01e8 |
self.assertEqual(data, expected_output)
|
|
Karsten Hopp |
be01e8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_no_user(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when the user
|
|
Pierre-Yves Chibon |
6ffde7 |
doesn't exist """
|
|
mprahl |
7d811e |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
mprahl |
7d811e |
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'nosuchuser',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'commit'
|
|
mprahl |
7d811e |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
6ffde7 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
mprahl |
7d811e |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'No such user found',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': u'ENOUSER'
|
|
mprahl |
7d811e |
}
|
|
mprahl |
7d811e |
self.assertEqual(data, expected_output)
|
|
mprahl |
7d811e |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_no_group(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when the group
|
|
Pierre-Yves Chibon |
6ffde7 |
doesn't exist """
|
|
mprahl |
7d811e |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'group',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'nosuchgroup',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'commit'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
8715b5 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8715b5 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'Group not found',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'ENOGROUP'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_no_permission(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when the user
|
|
Pierre-Yves Chibon |
6ffde7 |
doesn't have permissions """
|
|
Pierre-Yves Chibon |
6ffde7 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
6ffde7 |
id='foo_token2',
|
|
Pierre-Yves Chibon |
6ffde7 |
user_id=2,
|
|
Pierre-Yves Chibon |
6ffde7 |
project_id=None,
|
|
Pierre-Yves Chibon |
6ffde7 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
6ffde7 |
+ datetime.timedelta(days=30)
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'foo_token2', 'modify_project')
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token foo_token2'}
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'foo',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'commit'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
8715b5 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8715b5 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'You are not allowed to modify this project',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'EMODIFYPROJECTNOTALLOWED'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_neither_user_nor_group(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when neither
|
|
Pierre-Yves Chibon |
6ffde7 |
user nor group was set """
|
|
Pierre-Yves Chibon |
8715b5 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'commit'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
8715b5 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8715b5 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'Invalid or incomplete input submitted',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'EINVALIDREQ',
|
|
Pierre-Yves Chibon |
6ffde7 |
'errors': {'name': ['This field is required.'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': ['Not a valid choice']}
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_invalid_acl(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when the ACL
|
|
Pierre-Yves Chibon |
6ffde7 |
doesn't exist. Must be one of ticket, commit or admin. """
|
|
Pierre-Yves Chibon |
8715b5 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'bar',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'invalidacl'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
8715b5 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8715b5 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'error': 'Invalid or incomplete input submitted',
|
|
Pierre-Yves Chibon |
6ffde7 |
'error_code': 'EINVALIDREQ',
|
|
Pierre-Yves Chibon |
6ffde7 |
'errors': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': ['Not a valid choice']
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_user(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api for
|
|
Pierre-Yves Chibon |
6ffde7 |
setting an ACL for a user. """
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'foo',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'commit'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
8715b5 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_modified'] = '1510742566'
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'access_groups': {'admin': [], 'commit': [], 'ticket': []},
|
|
Pierre-Yves Chibon |
6ffde7 |
'access_users': {'admin': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'commit': ['foo'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'ticket': []},
|
|
Pierre-Yves Chibon |
6ffde7 |
'close_status':
|
|
Pierre-Yves Chibon |
6ffde7 |
['Invalid', 'Insufficient data', 'Fixed', 'Duplicate'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_created': '1510742565',
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_modified': '1510742566',
|
|
Pierre-Yves Chibon |
6ffde7 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
6ffde7 |
'fullname': 'test',
|
|
Pierre-Yves Chibon |
6ffde7 |
'id': 1,
|
|
Pierre-Yves Chibon |
6ffde7 |
'milestones': {},
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'test',
|
|
Pierre-Yves Chibon |
6ffde7 |
'namespace': None,
|
|
Pierre-Yves Chibon |
6ffde7 |
'parent': None,
|
|
Pierre-Yves Chibon |
6ffde7 |
'priorities': {},
|
|
Pierre-Yves Chibon |
6ffde7 |
'tags': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'url_path': 'test',
|
|
Pierre-Yves Chibon |
6ffde7 |
'user': {'fullname': 'PY C', 'name': 'pingou'}
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_group(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api for
|
|
Pierre-Yves Chibon |
6ffde7 |
setting an ACL for a group. """
|
|
Pierre-Yves Chibon |
abcbf7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
abcbf7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Create a group
|
|
Pierre-Yves Chibon |
6ffde7 |
msg = pagure.lib.add_group(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session,
|
|
Pierre-Yves Chibon |
6ffde7 |
group_name='baz',
|
|
Pierre-Yves Chibon |
6ffde7 |
display_name='baz group',
|
|
Pierre-Yves Chibon |
6ffde7 |
description=None,
|
|
Pierre-Yves Chibon |
6ffde7 |
group_type='bar',
|
|
Pierre-Yves Chibon |
6ffde7 |
user='foo',
|
|
Pierre-Yves Chibon |
6ffde7 |
is_admin=False,
|
|
Pierre-Yves Chibon |
6ffde7 |
blacklist=[],
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(msg, 'User `foo` added to the group `baz`.')
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'group',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'baz',
|
|
Pierre-Yves Chibon |
6ffde7 |
'acl': 'ticket'
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls',
|
|
Pierre-Yves Chibon |
8715b5 |
headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_modified'] = '1510742566'
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'access_groups': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'admin': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'commit': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'ticket': ['baz']
|
|
Pierre-Yves Chibon |
8715b5 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
'access_users': {
|
|
Pierre-Yves Chibon |
6ffde7 |
'admin': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'commit': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'owner': ['pingou'],
|
|
Pierre-Yves Chibon |
6ffde7 |
'ticket': []
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
'close_status': [
|
|
Pierre-Yves Chibon |
6ffde7 |
'Invalid',
|
|
Pierre-Yves Chibon |
6ffde7 |
'Insufficient data',
|
|
Pierre-Yves Chibon |
6ffde7 |
'Fixed',
|
|
Pierre-Yves Chibon |
6ffde7 |
'Duplicate'
|
|
Pierre-Yves Chibon |
6ffde7 |
],
|
|
Pierre-Yves Chibon |
6ffde7 |
'custom_keys': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_created': '1510742565',
|
|
Pierre-Yves Chibon |
6ffde7 |
'date_modified': '1510742566',
|
|
Pierre-Yves Chibon |
6ffde7 |
'description': 'test project #1',
|
|
Pierre-Yves Chibon |
6ffde7 |
'fullname': 'test',
|
|
Pierre-Yves Chibon |
6ffde7 |
'id': 1,
|
|
Pierre-Yves Chibon |
6ffde7 |
'milestones': {},
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'test',
|
|
Pierre-Yves Chibon |
6ffde7 |
'namespace': None,
|
|
Pierre-Yves Chibon |
6ffde7 |
'parent': None,
|
|
Pierre-Yves Chibon |
6ffde7 |
'priorities': {},
|
|
Pierre-Yves Chibon |
6ffde7 |
'tags': [],
|
|
Pierre-Yves Chibon |
6ffde7 |
'url_path': 'test',
|
|
Pierre-Yves Chibon |
6ffde7 |
'user': {'fullname': 'PY C', 'name': 'pingou'}
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_no_acl(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when no ACL
|
|
Pierre-Yves Chibon |
6ffde7 |
are specified. """
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
project = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEquals(
|
|
Pierre-Yves Chibon |
6ffde7 |
project.access_users,
|
|
Pierre-Yves Chibon |
6ffde7 |
{u'admin': [], u'commit': [], u'ticket': []}
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'foo',
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls', headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
6ffde7 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
6ffde7 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
6ffde7 |
"errors": "User does not have any access on the repo"
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_remove_own_acl_no_access(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when no ACL
|
|
Pierre-Yves Chibon |
6ffde7 |
are specified, so the user tries to remove their own access but the
|
|
Pierre-Yves Chibon |
6ffde7 |
user is the project owner. """
|
|
Pierre-Yves Chibon |
8715b5 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'pingou',
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
8715b5 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls', headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8715b5 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
6ffde7 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
6ffde7 |
"errors": "User does not have any access on the repo"
|
|
Pierre-Yves Chibon |
8715b5 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_remove_own_acl_(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api when no ACL
|
|
Pierre-Yves Chibon |
6ffde7 |
are specified, so the user tries to remove their own access but the
|
|
Pierre-Yves Chibon |
6ffde7 |
user is the project owner. """
|
|
Karsten Hopp |
a5d5f1 |
# Add the user `foo` to the project
|
|
Pierre-Yves Chibon |
6ffde7 |
self.test_api_modify_acls_user()
|
|
Pierre-Yves Chibon |
6882b8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Ensure `foo` was properly added:
|
|
Pierre-Yves Chibon |
6ffde7 |
project = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
user_foo = pagure.lib.search_user(self.session, username='foo')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEquals(
|
|
Pierre-Yves Chibon |
6ffde7 |
project.access_users,
|
|
Pierre-Yves Chibon |
6ffde7 |
{u'admin': [], u'commit': [user_foo], u'ticket': []}
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6882b8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Create an API token for `foo` for the project `test`
|
|
Pierre-Yves Chibon |
6ffde7 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
6ffde7 |
id='foo_test_token',
|
|
Pierre-Yves Chibon |
6ffde7 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
6ffde7 |
project_id=1, # test
|
|
Pierre-Yves Chibon |
6ffde7 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(days=10)
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
6882b8 |
self.session.commit()
|
|
Pierre-Yves Chibon |
6ffde7 |
tests.create_tokens_acl(
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session, 'foo_test_token', 'modify_project')
|
|
Pierre-Yves Chibon |
6882b8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
headers = {'Authorization': 'token foo_test_token'}
|
|
Pierre-Yves Chibon |
6882b8 |
|
|
Pierre-Yves Chibon |
6882b8 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'foo',
|
|
Pierre-Yves Chibon |
6882b8 |
}
|
|
Pierre-Yves Chibon |
6882b8 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls', headers=headers, data=data)
|
|
Pierre-Yves Chibon |
6882b8 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_modified'] = '1510742566'
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6882b8 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"access_groups": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"admin": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"commit": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"ticket": []
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
"access_users": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"admin": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"commit": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"owner": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"pingou"
|
|
Pierre-Yves Chibon |
6ffde7 |
],
|
|
Pierre-Yves Chibon |
6ffde7 |
"ticket": []
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
"close_status": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"Invalid",
|
|
Pierre-Yves Chibon |
6ffde7 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
6ffde7 |
"Fixed",
|
|
Pierre-Yves Chibon |
6ffde7 |
"Duplicate"
|
|
Pierre-Yves Chibon |
6ffde7 |
],
|
|
Pierre-Yves Chibon |
6ffde7 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"date_created": "1510742565",
|
|
Pierre-Yves Chibon |
6ffde7 |
"date_modified": "1510742566",
|
|
Pierre-Yves Chibon |
6ffde7 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
6ffde7 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
6ffde7 |
"id": 1,
|
|
Pierre-Yves Chibon |
6ffde7 |
"milestones": {},
|
|
Pierre-Yves Chibon |
6ffde7 |
"name": "test",
|
|
Pierre-Yves Chibon |
6ffde7 |
"namespace": None,
|
|
Pierre-Yves Chibon |
6ffde7 |
"parent": None,
|
|
Pierre-Yves Chibon |
6ffde7 |
"priorities": {},
|
|
Pierre-Yves Chibon |
6ffde7 |
"tags": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
6ffde7 |
"user": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
6ffde7 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Pierre-Yves Chibon |
6882b8 |
}
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6882b8 |
self.assertEqual(data, expected_output)
|
|
Pierre-Yves Chibon |
6882b8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Ensure `foo` was properly removed
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session = pagure.lib.create_session(self.dbpath)
|
|
Pierre-Yves Chibon |
6ffde7 |
project = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEquals(
|
|
Pierre-Yves Chibon |
6ffde7 |
project.access_users,
|
|
Pierre-Yves Chibon |
6ffde7 |
{u'admin': [], u'commit': [], u'ticket': []}
|
|
Pierre-Yves Chibon |
6882b8 |
)
|
|
Pierre-Yves Chibon |
6882b8 |
|
|
Pierre-Yves Chibon |
6ffde7 |
def test_api_modify_acls_remove_someone_else_acl(self):
|
|
Pierre-Yves Chibon |
6ffde7 |
""" Test the api_modify_acls method of the flask api an admin tries
|
|
Pierre-Yves Chibon |
6ffde7 |
to remove access from someone else. """
|
|
Pierre-Yves Chibon |
6ffde7 |
# Add the user `foo` to the project
|
|
Pierre-Yves Chibon |
6ffde7 |
self.test_api_modify_acls_user()
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Ensure `foo` was properly added:
|
|
Pierre-Yves Chibon |
6ffde7 |
project = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
user_foo = pagure.lib.search_user(self.session, username='foo')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEquals(
|
|
Pierre-Yves Chibon |
6ffde7 |
project.access_users,
|
|
Pierre-Yves Chibon |
6ffde7 |
{u'admin': [], u'commit': [user_foo], u'ticket': []}
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Slavek Kabrda |
45252f |
|
|
Slavek Kabrda |
45252f |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
6ffde7 |
data = {
|
|
Pierre-Yves Chibon |
6ffde7 |
'user_type': 'user',
|
|
Pierre-Yves Chibon |
6ffde7 |
'name': 'foo',
|
|
Slavek Kabrda |
45252f |
}
|
|
Slavek Kabrda |
45252f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
6ffde7 |
'/api/0/test/git/modifyacls', headers=headers, data=data)
|
|
Slavek Kabrda |
3e4583 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_created'] = '1510742565'
|
|
Pierre-Yves Chibon |
6ffde7 |
data['date_modified'] = '1510742566'
|
|
Slavek Kabrda |
3e4583 |
|
|
Slavek Kabrda |
3e4583 |
expected_output = {
|
|
Pierre-Yves Chibon |
6ffde7 |
"access_groups": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"admin": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"commit": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"ticket": []
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
"access_users": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"admin": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"commit": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"owner": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"pingou"
|
|
Slavek Kabrda |
3e4583 |
],
|
|
Pierre-Yves Chibon |
6ffde7 |
"ticket": []
|
|
Pierre-Yves Chibon |
6ffde7 |
},
|
|
Pierre-Yves Chibon |
6ffde7 |
"close_status": [
|
|
Pierre-Yves Chibon |
6ffde7 |
"Invalid",
|
|
Pierre-Yves Chibon |
6ffde7 |
"Insufficient data",
|
|
Pierre-Yves Chibon |
6ffde7 |
"Fixed",
|
|
Pierre-Yves Chibon |
6ffde7 |
"Duplicate"
|
|
Pierre-Yves Chibon |
6ffde7 |
],
|
|
Pierre-Yves Chibon |
6ffde7 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"date_created": "1510742565",
|
|
Pierre-Yves Chibon |
6ffde7 |
"date_modified": "1510742566",
|
|
Pierre-Yves Chibon |
6ffde7 |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
6ffde7 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
6ffde7 |
"id": 1,
|
|
Pierre-Yves Chibon |
6ffde7 |
"milestones": {},
|
|
Pierre-Yves Chibon |
6ffde7 |
"name": "test",
|
|
Pierre-Yves Chibon |
6ffde7 |
"namespace": None,
|
|
Pierre-Yves Chibon |
6ffde7 |
"parent": None,
|
|
Pierre-Yves Chibon |
6ffde7 |
"priorities": {},
|
|
Pierre-Yves Chibon |
6ffde7 |
"tags": [],
|
|
Pierre-Yves Chibon |
6ffde7 |
"url_path": "test",
|
|
Pierre-Yves Chibon |
6ffde7 |
"user": {
|
|
Pierre-Yves Chibon |
6ffde7 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
6ffde7 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
6ffde7 |
}
|
|
Slavek Kabrda |
3e4583 |
}
|
|
Slavek Kabrda |
3e4583 |
|
|
Slavek Kabrda |
3e4583 |
self.assertEqual(data, expected_output)
|
|
Slavek Kabrda |
3e4583 |
|
|
Pierre-Yves Chibon |
6ffde7 |
# Ensure `foo` was properly removed
|
|
Pierre-Yves Chibon |
6ffde7 |
self.session = pagure.lib.create_session(self.dbpath)
|
|
Pierre-Yves Chibon |
6ffde7 |
project = pagure.lib._get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
6ffde7 |
self.assertEquals(
|
|
Pierre-Yves Chibon |
6ffde7 |
project.access_users,
|
|
Pierre-Yves Chibon |
6ffde7 |
{u'admin': [], u'commit': [], u'ticket': []}
|
|
Pierre-Yves Chibon |
6ffde7 |
)
|
|
Pierre-Yves Chibon |
6ffde7 |
|
|
Pierre-Yves Chibon |
8715b5 |
|
|
Pierre-Yves Chibon |
f15f18 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|