|
Pierre-Yves Chibon |
993597 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
"""
|
|
Pierre-Yves Chibon |
993597 |
(c) 2015 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
Authors:
|
|
Pierre-Yves Chibon |
993597 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
"""
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
__requires__ = ['SQLAlchemy >= 0.8']
|
|
Pierre-Yves Chibon |
993597 |
import pkg_resources
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
f69837 |
import datetime
|
|
Pierre-Yves Chibon |
993597 |
import unittest
|
|
Pierre-Yves Chibon |
993597 |
import shutil
|
|
Pierre-Yves Chibon |
993597 |
import sys
|
|
Pierre-Yves Chibon |
993597 |
import os
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
import json
|
|
Pierre-Yves Chibon |
993597 |
from mock import patch
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
sys.path.insert(0, os.path.join(os.path.dirname(
|
|
Pierre-Yves Chibon |
993597 |
os.path.abspath(__file__)), '..'))
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
import pagure.lib
|
|
Pierre-Yves Chibon |
993597 |
import tests
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
89a786 |
FULL_ISSUE_LIST = [
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "We should work on this",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Mark Reynolds |
fc57b6 |
"id": 9,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": True,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "Test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Mark Reynolds |
fc57b6 |
"id": 8,
|
|
Mark Reynolds |
fc57b6 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Mark Reynolds |
fc57b6 |
"priority": None,
|
|
Mark Reynolds |
fc57b6 |
"private": True,
|
|
Mark Reynolds |
fc57b6 |
"status": "Open",
|
|
Mark Reynolds |
fc57b6 |
"tags": [],
|
|
Mark Reynolds |
fc57b6 |
"title": "test issue1",
|
|
Mark Reynolds |
fc57b6 |
"user": {
|
|
Mark Reynolds |
fc57b6 |
"fullname": "PY C",
|
|
Mark Reynolds |
fc57b6 |
"name": "pingou"
|
|
Mark Reynolds |
fc57b6 |
}
|
|
Mark Reynolds |
fc57b6 |
},
|
|
Mark Reynolds |
fc57b6 |
{
|
|
Mark Reynolds |
fc57b6 |
"assignee": None,
|
|
Mark Reynolds |
fc57b6 |
"blocks": [],
|
|
Mark Reynolds |
fc57b6 |
"close_status": None,
|
|
Mark Reynolds |
fc57b6 |
"closed_at": None,
|
|
Mark Reynolds |
fc57b6 |
"comments": [],
|
|
Mark Reynolds |
fc57b6 |
"content": "This issue needs attention",
|
|
Mark Reynolds |
fc57b6 |
"custom_fields": [],
|
|
Mark Reynolds |
fc57b6 |
"date_created": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 7,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": True,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 6,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Mark Reynolds |
fc57b6 |
"private": False,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 5,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": False,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 4,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": False,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 3,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": False,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 2,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "milestone-1.0",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": False,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"blocks": [],
|
|
Pierre-Yves Chibon |
89a786 |
"close_status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
89a786 |
"comments": [],
|
|
Pierre-Yves Chibon |
89a786 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
89a786 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
89a786 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
89a786 |
"depends": [],
|
|
Pierre-Yves Chibon |
89a786 |
"id": 1,
|
|
Pierre-Yves Chibon |
89a786 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
89a786 |
"priority": None,
|
|
Pierre-Yves Chibon |
89a786 |
"private": False,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "Open",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": [],
|
|
Pierre-Yves Chibon |
89a786 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
89a786 |
"user": {
|
|
Pierre-Yves Chibon |
89a786 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
89a786 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
]
|
|
Pierre-Yves Chibon |
993597 |
|
|
Mark Reynolds |
fc57b6 |
|
|
Pierre-Yves Chibon |
993597 |
class PagureFlaskApiIssuetests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
993597 |
""" Tests for the flask API of pagure for issue """
|
|
Pierre-Yves Chibon |
993597 |
def setUp(self):
|
|
Pierre-Yves Chibon |
993597 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
993597 |
super(PagureFlaskApiIssuetests, self).setUp()
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
pagure.APP.config['TESTING'] = True
|
|
Pierre-Yves Chibon |
993597 |
pagure.SESSION = self.session
|
|
Pierre-Yves Chibon |
993597 |
pagure.api.SESSION = self.session
|
|
Pierre-Yves Chibon |
993597 |
pagure.api.issue.SESSION = self.session
|
|
Pierre-Yves Chibon |
993597 |
pagure.lib.SESSION = self.session
|
|
Pierre-Yves Chibon |
e5c5fc |
|
|
Pierre-Yves Chibon |
0e5cb2 |
pagure.APP.config['TICKETS_FOLDER'] = None
|
|
Pierre-Yves Chibon |
e5c5fc |
|
|
Pierre-Yves Chibon |
993597 |
self.app = pagure.APP.test_client()
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
def test_api_new_issue(self):
|
|
Pierre-Yves Chibon |
3e3362 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
993597 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
b0c55b |
tests.create_projects_git(
|
|
Jeremy Cline |
20109f |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
993597 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
993597 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
993597 |
output = self.app.post('/api/0/test2/new_issue', headers=headers)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
993597 |
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 |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
# No input
|
|
Pierre-Yves Chibon |
993597 |
output = self.app.post('/api/0/test/new_issue', headers=headers)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
993597 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
993597 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
993597 |
data,
|
|
Pierre-Yves Chibon |
993597 |
{
|
|
Pierre-Yves Chibon |
993597 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {
|
|
Pierre-Yves Chibon |
f7fcaa |
"issue_content": ["This field is required."],
|
|
Mark Reynolds |
fc57b6 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
f7fcaa |
}
|
|
Pierre-Yves Chibon |
993597 |
}
|
|
Pierre-Yves Chibon |
993597 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
data = {
|
|
Mark Reynolds |
fc57b6 |
'title': 'test issue'
|
|
Pierre-Yves Chibon |
993597 |
}
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
f69837 |
# Invalid repo
|
|
Pierre-Yves Chibon |
f69837 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f69837 |
'/api/0/foo/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
f69837 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
f69837 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f69837 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f69837 |
data,
|
|
Pierre-Yves Chibon |
f69837 |
{
|
|
Pierre-Yves Chibon |
f69837 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
f69837 |
}
|
|
Pierre-Yves Chibon |
f69837 |
)
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
993597 |
# Incomplete request
|
|
Pierre-Yves Chibon |
993597 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
993597 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
993597 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
993597 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
993597 |
data,
|
|
Pierre-Yves Chibon |
993597 |
{
|
|
Pierre-Yves Chibon |
993597 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {
|
|
Pierre-Yves Chibon |
f7fcaa |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
f7fcaa |
"title": ["This field is required."]
|
|
Pierre-Yves Chibon |
f7fcaa |
}
|
|
Pierre-Yves Chibon |
993597 |
}
|
|
Pierre-Yves Chibon |
993597 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
data = {
|
|
Pierre-Yves Chibon |
993597 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
993597 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
993597 |
}
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
# Valid request
|
|
Pierre-Yves Chibon |
993597 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
993597 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
993597 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
993597 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
993597 |
data,
|
|
Pierre-Yves Chibon |
ec7d5e |
{
|
|
Mark Reynolds |
fc57b6 |
"issue": FULL_ISSUE_LIST[8],
|
|
Mark Reynolds |
fc57b6 |
"message": "Issue created"
|
|
Mark Reynolds |
fc57b6 |
}
|
|
Mark Reynolds |
fc57b6 |
)
|
|
Mark Reynolds |
fc57b6 |
|
|
Mark Reynolds |
fc57b6 |
# Valid request with milestone
|
|
Mark Reynolds |
fc57b6 |
data = {
|
|
Mark Reynolds |
fc57b6 |
'title': 'test issue',
|
|
Mark Reynolds |
fc57b6 |
'issue_content': 'This issue needs attention',
|
|
Mark Reynolds |
fc57b6 |
'milestone': ['milestone-1.0'],
|
|
Mark Reynolds |
fc57b6 |
}
|
|
Mark Reynolds |
fc57b6 |
output = self.app.post(
|
|
Mark Reynolds |
fc57b6 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Mark Reynolds |
fc57b6 |
self.assertEqual(output.status_code, 200)
|
|
Mark Reynolds |
fc57b6 |
data = json.loads(output.data)
|
|
Mark Reynolds |
fc57b6 |
data['issue']['date_created'] = '1431414800'
|
|
Mark Reynolds |
fc57b6 |
data['issue']['last_updated'] = '1431414800'
|
|
Mark Reynolds |
fc57b6 |
|
|
Mark Reynolds |
fc57b6 |
self.assertDictEqual(
|
|
Mark Reynolds |
fc57b6 |
data,
|
|
Mark Reynolds |
fc57b6 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[7],
|
|
Pierre-Yves Chibon |
ec7d5e |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
ec7d5e |
}
|
|
Pierre-Yves Chibon |
993597 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Valid request, with private='false'
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
9a9e42 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
9a9e42 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
9a9e42 |
'private': 'false',
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9a9e42 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[6],
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Valid request, with private=False
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
9a9e42 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
9a9e42 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
9a9e42 |
'private': False
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9a9e42 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[5],
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Valid request, with private='False'
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
9a9e42 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
9a9e42 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
9a9e42 |
'private': 'False'
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9a9e42 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[4],
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Valid request, with private=0
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
9a9e42 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
9a9e42 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
9a9e42 |
'private': 0
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9a9e42 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[3],
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Private issue: True
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
9a9e42 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
9a9e42 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
9a9e42 |
'private': True,
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9a9e42 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[2],
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Private issue: 1
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Mark Reynolds |
fc57b6 |
'title': 'test issue1',
|
|
Pierre-Yves Chibon |
9a9e42 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
9a9e42 |
'private': 1,
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
9a9e42 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"issue": FULL_ISSUE_LIST[1],
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
13e2e9 |
def test_api_view_issues(self):
|
|
Pierre-Yves Chibon |
13e2e9 |
""" Test the api_view_issues method of the flask api. """
|
|
Pierre-Yves Chibon |
13e2e9 |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
13e2e9 |
# Invalid repo
|
|
Pierre-Yves Chibon |
13e2e9 |
output = self.app.get('/api/0/foo/issues')
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
13e2e9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
13e2e9 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
13e2e9 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
13e2e9 |
}
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# List all opened issues
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issues')
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9a9e42 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
9a9e42 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
9a9e42 |
"args": {
|
|
Pierre-Yves Chibon |
9a9e42 |
"assignee": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"author": None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"status": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"tags": []
|
|
Pierre-Yves Chibon |
9a9e42 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST[3:],
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 6
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Create private issue
|
|
Pierre-Yves Chibon |
9a9e42 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
9a9e42 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
9a9e42 |
session=self.session,
|
|
Pierre-Yves Chibon |
9a9e42 |
repo=repo,
|
|
Pierre-Yves Chibon |
9a9e42 |
title='Test issue',
|
|
Pierre-Yves Chibon |
9a9e42 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
9a9e42 |
user='pingou',
|
|
Pierre-Yves Chibon |
9a9e42 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
9a9e42 |
private=True,
|
|
Mark Reynolds |
fc57b6 |
milestone=""
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.session.commit()
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues un-authenticated
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issues')
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
9a9e42 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9a9e42 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
9a9e42 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
9a9e42 |
"args": {
|
|
Pierre-Yves Chibon |
9a9e42 |
"assignee": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"author": None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"status": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"tags": []
|
|
Pierre-Yves Chibon |
9a9e42 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST[3:],
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 6
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
)
|
|
Pierre-Yves Chibon |
89a786 |
headers = {'Authorization': 'token aaabbbccc'}
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Access issues authenticated but non-existing token
|
|
Pierre-Yves Chibon |
89a786 |
output = self.app.get('/api/0/test/issues', headers=headers)
|
|
Pierre-Yves Chibon |
89a786 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Create a new token for another user
|
|
Pierre-Yves Chibon |
89a786 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
89a786 |
id='bar_token',
|
|
Pierre-Yves Chibon |
89a786 |
user_id=2,
|
|
Pierre-Yves Chibon |
89a786 |
project_id=1,
|
|
Pierre-Yves Chibon |
89a786 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
89a786 |
days=30)
|
|
Pierre-Yves Chibon |
89a786 |
)
|
|
Pierre-Yves Chibon |
89a786 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
headers = {'Authorization': 'token bar_token'}
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Access issues authenticated but wrong token
|
|
Pierre-Yves Chibon |
89a786 |
output = self.app.get('/api/0/test/issues', headers=headers)
|
|
Pierre-Yves Chibon |
89a786 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
89a786 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
89a786 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
89a786 |
data,
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"args": {
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"author": None,
|
|
Pierre-Yves Chibon |
89a786 |
"since": None,
|
|
Pierre-Yves Chibon |
89a786 |
"status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"tags": []
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST[3:],
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 6
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Access issues authenticated correctly
|
|
Pierre-Yves Chibon |
89a786 |
output = self.app.get('/api/0/test/issues', headers=headers)
|
|
Pierre-Yves Chibon |
89a786 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
89a786 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
89a786 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
89a786 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Mark Reynolds |
fc57b6 |
|
|
Pierre-Yves Chibon |
89a786 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
89a786 |
data,
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
89a786 |
"args": {
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"author": None,
|
|
Pierre-Yves Chibon |
89a786 |
"since": None,
|
|
Pierre-Yves Chibon |
89a786 |
"status": None,
|
|
Pierre-Yves Chibon |
89a786 |
"tags": []
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST,
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 9
|
|
Pierre-Yves Chibon |
89a786 |
}
|
|
Pierre-Yves Chibon |
89a786 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
headers = {'Authorization': 'token aaabbbccc'}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues authenticated but non-existing token
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issues', headers=headers)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Create a new token for another user
|
|
Pierre-Yves Chibon |
9a9e42 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
9a9e42 |
id='bar_token',
|
|
Pierre-Yves Chibon |
9a9e42 |
user_id=2,
|
|
Pierre-Yves Chibon |
9a9e42 |
project_id=1,
|
|
Pierre-Yves Chibon |
9a9e42 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
9a9e42 |
days=30)
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
headers = {'Authorization': 'token bar_token'}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues authenticated but wrong token
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issues', headers=headers)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
13e2e9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9a9e42 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
9a9e42 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
316f15 |
"args": {
|
|
Pierre-Yves Chibon |
316f15 |
"assignee": None,
|
|
Pierre-Yves Chibon |
316f15 |
"author": None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
316f15 |
"status": None,
|
|
Pierre-Yves Chibon |
316f15 |
"tags": []
|
|
Pierre-Yves Chibon |
316f15 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST[3:],
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 6
|
|
Pierre-Yves Chibon |
13e2e9 |
}
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
9a9e42 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues authenticated correctly
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issues', headers=headers)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
13e2e9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9a9e42 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
9a9e42 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
316f15 |
"args": {
|
|
Pierre-Yves Chibon |
316f15 |
"assignee": None,
|
|
Pierre-Yves Chibon |
316f15 |
"author": None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
316f15 |
"status": None,
|
|
Pierre-Yves Chibon |
316f15 |
"tags": []
|
|
Pierre-Yves Chibon |
316f15 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST,
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 9
|
|
Pierre-Yves Chibon |
13e2e9 |
}
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
13e2e9 |
# List closed issue
|
|
Pierre-Yves Chibon |
89a786 |
output = self.app.get('/api/0/test/issues?status=Closed', headers=headers)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
13e2e9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
316f15 |
"args": {
|
|
Pierre-Yves Chibon |
316f15 |
"assignee": None,
|
|
Pierre-Yves Chibon |
316f15 |
"author": None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
316f15 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
316f15 |
"tags": []
|
|
Pierre-Yves Chibon |
316f15 |
},
|
|
Pierre-Yves Chibon |
226628 |
"total_issues": 0,
|
|
Pierre-Yves Chibon |
316f15 |
"issues": []
|
|
Pierre-Yves Chibon |
13e2e9 |
}
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
13e2e9 |
# List closed issue
|
|
Pierre-Yves Chibon |
89a786 |
output = self.app.get('/api/0/test/issues?status=Invalid', headers=headers)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
13e2e9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
316f15 |
"args": {
|
|
Pierre-Yves Chibon |
316f15 |
"assignee": None,
|
|
Pierre-Yves Chibon |
316f15 |
"author": None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
316f15 |
"status": "Invalid",
|
|
Pierre-Yves Chibon |
316f15 |
"tags": []
|
|
Pierre-Yves Chibon |
316f15 |
},
|
|
Pierre-Yves Chibon |
226628 |
"total_issues": 0,
|
|
Pierre-Yves Chibon |
316f15 |
"issues": []
|
|
Pierre-Yves Chibon |
13e2e9 |
}
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Sayan Chowdhury |
e3c0af |
# List all issues
|
|
Sayan Chowdhury |
e3c0af |
output = self.app.get('/api/0/test/issues?status=All', headers=headers)
|
|
Sayan Chowdhury |
e3c0af |
self.assertEqual(output.status_code, 200)
|
|
Sayan Chowdhury |
e3c0af |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
9a9e42 |
for idx in range(len(data['issues'])):
|
|
Mark Reynolds |
23b4d2 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
89a786 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Sayan Chowdhury |
e3c0af |
self.assertDictEqual(
|
|
Sayan Chowdhury |
e3c0af |
data,
|
|
Sayan Chowdhury |
e3c0af |
{
|
|
Pierre-Yves Chibon |
89a786 |
"args": {
|
|
Pierre-Yves Chibon |
89a786 |
"assignee": None,
|
|
Pierre-Yves Chibon |
89a786 |
"author": None,
|
|
Pierre-Yves Chibon |
89a786 |
"since": None,
|
|
Pierre-Yves Chibon |
89a786 |
"status": "All",
|
|
Pierre-Yves Chibon |
89a786 |
"tags": []
|
|
Pierre-Yves Chibon |
89a786 |
},
|
|
Pierre-Yves Chibon |
89a786 |
"issues": FULL_ISSUE_LIST,
|
|
Mark Reynolds |
fc57b6 |
"total_issues": 9
|
|
Sayan Chowdhury |
e3c0af |
}
|
|
Sayan Chowdhury |
e3c0af |
)
|
|
Sayan Chowdhury |
e3c0af |
|
|
Pierre-Yves Chibon |
1c76b9 |
def test_api_view_issue(self):
|
|
Pierre-Yves Chibon |
1c76b9 |
""" Test the api_view_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
1c76b9 |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
1c76b9 |
|
|
Pierre-Yves Chibon |
4a277d |
# Invalid repo
|
|
Pierre-Yves Chibon |
4a277d |
output = self.app.get('/api/0/foo/issue/1')
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
4a277d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
4a277d |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
4a277d |
}
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
# Invalid issue for this repo
|
|
Pierre-Yves Chibon |
1c76b9 |
output = self.app.get('/api/0/test2/issue/1')
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
1c76b9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c76b9 |
data,
|
|
Pierre-Yves Chibon |
1c76b9 |
{
|
|
Pierre-Yves Chibon |
1c76b9 |
"error": "Issue not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOISSUE",
|
|
Pierre-Yves Chibon |
1c76b9 |
}
|
|
Pierre-Yves Chibon |
1c76b9 |
)
|
|
Pierre-Yves Chibon |
1c76b9 |
|
|
Pierre-Yves Chibon |
4a277d |
# Valid issue
|
|
Pierre-Yves Chibon |
1c76b9 |
output = self.app.get('/api/0/test/issue/1')
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1c76b9 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1c76b9 |
data['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c76b9 |
data,
|
|
Pierre-Yves Chibon |
1c76b9 |
{
|
|
Pierre-Yves Chibon |
1c76b9 |
"assignee": None,
|
|
Pierre-Yves Chibon |
1c76b9 |
"blocks": [],
|
|
Pierre-Yves Chibon |
1c76b9 |
"comments": [],
|
|
Pierre-Yves Chibon |
1c76b9 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
e5e9eb |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
1c76b9 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
a71f76 |
"close_status": None,
|
|
Vivek Anand |
d7285b |
"closed_at": None,
|
|
Pierre-Yves Chibon |
1c76b9 |
"depends": [],
|
|
Pierre-Yves Chibon |
1c76b9 |
"id": 1,
|
|
Mark Reynolds |
23b4d2 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
b5c8b4 |
"priority": None,
|
|
Pierre-Yves Chibon |
1c76b9 |
"private": False,
|
|
Pierre-Yves Chibon |
1c76b9 |
"status": "Open",
|
|
Pierre-Yves Chibon |
1c76b9 |
"tags": [],
|
|
Pierre-Yves Chibon |
1c76b9 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
1c76b9 |
"user": {
|
|
Pierre-Yves Chibon |
1c76b9 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
1c76b9 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
1c76b9 |
}
|
|
Pierre-Yves Chibon |
1c76b9 |
}
|
|
Pierre-Yves Chibon |
1c76b9 |
)
|
|
Pierre-Yves Chibon |
1c76b9 |
|
|
Pierre-Yves Chibon |
4a277d |
# Create private issue
|
|
Pierre-Yves Chibon |
4a277d |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
4a277d |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
4a277d |
session=self.session,
|
|
Pierre-Yves Chibon |
4a277d |
repo=repo,
|
|
Pierre-Yves Chibon |
4a277d |
title='Test issue',
|
|
Pierre-Yves Chibon |
4a277d |
content='We should work on this',
|
|
Pierre-Yves Chibon |
4a277d |
user='pingou',
|
|
Pierre-Yves Chibon |
4a277d |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
4a277d |
private=True,
|
|
Pierre-Yves Chibon |
7b4f84 |
issue_uid='aaabbbccc',
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
self.session.commit()
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
# Access private issue un-authenticated
|
|
Mark Reynolds |
fc57b6 |
output = self.app.get('/api/0/test/issue/7')
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
4a277d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
4a277d |
"error": "You are not allowed to view this issue",
|
|
Pierre-Yves Chibon |
76338b |
"error_code": "EISSUENOTALLOWED",
|
|
Pierre-Yves Chibon |
4a277d |
}
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
headers = {'Authorization': 'token aaabbbccc'}
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
c4fef5 |
# Access private issue authenticated but non-existing token
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issue/6', headers=headers)
|
|
Pierre-Yves Chibon |
c4fef5 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
c4fef5 |
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 |
c4fef5 |
|
|
Pierre-Yves Chibon |
c4fef5 |
# Create a new token for another user
|
|
Pierre-Yves Chibon |
c4fef5 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
c4fef5 |
id='bar_token',
|
|
Pierre-Yves Chibon |
c4fef5 |
user_id=2,
|
|
Pierre-Yves Chibon |
c4fef5 |
project_id=1,
|
|
Pierre-Yves Chibon |
c4fef5 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
c4fef5 |
days=30)
|
|
Pierre-Yves Chibon |
c4fef5 |
)
|
|
Pierre-Yves Chibon |
c4fef5 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
c4fef5 |
|
|
Pierre-Yves Chibon |
c4fef5 |
headers = {'Authorization': 'token bar_token'}
|
|
Pierre-Yves Chibon |
c4fef5 |
|
|
Pierre-Yves Chibon |
4a277d |
# Access private issue authenticated but wrong token
|
|
Mark Reynolds |
fc57b6 |
output = self.app.get('/api/0/test/issue/7', headers=headers)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
4a277d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
4a277d |
"error": "You are not allowed to view this issue",
|
|
Pierre-Yves Chibon |
76338b |
"error_code": "EISSUENOTALLOWED",
|
|
Pierre-Yves Chibon |
4a277d |
}
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
# Access private issue authenticated correctly
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.get('/api/0/test/issue/6', headers=headers)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7b4f84 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7b4f84 |
data['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
7b4f84 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7b4f84 |
data,
|
|
Pierre-Yves Chibon |
7b4f84 |
{
|
|
Pierre-Yves Chibon |
7b4f84 |
"assignee": None,
|
|
Pierre-Yves Chibon |
7b4f84 |
"blocks": [],
|
|
Pierre-Yves Chibon |
7b4f84 |
"comments": [],
|
|
Pierre-Yves Chibon |
9a9e42 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
e5e9eb |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
7b4f84 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
a71f76 |
"close_status": None,
|
|
Vivek Anand |
d7285b |
"closed_at": None,
|
|
Pierre-Yves Chibon |
7b4f84 |
"depends": [],
|
|
Pierre-Yves Chibon |
9a9e42 |
"id": 6,
|
|
Mark Reynolds |
23b4d2 |
"last_updated": "1431414800",
|
|
Mark Reynolds |
fc57b6 |
"milestone": "",
|
|
Pierre-Yves Chibon |
b5c8b4 |
"priority": None,
|
|
Mark Reynolds |
fc57b6 |
"private": False,
|
|
Pierre-Yves Chibon |
7b4f84 |
"status": "Open",
|
|
Pierre-Yves Chibon |
7b4f84 |
"tags": [],
|
|
Pierre-Yves Chibon |
9a9e42 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
7b4f84 |
"user": {
|
|
Pierre-Yves Chibon |
7b4f84 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
7b4f84 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
7b4f84 |
}
|
|
Pierre-Yves Chibon |
7b4f84 |
}
|
|
Pierre-Yves Chibon |
7b4f84 |
)
|
|
Pierre-Yves Chibon |
7b4f84 |
|
|
Pierre-Yves Chibon |
7b4f84 |
# Access private issue authenticated correctly using the issue's uid
|
|
Pierre-Yves Chibon |
7b4f84 |
output = self.app.get('/api/0/test/issue/aaabbbccc', headers=headers)
|
|
Pierre-Yves Chibon |
7b4f84 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
4a277d |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
4a277d |
data['date_created'] = '1431414800'
|
|
Mark Reynolds |
23b4d2 |
data['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
4a277d |
"assignee": None,
|
|
Pierre-Yves Chibon |
4a277d |
"blocks": [],
|
|
Pierre-Yves Chibon |
4a277d |
"comments": [],
|
|
Pierre-Yves Chibon |
4a277d |
"content": "We should work on this",
|
|
Pierre-Yves Chibon |
e5e9eb |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
4a277d |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
a71f76 |
"close_status": None,
|
|
Vivek Anand |
d7285b |
"closed_at": None,
|
|
Pierre-Yves Chibon |
4a277d |
"depends": [],
|
|
Mark Reynolds |
fc57b6 |
"id": 9,
|
|
Mark Reynolds |
23b4d2 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
725fca |
"milestone": None,
|
|
Pierre-Yves Chibon |
b5c8b4 |
"priority": None,
|
|
Pierre-Yves Chibon |
4a277d |
"private": True,
|
|
Pierre-Yves Chibon |
4a277d |
"status": "Open",
|
|
Pierre-Yves Chibon |
4a277d |
"tags": [],
|
|
Pierre-Yves Chibon |
4a277d |
"title": "Test issue",
|
|
Pierre-Yves Chibon |
4a277d |
"user": {
|
|
Pierre-Yves Chibon |
4a277d |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
4a277d |
"name": "pingou"
|
|
Pierre-Yves Chibon |
4a277d |
}
|
|
Pierre-Yves Chibon |
4a277d |
}
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
218ed6 |
def test_api_change_status_issue(self):
|
|
Pierre-Yves Chibon |
218ed6 |
""" Test the api_change_status_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
218ed6 |
tests.create_projects(self.session)
|
|
Jeremy Cline |
20109f |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
218ed6 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
218ed6 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
f69837 |
# Invalid project
|
|
Pierre-Yves Chibon |
f69837 |
output = self.app.post('/api/0/foo/issue/1/status', headers=headers)
|
|
Pierre-Yves Chibon |
f69837 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
f69837 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f69837 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f69837 |
data,
|
|
Pierre-Yves Chibon |
f69837 |
{
|
|
Pierre-Yves Chibon |
f69837 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
f69837 |
}
|
|
Pierre-Yves Chibon |
f69837 |
)
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
218ed6 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
218ed6 |
output = self.app.post('/api/0/test2/issue/1/status', headers=headers)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
218ed6 |
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 |
218ed6 |
|
|
Pierre-Yves Chibon |
7bbefe |
# No issue
|
|
Pierre-Yves Chibon |
218ed6 |
output = self.app.post('/api/0/test/issue/1/status', headers=headers)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
218ed6 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
218ed6 |
data,
|
|
Pierre-Yves Chibon |
218ed6 |
{
|
|
Pierre-Yves Chibon |
218ed6 |
"error": "Issue not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOISSUE",
|
|
Pierre-Yves Chibon |
218ed6 |
}
|
|
Pierre-Yves Chibon |
218ed6 |
)
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# Create normal issue
|
|
Pierre-Yves Chibon |
218ed6 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
218ed6 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
218ed6 |
session=self.session,
|
|
Pierre-Yves Chibon |
218ed6 |
repo=repo,
|
|
Pierre-Yves Chibon |
218ed6 |
title='Test issue #1',
|
|
Pierre-Yves Chibon |
218ed6 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
218ed6 |
user='pingou',
|
|
Pierre-Yves Chibon |
218ed6 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
218ed6 |
private=False,
|
|
Pierre-Yves Chibon |
218ed6 |
)
|
|
Pierre-Yves Chibon |
218ed6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
f69837 |
# Create another project
|
|
Pierre-Yves Chibon |
f69837 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
f69837 |
user_id=2, # pingou
|
|
Pierre-Yves Chibon |
f69837 |
name='foo',
|
|
Pierre-Yves Chibon |
f69837 |
description='test project #3',
|
|
Pierre-Yves Chibon |
f69837 |
hook_token='aaabbbdddeee',
|
|
Pierre-Yves Chibon |
f69837 |
)
|
|
Pierre-Yves Chibon |
f69837 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f69837 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
f69837 |
# Create a token for pingou for this project
|
|
Pierre-Yves Chibon |
f69837 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
f69837 |
id='pingou_foo',
|
|
Pierre-Yves Chibon |
f69837 |
user_id=1,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
f69837 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
f69837 |
days=30)
|
|
Pierre-Yves Chibon |
f69837 |
)
|
|
Pierre-Yves Chibon |
f69837 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f69837 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
f69837 |
# Give `change_status_issue` to this token
|
|
Pierre-Yves Chibon |
f69837 |
item = pagure.lib.model.TokenAcl(
|
|
Pierre-Yves Chibon |
f69837 |
token_id='pingou_foo',
|
|
Pierre-Yves Chibon |
e1ff5c |
acl_id=6,
|
|
Pierre-Yves Chibon |
f69837 |
)
|
|
Pierre-Yves Chibon |
f69837 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
f69837 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
f69837 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
218ed6 |
# Create private issue
|
|
Pierre-Yves Chibon |
218ed6 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
218ed6 |
session=self.session,
|
|
Pierre-Yves Chibon |
218ed6 |
repo=repo,
|
|
Pierre-Yves Chibon |
218ed6 |
title='Test issue',
|
|
Pierre-Yves Chibon |
218ed6 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
f69837 |
user='foo',
|
|
Pierre-Yves Chibon |
218ed6 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
218ed6 |
private=True,
|
|
Pierre-Yves Chibon |
218ed6 |
)
|
|
Pierre-Yves Chibon |
218ed6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# Check status before
|
|
Pierre-Yves Chibon |
218ed6 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
218ed6 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(issue.status, 'Open')
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
data = {
|
|
Pierre-Yves Chibon |
218ed6 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
218ed6 |
}
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# Incomplete request
|
|
Pierre-Yves Chibon |
218ed6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
218ed6 |
'/api/0/test/issue/1/status', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
218ed6 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
218ed6 |
data,
|
|
Pierre-Yves Chibon |
218ed6 |
{
|
|
Pierre-Yves Chibon |
218ed6 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
f7fcaa |
"errors": {"status": ["Not a valid choice"]}
|
|
Pierre-Yves Chibon |
218ed6 |
}
|
|
Pierre-Yves Chibon |
218ed6 |
)
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# No change
|
|
Pierre-Yves Chibon |
218ed6 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
218ed6 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(issue.status, 'Open')
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
data = {
|
|
Pierre-Yves Chibon |
218ed6 |
'status': 'Open',
|
|
Pierre-Yves Chibon |
218ed6 |
}
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# Valid request but no change
|
|
Pierre-Yves Chibon |
218ed6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
218ed6 |
'/api/0/test/issue/1/status', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
218ed6 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
218ed6 |
data,
|
|
Mark Reynolds |
eabdc8 |
{'message': 'No changes'}
|
|
Pierre-Yves Chibon |
218ed6 |
)
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# No change
|
|
Pierre-Yves Chibon |
218ed6 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
218ed6 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(issue.status, 'Open')
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
data = {
|
|
Pierre-Yves Chibon |
218ed6 |
'status': 'Fixed',
|
|
Pierre-Yves Chibon |
218ed6 |
}
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
218ed6 |
# Valid request
|
|
Pierre-Yves Chibon |
218ed6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
218ed6 |
'/api/0/test/issue/1/status', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
218ed6 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
218ed6 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
218ed6 |
data,
|
|
Pierre-Yves Chibon |
a18547 |
{'message':[
|
|
Pierre-Yves Chibon |
5b8052 |
'Issue status updated to: Closed (was: Open)',
|
|
Pierre-Yves Chibon |
a18547 |
'Issue close_status updated to: Fixed'
|
|
Pierre-Yves Chibon |
a18547 |
]}
|
|
Pierre-Yves Chibon |
218ed6 |
)
|
|
Pierre-Yves Chibon |
218ed6 |
|
|
Pierre-Yves Chibon |
f69837 |
headers = {'Authorization': 'token pingou_foo'}
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
f69837 |
# Un-authorized issue
|
|
Pierre-Yves Chibon |
f69837 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
f69837 |
'/api/0/foo/issue/1/status', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
ef3813 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
f69837 |
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 |
f69837 |
|
|
Pierre-Yves Chibon |
5aca93 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
5aca93 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
5aca93 |
def test_api_comment_issue(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
fc6bd4 |
""" Test the api_comment_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
5aca93 |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
5aca93 |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
5aca93 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
fc6bd4 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
fc6bd4 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Invalid project
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post('/api/0/foo/issue/1/comment', headers=headers)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
fc6bd4 |
data,
|
|
Pierre-Yves Chibon |
fc6bd4 |
{
|
|
Pierre-Yves Chibon |
fc6bd4 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
fc6bd4 |
}
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post('/api/0/test2/issue/1/comment', headers=headers)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
fc6bd4 |
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 |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# No input
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post('/api/0/test/issue/1/comment', headers=headers)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
fc6bd4 |
data,
|
|
Pierre-Yves Chibon |
fc6bd4 |
{
|
|
Pierre-Yves Chibon |
fc6bd4 |
"error": "Issue not found",
|
|
Pierre-Yves Chibon |
d661a4 |
"error_code": "ENOISSUE",
|
|
Pierre-Yves Chibon |
fc6bd4 |
}
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Create normal issue
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fc6bd4 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
fc6bd4 |
session=self.session,
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo=repo,
|
|
Pierre-Yves Chibon |
fc6bd4 |
title='Test issue #1',
|
|
Pierre-Yves Chibon |
fc6bd4 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
fc6bd4 |
user='pingou',
|
|
Pierre-Yves Chibon |
fc6bd4 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
fc6bd4 |
private=False,
|
|
Pierre-Yves Chibon |
5aca93 |
issue_uid='aaabbbccc#1',
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Check comments before
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fc6bd4 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = {
|
|
Pierre-Yves Chibon |
fc6bd4 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
fc6bd4 |
}
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Incomplete request
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
fc6bd4 |
'/api/0/test/issue/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
fc6bd4 |
data,
|
|
Pierre-Yves Chibon |
fc6bd4 |
{
|
|
Pierre-Yves Chibon |
fc6bd4 |
"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 |
fc6bd4 |
}
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# No change
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fc6bd4 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(issue.status, 'Open')
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = {
|
|
Pierre-Yves Chibon |
fc6bd4 |
'comment': 'This is a very interesting question',
|
|
Pierre-Yves Chibon |
fc6bd4 |
}
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Valid request
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
fc6bd4 |
'/api/0/test/issue/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
fc6bd4 |
data,
|
|
Pierre-Yves Chibon |
fc6bd4 |
{'message': 'Comment added'}
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# One comment added
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
fc6bd4 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(len(issue.comments), 1)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Create another project
|
|
Pierre-Yves Chibon |
fc6bd4 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
fc6bd4 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
fc6bd4 |
name='foo',
|
|
Pierre-Yves Chibon |
fc6bd4 |
description='test project #3',
|
|
Pierre-Yves Chibon |
fc6bd4 |
hook_token='aaabbbdddeee',
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Create a token for pingou for this project
|
|
Pierre-Yves Chibon |
fc6bd4 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
fc6bd4 |
id='pingou_foo',
|
|
Pierre-Yves Chibon |
fc6bd4 |
user_id=1,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
fc6bd4 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
fc6bd4 |
days=30)
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
d2dd03 |
# Give `issue_change_status` to this token when `issue_comment`
|
|
Pierre-Yves Chibon |
d2dd03 |
# is required
|
|
Pierre-Yves Chibon |
fc6bd4 |
item = pagure.lib.model.TokenAcl(
|
|
Pierre-Yves Chibon |
fc6bd4 |
token_id='pingou_foo',
|
|
Pierre-Yves Chibon |
d2dd03 |
acl_id=2,
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Create private issue
|
|
Pierre-Yves Chibon |
fc6bd4 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
fc6bd4 |
session=self.session,
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo=repo,
|
|
Pierre-Yves Chibon |
fc6bd4 |
title='Test issue',
|
|
Pierre-Yves Chibon |
fc6bd4 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
fc6bd4 |
user='foo',
|
|
Pierre-Yves Chibon |
fc6bd4 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
fc6bd4 |
private=True,
|
|
Pierre-Yves Chibon |
5aca93 |
issue_uid='aaabbbccc#2',
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Check before
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
fc6bd4 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
data = {
|
|
Pierre-Yves Chibon |
fc6bd4 |
'comment': 'This is a very interesting question',
|
|
Pierre-Yves Chibon |
fc6bd4 |
}
|
|
Pierre-Yves Chibon |
fc6bd4 |
headers = {'Authorization': 'token pingou_foo'}
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Valid request but un-authorized
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
fc6bd4 |
'/api/0/foo/issue/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
ef3813 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
fc6bd4 |
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 |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# No comment added
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
fc6bd4 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
5711a1 |
# Create token for user foo
|
|
Pierre-Yves Chibon |
5711a1 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
5711a1 |
id='foo_token2',
|
|
Pierre-Yves Chibon |
5711a1 |
user_id=2,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
5711a1 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(days=30)
|
|
Pierre-Yves Chibon |
5711a1 |
)
|
|
Pierre-Yves Chibon |
5711a1 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
5711a1 |
self.session.commit()
|
|
Pierre-Yves Chibon |
5711a1 |
tests.create_tokens_acl(self.session, token_id='foo_token2')
|
|
Pierre-Yves Chibon |
5711a1 |
|
|
Pierre-Yves Chibon |
5711a1 |
data = {
|
|
Pierre-Yves Chibon |
5711a1 |
'comment': 'This is a very interesting question',
|
|
Pierre-Yves Chibon |
5711a1 |
}
|
|
Pierre-Yves Chibon |
5711a1 |
headers = {'Authorization': 'token foo_token2'}
|
|
Pierre-Yves Chibon |
5711a1 |
|
|
Pierre-Yves Chibon |
5711a1 |
# Valid request and authorized
|
|
Pierre-Yves Chibon |
5711a1 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
5711a1 |
'/api/0/foo/issue/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
5711a1 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5711a1 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
5711a1 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
5711a1 |
data,
|
|
Pierre-Yves Chibon |
5711a1 |
{'message': 'Comment added'}
|
|
Pierre-Yves Chibon |
5711a1 |
)
|
|
Pierre-Yves Chibon |
5711a1 |
|
|
Pierre-Yves Chibon |
896cc0 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
896cc0 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
896cc0 |
def test_api_view_issue_comment(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
896cc0 |
""" Test the api_view_issue_comment endpoint. """
|
|
Pierre-Yves Chibon |
896cc0 |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
896cc0 |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
self.test_api_comment_issue()
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# View a comment that does not exist
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/foo/issue/100/comment/2')
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Issue exists but not the comment
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/test/issue/1/comment/2')
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Issue and comment exists
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/test/issue/1/comment/1')
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
896cc0 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
896cc0 |
data['date_created'] = '1435821770'
|
|
Pierre-Yves Chibon |
896cc0 |
data["comment_date"] = "2015-07-02 09:22"
|
|
Pierre-Yves Chibon |
896cc0 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
896cc0 |
data,
|
|
Pierre-Yves Chibon |
896cc0 |
{
|
|
Pierre-Yves Chibon |
896cc0 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
896cc0 |
"comment": "This is a very interesting question",
|
|
Pierre-Yves Chibon |
896cc0 |
"comment_date": "2015-07-02 09:22",
|
|
Pierre-Yves Chibon |
896cc0 |
"date_created": "1435821770",
|
|
Pierre-Yves Chibon |
37b343 |
"edited_on": None,
|
|
Pierre-Yves Chibon |
37b343 |
"editor": None,
|
|
Pierre-Yves Chibon |
bda7f1 |
"notification": False,
|
|
Pierre-Yves Chibon |
896cc0 |
"id": 1,
|
|
Pierre-Yves Chibon |
896cc0 |
"parent": None,
|
|
Pierre-Yves Chibon |
896cc0 |
"user": {
|
|
Pierre-Yves Chibon |
896cc0 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
896cc0 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
896cc0 |
}
|
|
Pierre-Yves Chibon |
896cc0 |
}
|
|
Pierre-Yves Chibon |
896cc0 |
)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Issue and comment exists, using UID
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/test/issue/aaabbbccc#1/comment/1')
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
896cc0 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
896cc0 |
data['date_created'] = '1435821770'
|
|
Pierre-Yves Chibon |
896cc0 |
data["comment_date"] = "2015-07-02 09:22"
|
|
Pierre-Yves Chibon |
896cc0 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
896cc0 |
data,
|
|
Pierre-Yves Chibon |
896cc0 |
{
|
|
Pierre-Yves Chibon |
896cc0 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
896cc0 |
"comment": "This is a very interesting question",
|
|
Pierre-Yves Chibon |
896cc0 |
"comment_date": "2015-07-02 09:22",
|
|
Pierre-Yves Chibon |
896cc0 |
"date_created": "1435821770",
|
|
Pierre-Yves Chibon |
37b343 |
"edited_on": None,
|
|
Pierre-Yves Chibon |
37b343 |
"editor": None,
|
|
Pierre-Yves Chibon |
bda7f1 |
"notification": False,
|
|
Pierre-Yves Chibon |
896cc0 |
"id": 1,
|
|
Pierre-Yves Chibon |
896cc0 |
"parent": None,
|
|
Pierre-Yves Chibon |
896cc0 |
"user": {
|
|
Pierre-Yves Chibon |
896cc0 |
"fullname": "PY C",
|
|
Pierre-Yves Chibon |
896cc0 |
"name": "pingou"
|
|
Pierre-Yves Chibon |
896cc0 |
}
|
|
Pierre-Yves Chibon |
896cc0 |
}
|
|
Pierre-Yves Chibon |
896cc0 |
)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Private issue
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/foo/issue/1/comment/2')
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Private issue - Auth - wrong token
|
|
Pierre-Yves Chibon |
896cc0 |
headers = {'Authorization': 'token pingou_foo'}
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/foo/issue/1/comment/2', headers=headers)
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Private issue - Auth - Invalid token
|
|
Pierre-Yves Chibon |
896cc0 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/foo/issue/1/comment/2', headers=headers)
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Private issue - Auth - valid token - unknown comment
|
|
Pierre-Yves Chibon |
896cc0 |
headers = {'Authorization': 'token foo_token2'}
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/foo/issue/1/comment/3', headers=headers)
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Private issue - Auth - valid token - known comment
|
|
Pierre-Yves Chibon |
896cc0 |
headers = {'Authorization': 'token foo_token2'}
|
|
Pierre-Yves Chibon |
896cc0 |
output = self.app.get('/api/0/foo/issue/1/comment/2', headers=headers)
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
896cc0 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
896cc0 |
data['date_created'] = '1435821770'
|
|
Pierre-Yves Chibon |
896cc0 |
data["comment_date"] = "2015-07-02 09:22"
|
|
Pierre-Yves Chibon |
896cc0 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
896cc0 |
data,
|
|
Pierre-Yves Chibon |
896cc0 |
{
|
|
Pierre-Yves Chibon |
896cc0 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
896cc0 |
"comment": "This is a very interesting question",
|
|
Pierre-Yves Chibon |
896cc0 |
"comment_date": "2015-07-02 09:22",
|
|
Pierre-Yves Chibon |
896cc0 |
"date_created": "1435821770",
|
|
Pierre-Yves Chibon |
37b343 |
"edited_on": None,
|
|
Pierre-Yves Chibon |
37b343 |
"editor": None,
|
|
Pierre-Yves Chibon |
bda7f1 |
"notification": False,
|
|
Pierre-Yves Chibon |
896cc0 |
"id": 2,
|
|
Pierre-Yves Chibon |
896cc0 |
"parent": None,
|
|
Pierre-Yves Chibon |
896cc0 |
"user": {
|
|
Pierre-Yves Chibon |
896cc0 |
"fullname": "foo bar",
|
|
Pierre-Yves Chibon |
896cc0 |
"name": "foo"
|
|
Pierre-Yves Chibon |
896cc0 |
}
|
|
Pierre-Yves Chibon |
896cc0 |
}
|
|
Pierre-Yves Chibon |
896cc0 |
)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
3d10a7 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
3d10a7 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
3d10a7 |
def test_api_assign_issue(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
3d10a7 |
""" Test the api_assign_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
3d10a7 |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
3d10a7 |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
3d10a7 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
3d10a7 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Invalid project
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post('/api/0/foo/issue/1/assign', headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3d10a7 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
3d10a7 |
data,
|
|
Pierre-Yves Chibon |
3d10a7 |
{
|
|
Pierre-Yves Chibon |
3d10a7 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
3d10a7 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
3d10a7 |
}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post('/api/0/test2/issue/1/assign', headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
3d10a7 |
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 |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# No input
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post('/api/0/test/issue/1/assign', headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3d10a7 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
3d10a7 |
data,
|
|
Pierre-Yves Chibon |
3d10a7 |
{
|
|
Pierre-Yves Chibon |
3d10a7 |
"error": "Issue not found",
|
|
Pierre-Yves Chibon |
3d10a7 |
"error_code": "ENOISSUE",
|
|
Pierre-Yves Chibon |
3d10a7 |
}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create normal issue
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
3d10a7 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
3d10a7 |
session=self.session,
|
|
Pierre-Yves Chibon |
3d10a7 |
repo=repo,
|
|
Pierre-Yves Chibon |
3d10a7 |
title='Test issue #1',
|
|
Pierre-Yves Chibon |
3d10a7 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
3d10a7 |
user='pingou',
|
|
Pierre-Yves Chibon |
3d10a7 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
3d10a7 |
private=False,
|
|
Pierre-Yves Chibon |
3d10a7 |
issue_uid='aaabbbccc#1',
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Check comments before
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
3d10a7 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# No change
|
|
Pierre-Yves Chibon |
538c06 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
538c06 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(issue.status, 'Open')
|
|
Pierre-Yves Chibon |
538c06 |
|
|
Pierre-Yves Chibon |
3d10a7 |
data = {
|
|
Pierre-Yves Chibon |
538c06 |
'assignee': 'pingou',
|
|
Pierre-Yves Chibon |
3d10a7 |
}
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# Valid request
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
3d10a7 |
'/api/0/test/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3d10a7 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
3d10a7 |
data,
|
|
Pierre-Yves Chibon |
a18547 |
{'message': 'Issue assigned to pingou'}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# Un-assign
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
538c06 |
'/api/0/test/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
538c06 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
538c06 |
data,
|
|
Mark Reynolds |
eabdc8 |
{'message': 'Assignee reset'}
|
|
Pierre-Yves Chibon |
538c06 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
3d10a7 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(issue.assignee, None)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# Un-assign
|
|
Pierre-Yves Chibon |
538c06 |
data = {'assignee': None}
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
538c06 |
'/api/0/test/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
538c06 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
538c06 |
data,
|
|
Mark Reynolds |
eabdc8 |
{'message': 'Nothing to change'}
|
|
Pierre-Yves Chibon |
538c06 |
)
|
|
Pierre-Yves Chibon |
538c06 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
538c06 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(issue.assignee, None)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# Re-assign for the rest of the tests
|
|
Pierre-Yves Chibon |
538c06 |
data = {'assignee': 'pingou'}
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
538c06 |
'/api/0/test/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
538c06 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
538c06 |
data,
|
|
Pierre-Yves Chibon |
a18547 |
{'message': 'Issue assigned to pingou'}
|
|
Pierre-Yves Chibon |
538c06 |
)
|
|
Pierre-Yves Chibon |
538c06 |
|
|
Pierre-Yves Chibon |
538c06 |
# Un-assign
|
|
Pierre-Yves Chibon |
538c06 |
data = {'assignee': ''}
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
538c06 |
'/api/0/test/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
538c06 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
538c06 |
data,
|
|
Mark Reynolds |
eabdc8 |
{'message': 'Assignee reset'}
|
|
Pierre-Yves Chibon |
538c06 |
)
|
|
Pierre-Yves Chibon |
538c06 |
|
|
Pierre-Yves Chibon |
538c06 |
# Re-assign for the rest of the tests
|
|
Pierre-Yves Chibon |
538c06 |
data = {'assignee': 'pingou'}
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
3d10a7 |
'/api/0/test/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3d10a7 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
3d10a7 |
data,
|
|
Pierre-Yves Chibon |
a18547 |
{'message': 'Issue assigned to pingou'}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# One comment added
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
3d10a7 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(issue.assignee.user, 'pingou')
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create another project
|
|
Pierre-Yves Chibon |
3d10a7 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
3d10a7 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
3d10a7 |
name='foo',
|
|
Pierre-Yves Chibon |
3d10a7 |
description='test project #3',
|
|
Pierre-Yves Chibon |
3d10a7 |
hook_token='aaabbbdddeee',
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create a token for pingou for this project
|
|
Pierre-Yves Chibon |
3d10a7 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
3d10a7 |
id='pingou_foo',
|
|
Pierre-Yves Chibon |
3d10a7 |
user_id=1,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
3d10a7 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(
|
|
Pierre-Yves Chibon |
3d10a7 |
days=30)
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Give `issue_change_status` to this token when `issue_comment`
|
|
Pierre-Yves Chibon |
3d10a7 |
# is required
|
|
Pierre-Yves Chibon |
3d10a7 |
item = pagure.lib.model.TokenAcl(
|
|
Pierre-Yves Chibon |
3d10a7 |
token_id='pingou_foo',
|
|
Pierre-Yves Chibon |
d60504 |
acl_id=5,
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create private issue
|
|
Pierre-Yves Chibon |
3d10a7 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
3d10a7 |
session=self.session,
|
|
Pierre-Yves Chibon |
3d10a7 |
repo=repo,
|
|
Pierre-Yves Chibon |
3d10a7 |
title='Test issue',
|
|
Pierre-Yves Chibon |
3d10a7 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
3d10a7 |
user='foo',
|
|
Pierre-Yves Chibon |
3d10a7 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
3d10a7 |
private=True,
|
|
Pierre-Yves Chibon |
3d10a7 |
issue_uid='aaabbbccc#2',
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(msg.title, 'Test issue')
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Check before
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
3d10a7 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
data = {
|
|
Pierre-Yves Chibon |
3d10a7 |
'assignee': 'pingou',
|
|
Pierre-Yves Chibon |
3d10a7 |
}
|
|
Pierre-Yves Chibon |
3d10a7 |
headers = {'Authorization': 'token pingou_foo'}
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Valid request but un-authorized
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
3d10a7 |
'/api/0/foo/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
3d10a7 |
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 |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# No comment added
|
|
Pierre-Yves Chibon |
3d10a7 |
repo = pagure.lib.get_project(self.session, 'foo')
|
|
Pierre-Yves Chibon |
3d10a7 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create token for user foo
|
|
Pierre-Yves Chibon |
3d10a7 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
3d10a7 |
id='foo_token2',
|
|
Pierre-Yves Chibon |
3d10a7 |
user_id=2,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
3d10a7 |
expiration=datetime.datetime.utcnow() + datetime.timedelta(days=30)
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
tests.create_tokens_acl(self.session, token_id='foo_token2')
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
data = {
|
|
Pierre-Yves Chibon |
3d10a7 |
'assignee': 'pingou',
|
|
Pierre-Yves Chibon |
3d10a7 |
}
|
|
Pierre-Yves Chibon |
3d10a7 |
headers = {'Authorization': 'token foo_token2'}
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Valid request and authorized
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
3d10a7 |
'/api/0/foo/issue/1/assign', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3d10a7 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
3d10a7 |
data,
|
|
Pierre-Yves Chibon |
a18547 |
{'message': 'Issue assigned to pingou'}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
be459f |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
be459f |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
be459f |
def test_api_subscribe_issue(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
be459f |
""" Test the api_subscribe_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
be459f |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
be459f |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
7e0d44 |
item = pagure.lib.model.User(
|
|
Pierre-Yves Chibon |
7e0d44 |
user='bar',
|
|
Pierre-Yves Chibon |
7e0d44 |
fullname='bar foo',
|
|
Pierre-Yves Chibon |
7e0d44 |
password='foo',
|
|
Pierre-Yves Chibon |
7e0d44 |
default_email='bar@bar.com',
|
|
Pierre-Yves Chibon |
7e0d44 |
)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
7e0d44 |
item = pagure.lib.model.UserEmail(
|
|
Pierre-Yves Chibon |
7e0d44 |
user_id=3,
|
|
Pierre-Yves Chibon |
7e0d44 |
email='bar@bar.com')
|
|
Pierre-Yves Chibon |
7e0d44 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
7e0d44 |
|
|
Pierre-Yves Chibon |
7e0d44 |
self.session.commit()
|
|
Pierre-Yves Chibon |
7e0d44 |
|
|
Pierre-Yves Chibon |
be459f |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
7e0d44 |
tests.create_tokens(self.session, user_id=3)
|
|
Pierre-Yves Chibon |
be459f |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Invalid project
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/foo/issue/1/subscribe', headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{
|
|
Pierre-Yves Chibon |
be459f |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
be459f |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
be459f |
}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test2/issue/1/subscribe', headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Pierre-Yves Chibon |
be459f |
data['error_code'])
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# No input
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test/issue/1/subscribe', headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{
|
|
Pierre-Yves Chibon |
be459f |
"error": "Issue not found",
|
|
Pierre-Yves Chibon |
be459f |
"error_code": "ENOISSUE",
|
|
Pierre-Yves Chibon |
be459f |
}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Create normal issue
|
|
Pierre-Yves Chibon |
be459f |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
be459f |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
be459f |
session=self.session,
|
|
Pierre-Yves Chibon |
be459f |
repo=repo,
|
|
Pierre-Yves Chibon |
be459f |
title='Test issue #1',
|
|
Pierre-Yves Chibon |
be459f |
content='We should work on this',
|
|
Pierre-Yves Chibon |
be459f |
user='foo',
|
|
Pierre-Yves Chibon |
be459f |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
be459f |
private=False,
|
|
Pierre-Yves Chibon |
be459f |
issue_uid='aaabbbccc#1',
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
self.session.commit()
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Check subscribtion before
|
|
Pierre-Yves Chibon |
be459f |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
be459f |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
7e0d44 |
pagure.lib.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
7e0d44 |
set(['pingou', 'foo']))
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Unsubscribe - no changes
|
|
Pierre-Yves Chibon |
be459f |
data = {}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test/issue/1/subscribe', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{'message': 'You are no longer watching this issue'}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
data = {}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test/issue/1/subscribe', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{'message': 'You are no longer watching this issue'}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# No change
|
|
Pierre-Yves Chibon |
be459f |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
be459f |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
7e0d44 |
pagure.lib.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
7e0d44 |
set(['pingou', 'foo']))
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Subscribe
|
|
Pierre-Yves Chibon |
be459f |
data = {'status': True}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test/issue/1/subscribe', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{'message': 'You are now watching this issue'}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Subscribe - no changes
|
|
Pierre-Yves Chibon |
be459f |
data = {'status': True}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test/issue/1/subscribe', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{'message': 'You are now watching this issue'}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
be459f |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
7e0d44 |
pagure.lib.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
7e0d44 |
set(['pingou', 'foo', 'bar']))
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Unsubscribe
|
|
Pierre-Yves Chibon |
be459f |
data = {}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
be459f |
'/api/0/test/issue/1/subscribe', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
be459f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
be459f |
{'message': 'You are no longer watching this issue'}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
be459f |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
7e0d44 |
pagure.lib.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
7e0d44 |
set(['pingou', 'foo']))
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
7bbefe |
def test_api_update_custom_field(self):
|
|
Pierre-Yves Chibon |
7bbefe |
""" Test the api_update_custom_field method of the flask api. """
|
|
Pierre-Yves Chibon |
7bbefe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
7bbefe |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
7bbefe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
7bbefe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Invalid project
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/foo/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
7bbefe |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
7bbefe |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test2/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Pierre-Yves Chibon |
7bbefe |
data['error_code'])
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# No issue
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
7bbefe |
"error": "Issue not found",
|
|
Pierre-Yves Chibon |
7bbefe |
"error_code": "ENOISSUE",
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Create normal issue
|
|
Pierre-Yves Chibon |
7bbefe |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
7bbefe |
session=self.session,
|
|
Pierre-Yves Chibon |
7bbefe |
repo=repo,
|
|
Pierre-Yves Chibon |
7bbefe |
title='Test issue #1',
|
|
Pierre-Yves Chibon |
7bbefe |
content='We should work on this',
|
|
Pierre-Yves Chibon |
7bbefe |
user='pingou',
|
|
Pierre-Yves Chibon |
7bbefe |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
7bbefe |
private=False,
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.commit()
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Project does not have this custom field
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
7bbefe |
"error": "Invalid custom field submitted",
|
|
Pierre-Yves Chibon |
7bbefe |
"error_code": "EINVALIDISSUEFIELD",
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Check the behavior if the project disabled the issue tracker
|
|
Pierre-Yves Chibon |
7bbefe |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
settings = repo.settings
|
|
Pierre-Yves Chibon |
7bbefe |
settings['issue_tracker'] = False
|
|
Pierre-Yves Chibon |
7bbefe |
repo.settings = settings
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.commit()
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
7bbefe |
"error": "Issue tracker disabled for this project",
|
|
Pierre-Yves Chibon |
7bbefe |
"error_code": "ETRACKERDISABLED",
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
settings = repo.settings
|
|
Pierre-Yves Chibon |
7bbefe |
settings['issue_tracker'] = True
|
|
Pierre-Yves Chibon |
7bbefe |
repo.settings = settings
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.commit()
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Invalid API token
|
|
Pierre-Yves Chibon |
7bbefe |
headers = {'Authorization': 'token foobar'}
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 401)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
7bbefe |
"error": "Invalid or expired token. Please visit "
|
|
Pierre-Yves Chibon |
7bbefe |
"https://pagure.org/ to get or renew your API token.",
|
|
Pierre-Yves Chibon |
7bbefe |
"error_code": "EINVALIDTOK",
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Set some custom fields
|
|
Pierre-Yves Chibon |
7bbefe |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
msg = pagure.lib.set_custom_key_fields(
|
|
Pierre-Yves Chibon |
7bbefe |
self.session, repo,
|
|
Mark Reynolds |
e18f6c |
['bugzilla', 'upstream', 'reviewstatus'],
|
|
Mark Reynolds |
e18f6c |
['link', 'boolean', 'list'],
|
|
Mark Reynolds |
b47c03 |
['unused data for non-list type', '', 'ack, nack , needs review'])
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.commit()
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(msg, 'List of custom fields updated')
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Mark Reynolds |
e18f6c |
# Check the project custom fields were correctly set
|
|
Mark Reynolds |
e18f6c |
for key in repo.issue_keys:
|
|
Mark Reynolds |
e18f6c |
# Check that the bugzilla field correctly had its data removed
|
|
Mark Reynolds |
6fac0c |
if key.name == "bugzilla":
|
|
Pierre-Yves Chibon |
16b189 |
self.assertIsNone(key.data)
|
|
Mark Reynolds |
75e6d9 |
|
|
Mark Reynolds |
e18f6c |
# Check that the reviewstatus list field still has its list
|
|
Mark Reynolds |
411167 |
if key.name == "reviewstatus":
|
|
Pierre-Yves Chibon |
ff0ba2 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ff0ba2 |
sorted(key.data), ['ack', 'nack', 'needs review'])
|
|
Mark Reynolds |
e18f6c |
|
|
Pierre-Yves Chibon |
16b189 |
# Check that not setting the value on a non-existing custom field
|
|
Pierre-Yves Chibon |
16b189 |
# changes nothing
|
|
Pierre-Yves Chibon |
16b189 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
16b189 |
'/api/0/test/issue/1/custom/bugzilla', headers=headers)
|
|
Pierre-Yves Chibon |
16b189 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
16b189 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
16b189 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
16b189 |
data,
|
|
Pierre-Yves Chibon |
16b189 |
{
|
|
Pierre-Yves Chibon |
16b189 |
'message': 'No changes'
|
|
Pierre-Yves Chibon |
16b189 |
}
|
|
Pierre-Yves Chibon |
16b189 |
)
|
|
Pierre-Yves Chibon |
16b189 |
|
|
Pierre-Yves Chibon |
16b189 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
16b189 |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
16b189 |
self.assertEqual(issue.other_fields, [])
|
|
Pierre-Yves Chibon |
16b189 |
self.assertEqual(len(issue.other_fields), 0)
|
|
Pierre-Yves Chibon |
16b189 |
|
|
Pierre-Yves Chibon |
7bbefe |
# Invalid value
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test/issue/1/custom/bugzilla', headers=headers,
|
|
Pierre-Yves Chibon |
7bbefe |
data={'value': 'foobar'})
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
7bbefe |
"error": "Invalid custom field submitted, the value is not "
|
|
Pierre-Yves Chibon |
7bbefe |
"a link",
|
|
Pierre-Yves Chibon |
7bbefe |
"error_code": "EINVALIDISSUEFIELD_LINK",
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
59b171 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(issue.other_fields, [])
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(len(issue.other_fields), 0)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# All good
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
7bbefe |
'/api/0/test/issue/1/custom/bugzilla', headers=headers,
|
|
Pierre-Yves Chibon |
7bbefe |
data={'value': 'https://bugzilla.redhat.com/1234'})
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
a18547 |
"message": "Custom field bugzilla adjusted to "
|
|
Pierre-Yves Chibon |
a18547 |
"https://bugzilla.redhat.com/1234"
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
59b171 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(len(issue.other_fields), 1)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(issue.other_fields[0].key.name, 'bugzilla')
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
issue.other_fields[0].value,
|
|
Pierre-Yves Chibon |
7bbefe |
'https://bugzilla.redhat.com/1234')
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Reset the value
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Mark Reynolds |
241908 |
'/api/0/test/issue/1/custom/bugzilla', headers=headers,
|
|
Mark Reynolds |
241908 |
data={'value': ''})
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
7bbefe |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
a18547 |
"message": "Custom field bugzilla reset"
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
59b171 |
repo = pagure.lib.get_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
7bbefe |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
5b8052 |
self.assertEqual(len(issue.other_fields), 0)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
if __name__ == '__main__':
|
|
Pierre-Yves Chibon |
993597 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
993597 |
PagureFlaskApiIssuetests)
|
|
Pierre-Yves Chibon |
993597 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|