|
Pierre-Yves Chibon |
c71c2d |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
"""
|
|
Pierre-Yves Chibon |
c71c2d |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
Authors:
|
|
Pierre-Yves Chibon |
c71c2d |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
"""
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
c71c2d |
import pkg_resources
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
import datetime
|
|
Pierre-Yves Chibon |
c71c2d |
import unittest
|
|
Pierre-Yves Chibon |
c71c2d |
import shutil
|
|
Pierre-Yves Chibon |
c71c2d |
import sys
|
|
Pierre-Yves Chibon |
c71c2d |
import os
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
import json
|
|
Pierre-Yves Chibon |
c71c2d |
from mock import patch
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
c71c2d |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Farhaan Bukhsh |
72e9db |
import pagure
|
|
Pierre-Yves Chibon |
c71c2d |
import pagure.lib
|
|
Pierre-Yves Chibon |
c71c2d |
import tests
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
class PagureFlaskApiForktests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
c71c2d |
""" Tests for the flask API of pagure for issue """
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
def setUp(self):
|
|
Pierre-Yves Chibon |
c71c2d |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
c71c2d |
super(PagureFlaskApiForktests, self).setUp()
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
c71c2d |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
c71c2d |
pagure.api.SESSION = self.session
|
|
Pierre-Yves Chibon |
c71c2d |
pagure.api.fork.SESSION = self.session
|
|
Pierre-Yves Chibon |
c71c2d |
pagure.lib.SESSION = self.session
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
pagure.APP.config['REQUESTS_FOLDER'] = None
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
7cc2d4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
7cc2d4 |
def test_api_pull_request_views(self, send_email):
|
|
Pierre-Yves Chibon |
ad85b9 |
""" Test the api_pull_request_views method of the flask api. """
|
|
Pierre-Yves Chibon |
7cc2d4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
7cc2d4 |
|
|
Pierre-Yves Chibon |
ad85b9 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
ad85b9 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
ad85b9 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
ad85b9 |
|
|
Pierre-Yves Chibon |
ad85b9 |
# Create a pull-request
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
72e9db |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
ad85b9 |
session=self.session,
|
|
Pierre-Yves Chibon |
ad85b9 |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
ad85b9 |
branch_from='master',
|
|
Pierre-Yves Chibon |
ad85b9 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
ad85b9 |
branch_to='master',
|
|
Pierre-Yves Chibon |
ad85b9 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
ad85b9 |
user='pingou',
|
|
Pierre-Yves Chibon |
ad85b9 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
ad85b9 |
)
|
|
Pierre-Yves Chibon |
ad85b9 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
ad85b9 |
|
|
Pierre-Yves Chibon |
ad85b9 |
# Invalid repo
|
|
Pierre-Yves Chibon |
ad85b9 |
output = self.app.get('/api/0/foo/pull-requests')
|
|
Pierre-Yves Chibon |
ad85b9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
ad85b9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
ad85b9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
ad85b9 |
data,
|
|
Pierre-Yves Chibon |
ad85b9 |
{
|
|
Pierre-Yves Chibon |
ad85b9 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
ad85b9 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
ad85b9 |
}
|
|
Pierre-Yves Chibon |
ad85b9 |
)
|
|
Pierre-Yves Chibon |
ad85b9 |
|
|
Pierre-Yves Chibon |
ad85b9 |
# List pull-requests
|
|
Pierre-Yves Chibon |
ad85b9 |
output = self.app.get('/api/0/test/pull-requests')
|
|
Pierre-Yves Chibon |
ad85b9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ad85b9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
ad85b9 |
data['requests'][0]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
44258a |
data['requests'][0]['updated_on'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
data['requests'][0]['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['requests'][0]['project']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
data['requests'][0]['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['requests'][0]['repo_from']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
data['requests'][0]['uid'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['requests'][0]['last_updated'] = '1431414800'
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
"args": {
|
|
Pierre-Yves Chibon |
316f15 |
"assignee": None,
|
|
Pierre-Yves Chibon |
316f15 |
"author": None,
|
|
Pierre-Yves Chibon |
316f15 |
"status": True
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"requests": [{
|
|
Matt Prahl |
6bf79a |
"assignee": None,
|
|
Matt Prahl |
6bf79a |
"branch": "master",
|
|
Matt Prahl |
6bf79a |
"branch_from": "master",
|
|
Matt Prahl |
6bf79a |
"closed_at": None,
|
|
Matt Prahl |
6bf79a |
"closed_by": None,
|
|
Matt Prahl |
6bf79a |
"comments": [],
|
|
Matt Prahl |
6bf79a |
"commit_start": None,
|
|
Matt Prahl |
6bf79a |
"commit_stop": None,
|
|
Matt Prahl |
6bf79a |
"date_created": "1431414800",
|
|
Matt Prahl |
6bf79a |
"id": 1,
|
|
Matt Prahl |
6bf79a |
"initial_comment": None,
|
|
Matt Prahl |
6bf79a |
"last_updated": "1431414800",
|
|
Matt Prahl |
6bf79a |
"project": {
|
|
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 |
},
|
|
Pierre-Yves Chibon |
f254bf |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"
|
|
Pierre-Yves Chibon |
f254bf |
],
|
|
Pierre-Yves Chibon |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ad85b9 |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Pierre-Yves Chibon |
ad85b9 |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ad85b9 |
"id": 1,
|
|
Pierre-Yves Chibon |
f254bf |
"milestones": {},
|
|
Pierre-Yves Chibon |
ad85b9 |
"name": "test",
|
|
Pierre-Yves Chibon |
733a9d |
"namespace": None,
|
|
Pierre-Yves Chibon |
ad85b9 |
"parent": None,
|
|
Pierre-Yves Chibon |
14bde2 |
"priorities": {},
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
Pierre-Yves Chibon |
ad85b9 |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Pierre-Yves Chibon |
ad85b9 |
}
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"remote_git": None,
|
|
Matt Prahl |
6bf79a |
"repo_from": {
|
|
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 |
},
|
|
Pierre-Yves Chibon |
f254bf |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"
|
|
Pierre-Yves Chibon |
f254bf |
],
|
|
Pierre-Yves Chibon |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
ad85b9 |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Pierre-Yves Chibon |
ad85b9 |
"description": "test project #1",
|
|
Matt Prahl |
6bf79a |
"fullname": "test",
|
|
Pierre-Yves Chibon |
ad85b9 |
"id": 1,
|
|
Pierre-Yves Chibon |
f254bf |
"milestones": {},
|
|
Pierre-Yves Chibon |
ad85b9 |
"name": "test",
|
|
Pierre-Yves Chibon |
733a9d |
"namespace": None,
|
|
Pierre-Yves Chibon |
ad85b9 |
"parent": None,
|
|
Pierre-Yves Chibon |
14bde2 |
"priorities": {},
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
Pierre-Yves Chibon |
ad85b9 |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Pierre-Yves Chibon |
ad85b9 |
}
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"status": "Open",
|
|
Matt Prahl |
6bf79a |
"title": "test pull-request",
|
|
Matt Prahl |
6bf79a |
"uid": "1431414800",
|
|
Matt Prahl |
6bf79a |
"updated_on": "1431414800",
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Pierre-Yves Chibon |
ad85b9 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
ad85b9 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
ad85b9 |
}
|
|
Matt Prahl |
6bf79a |
}],
|
|
Matt Prahl |
6bf79a |
"total_requests": 1
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
ad85b9 |
|
|
Pierre-Yves Chibon |
ad85b9 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
ad85b9 |
|
|
Pierre-Yves Chibon |
ad85b9 |
# Access Pull-Request authenticated
|
|
Pierre-Yves Chibon |
ad85b9 |
output = self.app.get('/api/0/test/pull-requests', headers=headers)
|
|
Pierre-Yves Chibon |
ad85b9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ad85b9 |
data2 = json.loads(output.data)
|
|
Pierre-Yves Chibon |
ad85b9 |
data2['requests'][0]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
44258a |
data2['requests'][0]['updated_on'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
data2['requests'][0]['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['requests'][0]['project']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
data2['requests'][0]['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['requests'][0]['repo_from']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
data2['requests'][0]['uid'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data2['requests'][0]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
ad85b9 |
self.assertDictEqual(data, data2)
|
|
Pierre-Yves Chibon |
ad85b9 |
|
|
Pierre-Yves Chibon |
7cc2d4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
7cc2d4 |
def test_api_pull_request_view(self, send_email):
|
|
Pierre-Yves Chibon |
c71c2d |
""" Test the api_pull_request_view method of the flask api. """
|
|
Pierre-Yves Chibon |
7cc2d4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
c71c2d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
c71c2d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
c71c2d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
# Create a pull-request
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
72e9db |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
c71c2d |
session=self.session,
|
|
Pierre-Yves Chibon |
c71c2d |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
c71c2d |
branch_from='master',
|
|
Pierre-Yves Chibon |
c71c2d |
repo_to=repo,
|
|
Pierre-Yves Chibon |
c71c2d |
branch_to='master',
|
|
Pierre-Yves Chibon |
c71c2d |
title='test pull-request',
|
|
Pierre-Yves Chibon |
c71c2d |
user='pingou',
|
|
Pierre-Yves Chibon |
c71c2d |
requestfolder=None,
|
|
Pierre-Yves Chibon |
c71c2d |
)
|
|
Pierre-Yves Chibon |
c71c2d |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
# Invalid repo
|
|
Pierre-Yves Chibon |
c71c2d |
output = self.app.get('/api/0/foo/pull-request/1')
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
c71c2d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
c71c2d |
data,
|
|
Pierre-Yves Chibon |
c71c2d |
{
|
|
Pierre-Yves Chibon |
c71c2d |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
c71c2d |
}
|
|
Pierre-Yves Chibon |
c71c2d |
)
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
# Invalid issue for this repo
|
|
Pierre-Yves Chibon |
c71c2d |
output = self.app.get('/api/0/test2/pull-request/1')
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
c71c2d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
c71c2d |
data,
|
|
Pierre-Yves Chibon |
c71c2d |
{
|
|
Pierre-Yves Chibon |
c71c2d |
"error": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
c71c2d |
}
|
|
Pierre-Yves Chibon |
c71c2d |
)
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
# Valid issue
|
|
Pierre-Yves Chibon |
c71c2d |
output = self.app.get('/api/0/test/pull-request/1')
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c71c2d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
c71c2d |
data['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
44258a |
data['updated_on'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['project']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data['repo_from']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data['uid'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['last_updated'] = '1431414800'
|
|
Matt Prahl |
6bf79a |
expected_data = {
|
|
Matt Prahl |
6bf79a |
"assignee": None,
|
|
Matt Prahl |
6bf79a |
"branch": "master",
|
|
Matt Prahl |
6bf79a |
"branch_from": "master",
|
|
Matt Prahl |
6bf79a |
"closed_at": None,
|
|
Matt Prahl |
6bf79a |
"closed_by": None,
|
|
Matt Prahl |
6bf79a |
"comments": [],
|
|
Matt Prahl |
6bf79a |
"commit_start": None,
|
|
Matt Prahl |
6bf79a |
"commit_stop": None,
|
|
Matt Prahl |
6bf79a |
"date_created": "1431414800",
|
|
Matt Prahl |
6bf79a |
"id": 1,
|
|
Matt Prahl |
6bf79a |
"initial_comment": None,
|
|
Matt Prahl |
6bf79a |
"last_updated": "1431414800",
|
|
Matt Prahl |
6bf79a |
"project": {
|
|
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 |
},
|
|
Pierre-Yves Chibon |
f254bf |
"close_status": [
|
|
Matt Prahl |
6bf79a |
"Invalid",
|
|
Matt Prahl |
6bf79a |
"Insufficient data",
|
|
Matt Prahl |
6bf79a |
"Fixed",
|
|
Matt Prahl |
6bf79a |
"Duplicate"
|
|
Pierre-Yves Chibon |
f254bf |
],
|
|
Pierre-Yves Chibon |
022564 |
"custom_keys": [],
|
|
Pierre-Yves Chibon |
c71c2d |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
Pierre-Yves Chibon |
c71c2d |
"description": "test project #1",
|
|
Pierre-Yves Chibon |
c9e619 |
"fullname": "test",
|
|
Pierre-Yves Chibon |
c71c2d |
"id": 1,
|
|
Pierre-Yves Chibon |
f254bf |
"milestones": {},
|
|
Pierre-Yves Chibon |
c71c2d |
"name": "test",
|
|
Pierre-Yves Chibon |
733a9d |
"namespace": None,
|
|
Pierre-Yves Chibon |
c71c2d |
"parent": None,
|
|
Pierre-Yves Chibon |
14bde2 |
"priorities": {},
|
|
Pierre-Yves Chibon |
a30916 |
"tags": [],
|
|
Pierre-Yves Chibon |
c71c2d |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Pierre-Yves Chibon |
c71c2d |
}
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"remote_git": None,
|
|
Matt Prahl |
6bf79a |
"repo_from": {
|
|
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"],
|
|
Matt Prahl |
6bf79a |
"custom_keys": [],
|
|
Matt Prahl |
6bf79a |
"date_created": "1431414800",
|
|
Clement Verna |
cd6e30 |
"date_modified": "1431414800",
|
|
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": [],
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Matt Prahl |
6bf79a |
"fullname": "PY C",
|
|
Matt Prahl |
6bf79a |
"name": "pingou"
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
},
|
|
Matt Prahl |
6bf79a |
"status": "Open",
|
|
Matt Prahl |
6bf79a |
"title": "test pull-request",
|
|
Matt Prahl |
6bf79a |
"uid": "1431414800",
|
|
Matt Prahl |
6bf79a |
"updated_on": "1431414800",
|
|
Matt Prahl |
6bf79a |
"user": {
|
|
Pierre-Yves Chibon |
c71c2d |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
c71c2d |
"name": "pingou"
|
|
Pierre-Yves Chibon |
c71c2d |
}
|
|
Matt Prahl |
6bf79a |
}
|
|
Matt Prahl |
6bf79a |
self.assertDictEqual(data, expected_data)
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
# Access Pull-Request authenticated
|
|
Pierre-Yves Chibon |
c71c2d |
output = self.app.get('/api/0/test/pull-request/1', headers=headers)
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
c71c2d |
data2 = json.loads(output.data)
|
|
Pierre-Yves Chibon |
c71c2d |
data2['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data2['project']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['project']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data2['repo_from']['date_created'] = '1431414800'
|
|
Clement Verna |
cd6e30 |
data2['repo_from']['date_modified'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data2['uid'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
data2['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
44258a |
data2['updated_on'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data2['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
c71c2d |
self.assertDictEqual(data, data2)
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
7cc2d4 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
7cc2d4 |
def test_api_pull_request_close(self, send_email):
|
|
Pierre-Yves Chibon |
209c7e |
""" Test the api_pull_request_close method of the flask api. """
|
|
Pierre-Yves Chibon |
7cc2d4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
7cc2d4 |
|
|
Pierre-Yves Chibon |
209c7e |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
209c7e |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
209c7e |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
209c7e |
|
|
Pierre-Yves Chibon |
209c7e |
# Create the pull-request to close
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
72e9db |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
209c7e |
session=self.session,
|
|
Pierre-Yves Chibon |
209c7e |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
209c7e |
branch_from='master',
|
|
Pierre-Yves Chibon |
209c7e |
repo_to=repo,
|
|
Pierre-Yves Chibon |
209c7e |
branch_to='master',
|
|
Pierre-Yves Chibon |
209c7e |
title='test pull-request',
|
|
Pierre-Yves Chibon |
209c7e |
user='pingou',
|
|
Pierre-Yves Chibon |
209c7e |
requestfolder=None,
|
|
Pierre-Yves Chibon |
209c7e |
)
|
|
Pierre-Yves Chibon |
209c7e |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
209c7e |
|
|
Pierre-Yves Chibon |
209c7e |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
209c7e |
|
|
Pierre-Yves Chibon |
209c7e |
# Invalid project
|
|
Pierre-Yves Chibon |
209c7e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
209c7e |
'/api/0/foo/pull-request/1/close', headers=headers)
|
|
Pierre-Yves Chibon |
209c7e |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
209c7e |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
209c7e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
209c7e |
data,
|
|
Pierre-Yves Chibon |
209c7e |
{
|
|
Pierre-Yves Chibon |
209c7e |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
209c7e |
}
|
|
Pierre-Yves Chibon |
209c7e |
)
|
|
Pierre-Yves Chibon |
209c7e |
|
|
Pierre-Yves Chibon |
209c7e |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
209c7e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
209c7e |
'/api/0/test2/pull-request/1/close', headers=headers)
|
|
Pierre-Yves Chibon |
209c7e |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
209c7e |
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 |
209c7e |
|
|
Pierre-Yves Chibon |
f12b4a |
# Invalid PR
|
|
Pierre-Yves Chibon |
f12b4a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f12b4a |
'/api/0/test/pull-request/2/close', headers=headers)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
f12b4a |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f12b4a |
data,
|
|
Pierre-Yves Chibon |
d661a4 |
{'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
# Create a token for foo for this project
|
|
Pierre-Yves Chibon |
f12b4a |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
f12b4a |
id='foobar_token',
|
|
Pierre-Yves Chibon |
f12b4a |
user_id=2,
|
|
Pierre-Yves Chibon |
f12b4a |
project_id=1,
|
|
Pierre-Yves Chibon |
f12b4a |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
f12b4a |
days=30)
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.commit()
|
|
Pierre-Yves Chibon |
c02e60 |
|
|
Pierre-Yves Chibon |
c02e60 |
# Allow the token to close PR
|
|
Pierre-Yves Chibon |
b11d54 |
acls = pagure.lib.get_acls(self.session)
|
|
Pierre-Yves Chibon |
b11d54 |
for acl in acls:
|
|
Pierre-Yves Chibon |
b11d54 |
if acl.name == 'pull_request_close':
|
|
Pierre-Yves Chibon |
b11d54 |
break
|
|
Pierre-Yves Chibon |
f12b4a |
item = pagure.lib.model.TokenAcl(
|
|
Pierre-Yves Chibon |
f12b4a |
token_id='foobar_token',
|
|
Pierre-Yves Chibon |
b11d54 |
acl_id=acl.id,
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.commit()
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
headers = {'Authorization': 'token foobar_token'}
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
# User not admin
|
|
Pierre-Yves Chibon |
f12b4a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f12b4a |
'/api/0/test/pull-request/1/close', headers=headers)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
f12b4a |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f12b4a |
data,
|
|
Pierre-Yves Chibon |
f12b4a |
{
|
|
Pierre-Yves Chibon |
f12b4a |
'error': 'You are not allowed to merge/close pull-request '
|
|
Pierre-Yves Chibon |
f12b4a |
'for this project',
|
|
Pierre-Yves Chibon |
d661a4 |
'error_code': "ENOPRCLOSE",
|
|
Pierre-Yves Chibon |
f12b4a |
}
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
209c7e |
# Close PR
|
|
Pierre-Yves Chibon |
209c7e |
output = self.app.post(
|
|
Pierre-Yves Chibon |
209c7e |
'/api/0/test/pull-request/1/close', headers=headers)
|
|
Pierre-Yves Chibon |
209c7e |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
209c7e |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
209c7e |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
209c7e |
data,
|
|
Pierre-Yves Chibon |
316f15 |
{"message": "Pull-request closed!"}
|
|
Pierre-Yves Chibon |
209c7e |
)
|
|
Pierre-Yves Chibon |
209c7e |
|
|
Pierre-Yves Chibon |
7cc2d4 |
@patch('pagure.lib.notify.send_email')
|
|
Patrick Uiterwijk |
02a7cc |
def test_api_pull_request_merge(self, send_email):
|
|
Pierre-Yves Chibon |
a9c964 |
""" Test the api_pull_request_merge method of the flask api. """
|
|
Pierre-Yves Chibon |
7cc2d4 |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
a9c964 |
|
|
Pierre-Yves Chibon |
a9c964 |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
02a7cc |
tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
|
Patrick Uiterwijk |
02a7cc |
tests.create_projects_git(os.path.join(self.path, 'requests'),
|
|
Patrick Uiterwijk |
02a7cc |
bare=True)
|
|
Patrick Uiterwijk |
02a7cc |
tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
|
|
Patrick Uiterwijk |
02a7cc |
tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
|
|
Patrick Uiterwijk |
02a7cc |
branch='test')
|
|
Pierre-Yves Chibon |
a9c964 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
a9c964 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
a9c964 |
|
|
Pierre-Yves Chibon |
a9c964 |
# Create the pull-request to close
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
72e9db |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
a9c964 |
session=self.session,
|
|
Pierre-Yves Chibon |
a9c964 |
repo_from=forked_repo,
|
|
Patrick Uiterwijk |
02a7cc |
branch_from='test',
|
|
Pierre-Yves Chibon |
a9c964 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
a9c964 |
branch_to='master',
|
|
Pierre-Yves Chibon |
a9c964 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
a9c964 |
user='pingou',
|
|
Pierre-Yves Chibon |
a9c964 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
a9c964 |
)
|
|
Pierre-Yves Chibon |
a9c964 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
a9c964 |
|
|
Pierre-Yves Chibon |
a9c964 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
a9c964 |
|
|
Pierre-Yves Chibon |
a9c964 |
# Invalid project
|
|
Pierre-Yves Chibon |
a9c964 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a9c964 |
'/api/0/foo/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
a9c964 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
a9c964 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
a9c964 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
a9c964 |
data,
|
|
Pierre-Yves Chibon |
a9c964 |
{
|
|
Pierre-Yves Chibon |
a9c964 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
a9c964 |
}
|
|
Pierre-Yves Chibon |
a9c964 |
)
|
|
Pierre-Yves Chibon |
a9c964 |
|
|
Pierre-Yves Chibon |
a9c964 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
a9c964 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a9c964 |
'/api/0/test2/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
a9c964 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
a9c964 |
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 |
a9c964 |
|
|
Pierre-Yves Chibon |
f12b4a |
# Invalid PR
|
|
Pierre-Yves Chibon |
f12b4a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f12b4a |
'/api/0/test/pull-request/2/merge', headers=headers)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
f12b4a |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f12b4a |
data,
|
|
Pierre-Yves Chibon |
d661a4 |
{'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
# Create a token for foo for this project
|
|
Pierre-Yves Chibon |
f12b4a |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
f12b4a |
id='foobar_token',
|
|
Pierre-Yves Chibon |
f12b4a |
user_id=2,
|
|
Pierre-Yves Chibon |
f12b4a |
project_id=1,
|
|
Pierre-Yves Chibon |
f12b4a |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
f12b4a |
days=30)
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.commit()
|
|
Pierre-Yves Chibon |
c02e60 |
|
|
Pierre-Yves Chibon |
c02e60 |
# Allow the token to merge PR
|
|
Pierre-Yves Chibon |
b11d54 |
acls = pagure.lib.get_acls(self.session)
|
|
Pierre-Yves Chibon |
b11d54 |
for acl in acls:
|
|
Pierre-Yves Chibon |
b11d54 |
if acl.name == 'pull_request_merge':
|
|
Pierre-Yves Chibon |
b11d54 |
break
|
|
Pierre-Yves Chibon |
f12b4a |
item = pagure.lib.model.TokenAcl(
|
|
Pierre-Yves Chibon |
f12b4a |
token_id='foobar_token',
|
|
Pierre-Yves Chibon |
b11d54 |
acl_id=acl.id,
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.add(item)
|
|
Pierre-Yves Chibon |
dea6ca |
self.session.commit()
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
headers = {'Authorization': 'token foobar_token'}
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# User not admin
|
|
Pierre-Yves Chibon |
dea6ca |
output = self.app.post(
|
|
Pierre-Yves Chibon |
dea6ca |
'/api/0/test/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
dea6ca |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
dea6ca |
data,
|
|
Pierre-Yves Chibon |
dea6ca |
{
|
|
Pierre-Yves Chibon |
dea6ca |
'error': 'You are not allowed to merge/close pull-request '
|
|
Pierre-Yves Chibon |
dea6ca |
'for this project',
|
|
Pierre-Yves Chibon |
dea6ca |
'error_code': "ENOPRCLOSE",
|
|
Pierre-Yves Chibon |
dea6ca |
}
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Merge PR
|
|
Pierre-Yves Chibon |
dea6ca |
output = self.app.post(
|
|
Pierre-Yves Chibon |
dea6ca |
'/api/0/test/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
dea6ca |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
dea6ca |
data,
|
|
Pierre-Yves Chibon |
dea6ca |
{"message": "Changes merged!"}
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
@patch('pagure.lib.notify.send_email')
|
|
Patrick Uiterwijk |
02a7cc |
def test_api_pull_request_merge_user_token(self, send_email):
|
|
Pierre-Yves Chibon |
dea6ca |
""" Test the api_pull_request_merge method of the flask api. """
|
|
Pierre-Yves Chibon |
dea6ca |
send_email.return_value = True
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
tests.create_projects(self.session)
|
|
Patrick Uiterwijk |
02a7cc |
tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
|
|
Patrick Uiterwijk |
02a7cc |
tests.create_projects_git(os.path.join(self.path, 'requests'),
|
|
Patrick Uiterwijk |
02a7cc |
bare=True)
|
|
Patrick Uiterwijk |
02a7cc |
tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
|
|
Patrick Uiterwijk |
02a7cc |
tests.add_commit_git_repo(os.path.join(self.path, 'repos', 'test.git'),
|
|
Patrick Uiterwijk |
02a7cc |
branch='test')
|
|
Pierre-Yves Chibon |
dea6ca |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
dea6ca |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Create the pull-request to close
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
e498a1 |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
dea6ca |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
dea6ca |
session=self.session,
|
|
Pierre-Yves Chibon |
dea6ca |
repo_from=forked_repo,
|
|
Patrick Uiterwijk |
02a7cc |
branch_from='test',
|
|
Pierre-Yves Chibon |
dea6ca |
repo_to=repo,
|
|
Pierre-Yves Chibon |
dea6ca |
branch_to='master',
|
|
Pierre-Yves Chibon |
dea6ca |
title='test pull-request',
|
|
Pierre-Yves Chibon |
dea6ca |
user='pingou',
|
|
Pierre-Yves Chibon |
dea6ca |
requestfolder=None,
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
self.session.commit()
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Invalid project
|
|
Pierre-Yves Chibon |
dea6ca |
output = self.app.post(
|
|
Pierre-Yves Chibon |
dea6ca |
'/api/0/foo/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
dea6ca |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
dea6ca |
data,
|
|
Pierre-Yves Chibon |
dea6ca |
{
|
|
Pierre-Yves Chibon |
dea6ca |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
dea6ca |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
dea6ca |
}
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Valid token, invalid PR
|
|
Pierre-Yves Chibon |
dea6ca |
output = self.app.post(
|
|
Pierre-Yves Chibon |
dea6ca |
'/api/0/test2/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
dea6ca |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
dea6ca |
data,
|
|
Pierre-Yves Chibon |
dea6ca |
{'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Valid token, invalid PR - other project
|
|
Pierre-Yves Chibon |
dea6ca |
output = self.app.post(
|
|
Pierre-Yves Chibon |
dea6ca |
'/api/0/test/pull-request/2/merge', headers=headers)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
dea6ca |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
dea6ca |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
dea6ca |
data,
|
|
Pierre-Yves Chibon |
dea6ca |
{'error': 'Pull-Request not found', 'error_code': "ENOREQ"}
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Create a token for foo for this project
|
|
Pierre-Yves Chibon |
dea6ca |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
dea6ca |
id='foobar_token',
|
|
Pierre-Yves Chibon |
dea6ca |
user_id=2,
|
|
Pierre-Yves Chibon |
dea6ca |
project_id=1,
|
|
Pierre-Yves Chibon |
dea6ca |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
dea6ca |
days=30)
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
self.session.add(item)
|
|
Pierre-Yves Chibon |
dea6ca |
self.session.commit()
|
|
Pierre-Yves Chibon |
dea6ca |
|
|
Pierre-Yves Chibon |
dea6ca |
# Allow the token to merge PR
|
|
Pierre-Yves Chibon |
dea6ca |
acls = pagure.lib.get_acls(self.session)
|
|
Pierre-Yves Chibon |
dea6ca |
acl = None
|
|
Pierre-Yves Chibon |
dea6ca |
for acl in acls:
|
|
Pierre-Yves Chibon |
dea6ca |
if acl.name == 'pull_request_merge':
|
|
Pierre-Yves Chibon |
dea6ca |
break
|
|
Pierre-Yves Chibon |
dea6ca |
item = pagure.lib.model.TokenAcl(
|
|
Pierre-Yves Chibon |
dea6ca |
token_id='foobar_token',
|
|
Pierre-Yves Chibon |
dea6ca |
acl_id=acl.id,
|
|
Pierre-Yves Chibon |
dea6ca |
)
|
|
Pierre-Yves Chibon |
dea6ca |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f12b4a |
self.session.commit()
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
headers = {'Authorization': 'token foobar_token'}
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
# User not admin
|
|
Pierre-Yves Chibon |
f12b4a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f12b4a |
'/api/0/test/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
f12b4a |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f12b4a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f12b4a |
data,
|
|
Pierre-Yves Chibon |
f12b4a |
{
|
|
Pierre-Yves Chibon |
f12b4a |
'error': 'You are not allowed to merge/close pull-request '
|
|
Pierre-Yves Chibon |
f12b4a |
'for this project',
|
|
Pierre-Yves Chibon |
d661a4 |
'error_code': "ENOPRCLOSE",
|
|
Pierre-Yves Chibon |
f12b4a |
}
|
|
Pierre-Yves Chibon |
f12b4a |
)
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
f12b4a |
|
|
Pierre-Yves Chibon |
f12b4a |
# Merge PR
|
|
Pierre-Yves Chibon |
a9c964 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
a9c964 |
'/api/0/test/pull-request/1/merge', headers=headers)
|
|
Pierre-Yves Chibon |
a9c964 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
a9c964 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
a9c964 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
a9c964 |
data,
|
|
Pierre-Yves Chibon |
a9c964 |
{"message": "Changes merged!"}
|
|
Pierre-Yves Chibon |
a9c964 |
)
|
|
Pierre-Yves Chibon |
a9c964 |
|
|
Pierre-Yves Chibon |
4eb5ad |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
4eb5ad |
def test_api_pull_request_add_comment(self, mockemail):
|
|
Pierre-Yves Chibon |
9ba77b |
""" Test the api_pull_request_add_comment method of the flask api. """
|
|
Pierre-Yves Chibon |
4eb5ad |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
4eb5ad |
|
|
Pierre-Yves Chibon |
9ba77b |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
9ba77b |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
9ba77b |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# Invalid project
|
|
Pierre-Yves Chibon |
9ba77b |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9ba77b |
'/api/0/foo/pull-request/1/comment', headers=headers)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
9ba77b |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9ba77b |
data,
|
|
Pierre-Yves Chibon |
9ba77b |
{
|
|
Pierre-Yves Chibon |
9ba77b |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
9ba77b |
}
|
|
Pierre-Yves Chibon |
9ba77b |
)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
9ba77b |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9ba77b |
'/api/0/test2/pull-request/1/comment', headers=headers)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
9ba77b |
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 |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# No input
|
|
Pierre-Yves Chibon |
9ba77b |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9ba77b |
'/api/0/test/pull-request/1/comment', headers=headers)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
9ba77b |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9ba77b |
data,
|
|
Pierre-Yves Chibon |
9ba77b |
{
|
|
Pierre-Yves Chibon |
9ba77b |
"error": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
9ba77b |
}
|
|
Pierre-Yves Chibon |
9ba77b |
)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# Create a pull-request
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
72e9db |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
9ba77b |
session=self.session,
|
|
Pierre-Yves Chibon |
9ba77b |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
9ba77b |
branch_from='master',
|
|
Pierre-Yves Chibon |
9ba77b |
repo_to=repo,
|
|
Pierre-Yves Chibon |
9ba77b |
branch_to='master',
|
|
Pierre-Yves Chibon |
9ba77b |
title='test pull-request',
|
|
Pierre-Yves Chibon |
9ba77b |
user='pingou',
|
|
Pierre-Yves Chibon |
9ba77b |
requestfolder=None,
|
|
Pierre-Yves Chibon |
9ba77b |
)
|
|
Pierre-Yves Chibon |
9ba77b |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# Check comments before
|
|
Pierre-Yves Chibon |
9ba77b |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
9ba77b |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(len(request.comments), 0)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
data = {
|
|
Pierre-Yves Chibon |
9ba77b |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
9ba77b |
}
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# Incomplete request
|
|
Pierre-Yves Chibon |
9ba77b |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9ba77b |
'/api/0/test/pull-request/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
9ba77b |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9ba77b |
data,
|
|
Pierre-Yves Chibon |
9ba77b |
{
|
|
Pierre-Yves Chibon |
9ba77b |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {"comment": ["This field is required."]}
|
|
Pierre-Yves Chibon |
9ba77b |
}
|
|
Pierre-Yves Chibon |
9ba77b |
)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# No change
|
|
Pierre-Yves Chibon |
9ba77b |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
9ba77b |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(len(request.comments), 0)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
data = {
|
|
Pierre-Yves Chibon |
9ba77b |
'comment': 'This is a very interesting question',
|
|
Pierre-Yves Chibon |
9ba77b |
}
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# Valid request
|
|
Pierre-Yves Chibon |
9ba77b |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9ba77b |
'/api/0/test/pull-request/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9ba77b |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9ba77b |
data,
|
|
Pierre-Yves Chibon |
9ba77b |
{'message': 'Comment added'}
|
|
Pierre-Yves Chibon |
9ba77b |
)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
9ba77b |
# One comment added
|
|
Pierre-Yves Chibon |
9ba77b |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
9ba77b |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
9ba77b |
self.assertEqual(len(request.comments), 1)
|
|
Pierre-Yves Chibon |
9ba77b |
|
|
Pierre-Yves Chibon |
e18f81 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
1dfd94 |
def test_api_pull_request_add_comment_user_token(self, mockemail):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_pull_request_add_comment method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects(self.session)
|
|
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 aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Invalid project
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/foo/pull-request/1/comment', 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 |
# Valid token, invalid request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test2/pull-request/1/comment', 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": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid token, invalid request in another project
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/pull-request/1/comment', 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": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Create a pull-request
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
e498a1 |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
1dfd94 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
1dfd94 |
session=self.session,
|
|
Pierre-Yves Chibon |
1dfd94 |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
1dfd94 |
branch_from='master',
|
|
Pierre-Yves Chibon |
1dfd94 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
1dfd94 |
branch_to='master',
|
|
Pierre-Yves Chibon |
1dfd94 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
1dfd94 |
user='pingou',
|
|
Pierre-Yves Chibon |
1dfd94 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session.commit()
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Check comments before
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.comments), 0)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
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/test/pull-request/1/comment', 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": {"comment": ["This field is required."]}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# No change
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.comments), 0)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'comment': 'This is a very interesting question',
|
|
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/test/pull-request/1/comment', 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': 'Comment added'}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# One comment added
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.comments), 1)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
e18f81 |
def test_api_pull_request_add_flag(self, mockemail):
|
|
Pierre-Yves Chibon |
e18f81 |
""" Test the api_pull_request_add_flag method of the flask api. """
|
|
Pierre-Yves Chibon |
e18f81 |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
e18f81 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
e18f81 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Invalid project
|
|
Pierre-Yves Chibon |
e18f81 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
e18f81 |
'/api/0/foo/pull-request/1/flag', headers=headers)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
e18f81 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e18f81 |
data,
|
|
Pierre-Yves Chibon |
e18f81 |
{
|
|
Pierre-Yves Chibon |
e18f81 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
e18f81 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
e18f81 |
}
|
|
Pierre-Yves Chibon |
e18f81 |
)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
e18f81 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
e18f81 |
'/api/0/test2/pull-request/1/flag', headers=headers)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
e18f81 |
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 |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# No input
|
|
Pierre-Yves Chibon |
e18f81 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
e18f81 |
'/api/0/test/pull-request/1/flag', headers=headers)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
e18f81 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e18f81 |
data,
|
|
Pierre-Yves Chibon |
e18f81 |
{
|
|
Pierre-Yves Chibon |
e18f81 |
"error": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
e18f81 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
e18f81 |
}
|
|
Pierre-Yves Chibon |
e18f81 |
)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Create a pull-request
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
72e9db |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
f9c5f9 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
e18f81 |
session=self.session,
|
|
Pierre-Yves Chibon |
e18f81 |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
e18f81 |
branch_from='master',
|
|
Pierre-Yves Chibon |
e18f81 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
e18f81 |
branch_to='master',
|
|
Pierre-Yves Chibon |
e18f81 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
e18f81 |
user='pingou',
|
|
Pierre-Yves Chibon |
e18f81 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session.commit()
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Check comments before
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.flags), 0)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
1dfd94 |
'percent': 100,
|
|
Pierre-Yves Chibon |
1dfd94 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
1dfd94 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
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/test/pull-request/1/flag', 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": {"comment": ["This field is required."]}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# No change
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.flags), 0)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
1dfd94 |
'percent': 0,
|
|
Pierre-Yves Chibon |
1dfd94 |
'comment': 'Tests failed',
|
|
Pierre-Yves Chibon |
1dfd94 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
1dfd94 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
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/test/pull-request/1/flag', 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': 'Flag added'}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# One flag added
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.flags), 1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(request.flags[0].comment, 'Tests failed')
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(request.flags[0].percent, 0)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Update flag
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
1dfd94 |
'percent': 100,
|
|
Pierre-Yves Chibon |
1dfd94 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
1dfd94 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
1dfd94 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/pull-request/1/flag', 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': 'Flag updated'}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# One flag added
|
|
Pierre-Yves Chibon |
1dfd94 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
1dfd94 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(len(request.flags), 1)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(request.flags[0].comment, 'Tests passed')
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(request.flags[0].percent, 100)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
1dfd94 |
def test_api_pull_request_add_flag_user_token(self, mockemail):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_pull_request_add_flag method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
mockemail.return_value = True
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects(self.session)
|
|
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 aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Invalid project
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/foo/pull-request/1/flag', 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 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test2/pull-request/1/flag', 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": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# No input
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/pull-request/1/flag', 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": "Pull-Request not found",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Create a pull-request
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Farhaan Bukhsh |
e498a1 |
forked_repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
1dfd94 |
req = pagure.lib.new_pull_request(
|
|
Pierre-Yves Chibon |
1dfd94 |
session=self.session,
|
|
Pierre-Yves Chibon |
1dfd94 |
repo_from=forked_repo,
|
|
Pierre-Yves Chibon |
1dfd94 |
branch_from='master',
|
|
Pierre-Yves Chibon |
1dfd94 |
repo_to=repo,
|
|
Pierre-Yves Chibon |
1dfd94 |
branch_to='master',
|
|
Pierre-Yves Chibon |
1dfd94 |
title='test pull-request',
|
|
Pierre-Yves Chibon |
1dfd94 |
user='pingou',
|
|
Pierre-Yves Chibon |
1dfd94 |
requestfolder=None,
|
|
Pierre-Yves Chibon |
e18f81 |
)
|
|
Pierre-Yves Chibon |
e18f81 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
f9c5f9 |
self.assertEqual(req.title, 'test pull-request')
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Check comments before
|
|
Pierre-Yves Chibon |
e18f81 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
e18f81 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(len(request.flags), 0)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
data = {
|
|
Pierre-Yves Chibon |
e18f81 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
e18f81 |
'percent': 100,
|
|
Pierre-Yves Chibon |
e18f81 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
e18f81 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
e18f81 |
}
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Incomplete request
|
|
Pierre-Yves Chibon |
e18f81 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
e18f81 |
'/api/0/test/pull-request/1/flag', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
e18f81 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e18f81 |
data,
|
|
Pierre-Yves Chibon |
e18f81 |
{
|
|
Pierre-Yves Chibon |
e18f81 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
e18f81 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {"comment": ["This field is required."]}
|
|
Pierre-Yves Chibon |
e18f81 |
}
|
|
Pierre-Yves Chibon |
e18f81 |
)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# No change
|
|
Pierre-Yves Chibon |
e18f81 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
e18f81 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(len(request.flags), 0)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
data = {
|
|
Pierre-Yves Chibon |
e18f81 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
e18f81 |
'percent': 0,
|
|
Pierre-Yves Chibon |
e18f81 |
'comment': 'Tests failed',
|
|
Pierre-Yves Chibon |
e18f81 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
e18f81 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
e18f81 |
}
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Valid request
|
|
Pierre-Yves Chibon |
e18f81 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
e18f81 |
'/api/0/test/pull-request/1/flag', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e18f81 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e18f81 |
data,
|
|
Pierre-Yves Chibon |
e18f81 |
{'message': 'Flag added'}
|
|
Pierre-Yves Chibon |
e18f81 |
)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# One flag added
|
|
Pierre-Yves Chibon |
e18f81 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
e18f81 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(len(request.flags), 1)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(request.flags[0].comment, 'Tests failed')
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(request.flags[0].percent, 0)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# Update flag
|
|
Pierre-Yves Chibon |
e18f81 |
data = {
|
|
Pierre-Yves Chibon |
e18f81 |
'username': 'Jenkins',
|
|
Pierre-Yves Chibon |
e18f81 |
'percent': 100,
|
|
Pierre-Yves Chibon |
e18f81 |
'comment': 'Tests passed',
|
|
Pierre-Yves Chibon |
e18f81 |
'url': 'http://jenkins.cloud.fedoraproject.org/',
|
|
Pierre-Yves Chibon |
e18f81 |
'uid': 'jenkins_build_pagure_100+seed',
|
|
Pierre-Yves Chibon |
e18f81 |
}
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
e18f81 |
'/api/0/test/pull-request/1/flag', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e18f81 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e18f81 |
data,
|
|
Pierre-Yves Chibon |
e18f81 |
{'message': 'Flag updated'}
|
|
Pierre-Yves Chibon |
e18f81 |
)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
e18f81 |
# One flag added
|
|
Pierre-Yves Chibon |
e18f81 |
request = pagure.lib.search_pull_requests(
|
|
Pierre-Yves Chibon |
e18f81 |
self.session, project_id=1, requestid=1)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(len(request.flags), 1)
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(request.flags[0].comment, 'Tests passed')
|
|
Pierre-Yves Chibon |
e18f81 |
self.assertEqual(request.flags[0].percent, 100)
|
|
Pierre-Yves Chibon |
e18f81 |
|
|
Pierre-Yves Chibon |
c71c2d |
|
|
Pierre-Yves Chibon |
c71c2d |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
393f31 |
unittest.main(verbosity=2)
|