|
Pierre-Yves Chibon |
f15f18 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
"""
|
|
Pierre-Yves Chibon |
b63f28 |
(c) 2015-2017 - 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>
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
"""
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
f15f18 |
import pkg_resources
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
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 |
|
|
Pierre-Yves Chibon |
f15f18 |
import pygit2
|
|
Pierre-Yves Chibon |
f15f18 |
from mock import patch
|
|
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 |
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 |
|
|
Pierre-Yves Chibon |
f15f18 |
def setUp(self):
|
|
Pierre-Yves Chibon |
f15f18 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
f15f18 |
super(PagureFlaskApiProjecttests, self).setUp()
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
f15f18 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
f15f18 |
pagure.api.SESSION = self.session
|
|
Pierre-Yves Chibon |
f15f18 |
pagure.api.project.SESSION = self.session
|
|
Pierre-Yves Chibon |
f15f18 |
pagure.lib.SESSION = self.session
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Jeremy Cline |
20109f |
pagure.APP.config['GIT_FOLDER'] = os.path.join(self.path, 'repos')
|
|
Pierre-Yves Chibon |
1c1b5d |
pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'requests')
|
|
Pierre-Yves Chibon |
1c1b5d |
pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'tickets')
|
|
Pierre-Yves Chibon |
1c1b5d |
pagure.APP.config['DOCS_FOLDER'] = os.path.join(
|
|
Jeremy Cline |
20109f |
self.path, 'docs')
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
Pierre-Yves Chibon |
f15f18 |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
f15f18 |
|
|
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)
|
|
Pierre-Yves Chibon |
f15f18 |
data = json.loads(output.data)
|
|
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 |
62ffe0 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
62ffe0 |
|
|
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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.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(
|
|
Pierre-Yves Chibon |
ceb262 |
self.session, repo, 'infra', 'pingou',
|
|
Pierre-Yves Chibon |
a18547 |
None)
|
|
Pierre-Yves Chibon |
a18547 |
self.assertEqual(output, ['Issue tagged with: infra'])
|
|
Pierre-Yves Chibon |
ceb262 |
|
|
Pierre-Yves Chibon |
ceb262 |
# Check after adding
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.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')
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ceb262 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
ceb262 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
ceb262 |
data,
|
|
Pierre-Yves Chibon |
ceb262 |
{'error_code': 'ENOPROJECTS', 'error': 'No projects found'}
|
|
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)
|
|
Pierre-Yves Chibon |
ceb262 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
'args': {
|
|
Matt Prahl |
6bf79a |
'fork': None,
|
|
Matt Prahl |
6bf79a |
'pattern': None,
|
|
Matt Prahl |
6bf79a |
'tags': ['infra'],
|
|
Matt Prahl |
6bf79a |
'username': None
|
|
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 |
'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'
|
|
Pierre-Yves Chibon |
e33592 |
],
|
|
Matt Prahl |
6bf79a |
'custom_keys': [],
|
|
Matt Prahl |
6bf79a |
'date_created': '1436527638',
|
|
Matt Prahl |
6bf79a |
'description': 'test project #1',
|
|
Matt Prahl |
6bf79a |
'fullname': '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'
|
|
Pierre-Yves Chibon |
07a462 |
}
|
|
Matt Prahl |
6bf79a |
}],
|
|
Matt Prahl |
6bf79a |
'total_projects': 1
|
|
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')
|
|
Pierre-Yves Chibon |
7485e2 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7485e2 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][1]['date_created'] = "1436527638"
|
|
clime |
afed57 |
data['projects'][2]['date_created'] = "1436527638"
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
"args": {
|
|
Pierre-Yves Chibon |
e33592 |
"fork": None,
|
|
Pierre-Yves Chibon |
e33592 |
"pattern": None,
|
|
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",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "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",
|
|
Matt Prahl |
6bf79a |
"description": "test project #2",
|
|
Matt Prahl |
6bf79a |
"fullname": "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",
|
|
Matt Prahl |
6bf79a |
"description": "namespaced test project",
|
|
Matt Prahl |
6bf79a |
"fullname": "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)
|
|
Pierre-Yves Chibon |
7485e2 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
07a462 |
data['projects'][0]['date_created'] = "1436527638"
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
"args": {
|
|
Pierre-Yves Chibon |
e33592 |
"fork": None,
|
|
Pierre-Yves Chibon |
e33592 |
"pattern": None,
|
|
Matt Prahl |
6bf79a |
"tags": ["infra"],
|
|
Pierre-Yves Chibon |
e33592 |
"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",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "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 |
|
|
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 |
b42ba1 |
repo = pagure.lib.get_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(
|
|
Pierre-Yves Chibon |
b42ba1 |
self.session, repo, 'infra', 'pingou',
|
|
Pierre-Yves Chibon |
a18547 |
ticketfolder=None)
|
|
Pierre-Yves Chibon |
a18547 |
self.assertEqual(output, ['Issue tagged with: infra'])
|
|
Pierre-Yves Chibon |
b42ba1 |
|
|
Pierre-Yves Chibon |
b42ba1 |
# Check after adding
|
|
Pierre-Yves Chibon |
b42ba1 |
repo = pagure.lib.get_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)
|
|
Pierre-Yves Chibon |
b42ba1 |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
b42ba1 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
b42ba1 |
data['date_created'] = "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"],
|
|
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",
|
|
Matt Prahl |
6bf79a |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "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 |
|
|
Pierre-Yves Chibon |
1c1b5d |
@patch('pagure.lib.git.generate_gitolite_acls')
|
|
Pierre-Yves Chibon |
1c1b5d |
def test_api_new_project(self, p_gga):
|
|
Pierre-Yves Chibon |
1c1b5d |
""" Test the api_new_project method of the flask api. """
|
|
Pierre-Yves Chibon |
1c1b5d |
p_gga.return_value = True
|
|
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)
|
|
Pierre-Yves Chibon |
1c1b5d |
data = json.loads(output.data)
|
|
Jeremy Cline |
099538 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Jeremy Cline |
099538 |
data['error_code'])
|
|
Jeremy Cline |
099538 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
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)
|
|
Pierre-Yves Chibon |
1c1b5d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{
|
|
Pierre-Yves Chibon |
1c1b5d |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
1c1b5d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{
|
|
Pierre-Yves Chibon |
1c1b5d |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
1c1b5d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1c1b5d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c1b5d |
data,
|
|
Pierre-Yves Chibon |
1c1b5d |
{
|
|
Pierre-Yves Chibon |
b63f28 |
"error": "The project repo \"test\" already exists "
|
|
Pierre-Yves Chibon |
b63f28 |
"in the database",
|
|
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)
|
|
Pierre-Yves Chibon |
1c1b5d |
data = json.loads(output.data)
|
|
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 |
f0e08e |
@patch('pagure.lib.git.generate_gitolite_acls')
|
|
Pierre-Yves Chibon |
1dfd94 |
def test_api_new_project_user_token(self, p_gga):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_new_project method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
p_gga.return_value = True
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Pierre-Yves Chibon |
1dfd94 |
data['error_code'])
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "The project repo \"test\" already exists "
|
|
Pierre-Yves Chibon |
1dfd94 |
"in the database",
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
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 |
2aa56f |
pagure.APP.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)
|
|
Pierre-Yves Chibon |
2aa56f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
2aa56f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
2aa56f |
data,
|
|
Pierre-Yves Chibon |
2aa56f |
{
|
|
Pierre-Yves Chibon |
2aa56f |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
2aa56f |
data = json.loads(output.data)
|
|
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 |
|
|
Pierre-Yves Chibon |
1dfd94 |
@patch('pagure.lib.git.generate_gitolite_acls')
|
|
Pierre-Yves Chibon |
baec09 |
def test_api_new_project_user_ns(self, p_gga):
|
|
Pierre-Yves Chibon |
baec09 |
""" Test the api_new_project method of the flask api. """
|
|
Pierre-Yves Chibon |
baec09 |
pagure.APP.config['USER_NAMESPACE'] = True
|
|
Pierre-Yves Chibon |
baec09 |
p_gga.return_value = True
|
|
Pierre-Yves Chibon |
baec09 |
|
|
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)
|
|
Pierre-Yves Chibon |
baec09 |
data = json.loads(output.data)
|
|
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 |
pagure.APP.config['ALLOWED_PREFIX'] = ['testns']
|
|
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
|
|
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)
|
|
Pierre-Yves Chibon |
baec09 |
data = json.loads(output.data)
|
|
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 |
|
|
Pierre-Yves Chibon |
baec09 |
pagure.APP.config['USER_NAMESPACE'] = False
|
|
Pierre-Yves Chibon |
baec09 |
|
|
Pierre-Yves Chibon |
baec09 |
@patch('pagure.lib.git.generate_gitolite_acls')
|
|
Pierre-Yves Chibon |
f0e08e |
def test_api_fork_project(self, p_gga):
|
|
Pierre-Yves Chibon |
f0e08e |
""" Test the api_fork_project method of the flask api. """
|
|
Pierre-Yves Chibon |
f0e08e |
p_gga.return_value = True
|
|
Pierre-Yves Chibon |
f0e08e |
|
|
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)
|
|
Pierre-Yves Chibon |
f0e08e |
data = json.loads(output.data)
|
|
Jeremy Cline |
099538 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Jeremy Cline |
099538 |
data['error_code'])
|
|
Jeremy Cline |
099538 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
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 |
|
|
Pierre-Yves Chibon |
1dfd94 |
@patch('pagure.lib.git.generate_gitolite_acls')
|
|
Pierre-Yves Chibon |
1dfd94 |
def test_api_fork_project_user_token(self, p_gga):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_fork_project method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
p_gga.return_value = True
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
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)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Pierre-Yves Chibon |
1dfd94 |
data['error_code'])
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
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)
|
|
Pierre-Yves Chibon |
f0e08e |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
Pierre-Yves Chibon |
f0e08e |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
f0e08e |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f0e08e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f0e08e |
data,
|
|
Pierre-Yves Chibon |
f0e08e |
{
|
|
Pierre-Yves Chibon |
f0e08e |
"error": "Invalid or incomplete input submited",
|
|
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)
|
|
Pierre-Yves Chibon |
f0e08e |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
f0e08e |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
f0e08e |
data = json.loads(output.data)
|
|
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)
|
|
Pierre-Yves Chibon |
2c43bb |
data = json.loads(output.data)
|
|
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 |
|
|
Pierre-Yves Chibon |
f15f18 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
f15f18 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
f15f18 |
PagureFlaskApiProjecttests)
|
|
Pierre-Yves Chibon |
f15f18 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|