|
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 |
bceef0 |
import copy
|
|
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 |
efe4a8 |
import time
|
|
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 |
|
|
Farhaan Bukhsh |
72e9db |
import pagure
|
|
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 |
bceef0 |
LCL_ISSUES = [
|
|
Pierre-Yves Chibon |
bceef0 |
{
|
|
Pierre-Yves Chibon |
bceef0 |
'assignee': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'blocks': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'close_status': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'closed_at': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'comments': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'content': 'Description',
|
|
Pierre-Yves Chibon |
bceef0 |
'custom_fields': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'date_created': '1431414800',
|
|
Pierre-Yves Chibon |
bceef0 |
'depends': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'id': 2,
|
|
Pierre-Yves Chibon |
bceef0 |
'last_updated': '1431414800',
|
|
Pierre-Yves Chibon |
bceef0 |
'milestone': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'priority': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'private': False,
|
|
Pierre-Yves Chibon |
bceef0 |
'status': 'Open',
|
|
Pierre-Yves Chibon |
bceef0 |
'tags': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'title': 'Issue #2',
|
|
Pierre-Yves Chibon |
bceef0 |
'user': {'fullname': 'PY C', 'name': 'pingou'}
|
|
Pierre-Yves Chibon |
bceef0 |
},
|
|
Pierre-Yves Chibon |
bceef0 |
{
|
|
Pierre-Yves Chibon |
bceef0 |
'assignee': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'blocks': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'close_status': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'closed_at': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'comments': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'content': 'Description',
|
|
Pierre-Yves Chibon |
bceef0 |
'custom_fields': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'date_created': '1431414800',
|
|
Pierre-Yves Chibon |
bceef0 |
'depends': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'id': 1,
|
|
Pierre-Yves Chibon |
bceef0 |
'last_updated': '1431414800',
|
|
Pierre-Yves Chibon |
bceef0 |
'milestone': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'priority': None,
|
|
Pierre-Yves Chibon |
bceef0 |
'private': False,
|
|
Pierre-Yves Chibon |
bceef0 |
'status': 'Open',
|
|
Pierre-Yves Chibon |
bceef0 |
'tags': [],
|
|
Pierre-Yves Chibon |
bceef0 |
'title': 'Issue #1',
|
|
Pierre-Yves Chibon |
bceef0 |
'user': {'fullname': 'PY C', 'name': 'pingou'}
|
|
Pierre-Yves Chibon |
bceef0 |
}
|
|
Pierre-Yves Chibon |
bceef0 |
]
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
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 |
|
|
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 |
0c6a50 |
exp = FULL_ISSUE_LIST[1]
|
|
Pierre-Yves Chibon |
0c6a50 |
exp['id'] = 8
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
0c6a50 |
"issue": exp,
|
|
Pierre-Yves Chibon |
9a9e42 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
1dfd94 |
def test_api_new_issue_user_token(self):
|
|
Pierre-Yves Chibon |
1dfd94 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
1dfd94 |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
1dfd94 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid token, invalid request - No input
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post('/api/0/test2/new_issue', headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
1dfd94 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Another project, still an invalid request - No input
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post('/api/0/test/new_issue', headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
1dfd94 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue'
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Invalid repo
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/foo/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Project not found",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "ENOPROJECT",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Incomplete request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"error": "Invalid or incomplete input submited",
|
|
Pierre-Yves Chibon |
1dfd94 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
1dfd94 |
"errors": {
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
1dfd94 |
"title": ["This field is required."]
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Farhaan Bukhsh |
8267d1 |
|
|
Farhaan Bukhsh |
8267d1 |
# Valid request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[8],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request with milestone
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'milestone': ['milestone-1.0'],
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[7],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request, with private='false'
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'private': 'false',
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[6],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request, with private=False
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'private': False
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[5],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request, with private='False'
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'private': 'False'
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[4],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request, with private=0
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'private': 0
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[3],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Private issue: True
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'private': True,
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[2],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Private issue: 1
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
1dfd94 |
'title': 'test issue1',
|
|
Pierre-Yves Chibon |
1dfd94 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
1dfd94 |
'private': 1,
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
1dfd94 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
1dfd94 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
1dfd94 |
"issue": FULL_ISSUE_LIST[1],
|
|
Pierre-Yves Chibon |
1dfd94 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
0c6a50 |
# Private issue: 'true'
|
|
Pierre-Yves Chibon |
0c6a50 |
data = {
|
|
Pierre-Yves Chibon |
0c6a50 |
'title': 'test issue1',
|
|
Pierre-Yves Chibon |
0c6a50 |
'issue_content': 'This issue needs attention',
|
|
Pierre-Yves Chibon |
0c6a50 |
'private': 'true',
|
|
Pierre-Yves Chibon |
0c6a50 |
}
|
|
Pierre-Yves Chibon |
0c6a50 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
0c6a50 |
'/api/0/test/new_issue', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
0c6a50 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0c6a50 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
0c6a50 |
data['issue']['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
0c6a50 |
data['issue']['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
0c6a50 |
exp = FULL_ISSUE_LIST[1]
|
|
Pierre-Yves Chibon |
0c6a50 |
exp['id'] = 9
|
|
Pierre-Yves Chibon |
0c6a50 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
0c6a50 |
data,
|
|
Pierre-Yves Chibon |
0c6a50 |
{
|
|
Pierre-Yves Chibon |
0c6a50 |
"issue": exp,
|
|
Pierre-Yves Chibon |
0c6a50 |
"message": "Issue created"
|
|
Pierre-Yves Chibon |
0c6a50 |
}
|
|
Pierre-Yves Chibon |
0c6a50 |
)
|
|
Pierre-Yves Chibon |
0c6a50 |
|
|
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,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Mark Reynolds |
23b4d2 |
"since": None,
|
|
Pierre-Yves Chibon |
9a9e42 |
"status": None,
|
|
Pierre-Yves Chibon |
ca5286 |
"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
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_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,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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 |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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 |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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 |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 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 |
bceef0 |
def test_api_view_issues_milestone(self):
|
|
Pierre-Yves Chibon |
bceef0 |
""" Test the api_view_issues method of the flask api when filtering
|
|
Pierre-Yves Chibon |
bceef0 |
for a milestone.
|
|
Pierre-Yves Chibon |
bceef0 |
"""
|
|
Pierre-Yves Chibon |
bceef0 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
bceef0 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
bceef0 |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
bceef0 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
bceef0 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
# Create 2 tickets but only 1 has a milestone
|
|
Pierre-Yves Chibon |
bceef0 |
start = datetime.datetime.utcnow().strftime('%s')
|
|
Pierre-Yves Chibon |
bceef0 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
bceef0 |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
bceef0 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
bceef0 |
title='Issue #1',
|
|
Pierre-Yves Chibon |
bceef0 |
content='Description',
|
|
Pierre-Yves Chibon |
bceef0 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
bceef0 |
uid='issue#1',
|
|
Pierre-Yves Chibon |
bceef0 |
private=False,
|
|
Pierre-Yves Chibon |
bceef0 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
bceef0 |
self.session.commit()
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
bceef0 |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
bceef0 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
bceef0 |
title='Issue #2',
|
|
Pierre-Yves Chibon |
bceef0 |
content='Description',
|
|
Pierre-Yves Chibon |
bceef0 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
bceef0 |
uid='issue#2',
|
|
Pierre-Yves Chibon |
bceef0 |
private=False,
|
|
Pierre-Yves Chibon |
bceef0 |
milestone='v1.0',
|
|
Pierre-Yves Chibon |
bceef0 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
bceef0 |
self.session.commit()
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
# List all opened issues
|
|
Pierre-Yves Chibon |
bceef0 |
output = self.app.get('/api/0/test/issues')
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
bceef0 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
bceef0 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
bceef0 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
bceef0 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
bceef0 |
lcl_issues = copy.deepcopy(LCL_ISSUES)
|
|
Pierre-Yves Chibon |
bceef0 |
lcl_issues[0]['milestone'] = 'v1.0'
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
bceef0 |
data,
|
|
Pierre-Yves Chibon |
bceef0 |
{
|
|
Pierre-Yves Chibon |
bceef0 |
"args": {
|
|
Pierre-Yves Chibon |
bceef0 |
"assignee": None,
|
|
Pierre-Yves Chibon |
bceef0 |
"author": None,
|
|
Pierre-Yves Chibon |
bceef0 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
bceef0 |
"since": None,
|
|
Pierre-Yves Chibon |
bceef0 |
"status": None,
|
|
Pierre-Yves Chibon |
bceef0 |
"tags": [],
|
|
Pierre-Yves Chibon |
bceef0 |
},
|
|
Pierre-Yves Chibon |
bceef0 |
"issues": lcl_issues,
|
|
Pierre-Yves Chibon |
bceef0 |
"total_issues": 2
|
|
Pierre-Yves Chibon |
bceef0 |
}
|
|
Pierre-Yves Chibon |
bceef0 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
# List all issues of the milestone v1.0
|
|
Pierre-Yves Chibon |
bceef0 |
output = self.app.get('/api/0/test/issues?milestones=v1.0')
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
bceef0 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
bceef0 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
bceef0 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
bceef0 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
bceef0 |
data,
|
|
Pierre-Yves Chibon |
bceef0 |
{
|
|
Pierre-Yves Chibon |
bceef0 |
"args": {
|
|
Pierre-Yves Chibon |
bceef0 |
"assignee": None,
|
|
Pierre-Yves Chibon |
bceef0 |
"author": None,
|
|
Pierre-Yves Chibon |
bceef0 |
'milestones': ['v1.0'],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
e34a6f |
"since": None,
|
|
Pierre-Yves Chibon |
e34a6f |
"status": None,
|
|
Pierre-Yves Chibon |
e34a6f |
"tags": [],
|
|
Pierre-Yves Chibon |
e34a6f |
},
|
|
Pierre-Yves Chibon |
e34a6f |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
e34a6f |
"total_issues": 1
|
|
Pierre-Yves Chibon |
e34a6f |
}
|
|
Pierre-Yves Chibon |
e34a6f |
)
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
e34a6f |
def test_api_view_issues_priority(self):
|
|
Pierre-Yves Chibon |
e34a6f |
""" Test the api_view_issues method of the flask api when filtering
|
|
Pierre-Yves Chibon |
e34a6f |
for a priority.
|
|
Pierre-Yves Chibon |
e34a6f |
"""
|
|
Pierre-Yves Chibon |
e34a6f |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
e34a6f |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
e34a6f |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
e34a6f |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
e34a6f |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
e34a6f |
# Create 2 tickets but only 1 has a priority
|
|
Pierre-Yves Chibon |
e34a6f |
start = datetime.datetime.utcnow().strftime('%s')
|
|
Pierre-Yves Chibon |
e34a6f |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
e34a6f |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
e34a6f |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
e34a6f |
title='Issue #1',
|
|
Pierre-Yves Chibon |
e34a6f |
content='Description',
|
|
Pierre-Yves Chibon |
e34a6f |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
e34a6f |
uid='issue#1',
|
|
Pierre-Yves Chibon |
e34a6f |
private=False,
|
|
Pierre-Yves Chibon |
e34a6f |
)
|
|
Pierre-Yves Chibon |
e34a6f |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
e34a6f |
self.session.commit()
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
e34a6f |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
e34a6f |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
e34a6f |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
e34a6f |
title='Issue #2',
|
|
Pierre-Yves Chibon |
e34a6f |
content='Description',
|
|
Pierre-Yves Chibon |
e34a6f |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
e34a6f |
uid='issue#2',
|
|
Pierre-Yves Chibon |
e34a6f |
private=False,
|
|
Pierre-Yves Chibon |
5e4fd1 |
priority=1,
|
|
Pierre-Yves Chibon |
e34a6f |
)
|
|
Pierre-Yves Chibon |
e34a6f |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
e34a6f |
self.session.commit()
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
f07509 |
# Set some priorities to the project
|
|
Pierre-Yves Chibon |
f07509 |
repo.priorities = {'1': 'High', '2': 'Normal'}
|
|
Pierre-Yves Chibon |
f07509 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
f07509 |
self.session.commit()
|
|
Pierre-Yves Chibon |
f07509 |
|
|
Pierre-Yves Chibon |
e34a6f |
# List all opened issues
|
|
Pierre-Yves Chibon |
e34a6f |
output = self.app.get('/api/0/test/issues')
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e34a6f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e34a6f |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
e34a6f |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
e34a6f |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
e34a6f |
lcl_issues = copy.deepcopy(LCL_ISSUES)
|
|
Pierre-Yves Chibon |
f07509 |
lcl_issues[0]['priority'] = 1
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e34a6f |
data,
|
|
Pierre-Yves Chibon |
e34a6f |
{
|
|
Pierre-Yves Chibon |
e34a6f |
"args": {
|
|
Pierre-Yves Chibon |
e34a6f |
"assignee": None,
|
|
Pierre-Yves Chibon |
e34a6f |
"author": None,
|
|
Pierre-Yves Chibon |
e34a6f |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
e34a6f |
"since": None,
|
|
Pierre-Yves Chibon |
e34a6f |
"status": None,
|
|
Pierre-Yves Chibon |
e34a6f |
"tags": [],
|
|
Pierre-Yves Chibon |
e34a6f |
},
|
|
Pierre-Yves Chibon |
e34a6f |
"issues": lcl_issues,
|
|
Pierre-Yves Chibon |
e34a6f |
"total_issues": 2
|
|
Pierre-Yves Chibon |
e34a6f |
}
|
|
Pierre-Yves Chibon |
e34a6f |
)
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
f07509 |
# List all issues of the priority high (ie: 1)
|
|
Pierre-Yves Chibon |
f07509 |
output = self.app.get('/api/0/test/issues?priority=high')
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
e34a6f |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
e34a6f |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
e34a6f |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
e34a6f |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e34a6f |
data,
|
|
Pierre-Yves Chibon |
e34a6f |
{
|
|
Pierre-Yves Chibon |
e34a6f |
"args": {
|
|
Pierre-Yves Chibon |
e34a6f |
"assignee": None,
|
|
Pierre-Yves Chibon |
e34a6f |
"author": None,
|
|
Pierre-Yves Chibon |
e34a6f |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': 'high',
|
|
Pierre-Yves Chibon |
bceef0 |
"since": None,
|
|
Pierre-Yves Chibon |
bceef0 |
"status": None,
|
|
Pierre-Yves Chibon |
bceef0 |
"tags": [],
|
|
Pierre-Yves Chibon |
bceef0 |
},
|
|
Pierre-Yves Chibon |
bceef0 |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
bceef0 |
"total_issues": 1
|
|
Pierre-Yves Chibon |
bceef0 |
}
|
|
Pierre-Yves Chibon |
bceef0 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
f07509 |
output = self.app.get('/api/0/test/issues?priority=1')
|
|
Pierre-Yves Chibon |
f07509 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
f07509 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f07509 |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
f07509 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
f07509 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
f07509 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f07509 |
data,
|
|
Pierre-Yves Chibon |
f07509 |
{
|
|
Pierre-Yves Chibon |
f07509 |
"args": {
|
|
Pierre-Yves Chibon |
f07509 |
"assignee": None,
|
|
Pierre-Yves Chibon |
f07509 |
"author": None,
|
|
Pierre-Yves Chibon |
f07509 |
'milestones': [],
|
|
Pierre-Yves Chibon |
f07509 |
'no_stones': None,
|
|
Pierre-Yves Chibon |
f07509 |
'priority': '1',
|
|
Pierre-Yves Chibon |
f07509 |
"since": None,
|
|
Pierre-Yves Chibon |
f07509 |
"status": None,
|
|
Pierre-Yves Chibon |
f07509 |
"tags": [],
|
|
Pierre-Yves Chibon |
f07509 |
},
|
|
Pierre-Yves Chibon |
f07509 |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
f07509 |
"total_issues": 1
|
|
Pierre-Yves Chibon |
f07509 |
}
|
|
Pierre-Yves Chibon |
f07509 |
)
|
|
Pierre-Yves Chibon |
f07509 |
|
|
Pierre-Yves Chibon |
c2250f |
def test_api_view_issues_priority_invalid(self):
|
|
Pierre-Yves Chibon |
c2250f |
""" Test the api_view_issues method of the flask api when filtering
|
|
Pierre-Yves Chibon |
c2250f |
for an invalid priority.
|
|
Pierre-Yves Chibon |
c2250f |
"""
|
|
Pierre-Yves Chibon |
c2250f |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
c2250f |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
c2250f |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
c2250f |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
c2250f |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
c2250f |
|
|
Pierre-Yves Chibon |
f07509 |
# Try getting issues with an invalid priority
|
|
Pierre-Yves Chibon |
f07509 |
output = self.app.get('/api/0/test/issues?priority=foobar')
|
|
Pierre-Yves Chibon |
f07509 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
f07509 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
f07509 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f07509 |
data,
|
|
Pierre-Yves Chibon |
f07509 |
{
|
|
Pierre-Yves Chibon |
f07509 |
"error": "Invalid priority submitted",
|
|
Pierre-Yves Chibon |
f07509 |
"error_code": "EINVALIDPRIORITY"
|
|
Pierre-Yves Chibon |
f07509 |
}
|
|
Pierre-Yves Chibon |
f07509 |
)
|
|
Pierre-Yves Chibon |
f07509 |
|
|
Pierre-Yves Chibon |
eb3bbc |
def test_api_view_issues_no_stones(self):
|
|
Pierre-Yves Chibon |
eb3bbc |
""" Test the api_view_issues method of the flask api when filtering
|
|
Pierre-Yves Chibon |
eb3bbc |
with no_stones.
|
|
Pierre-Yves Chibon |
eb3bbc |
"""
|
|
Pierre-Yves Chibon |
eb3bbc |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
eb3bbc |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
eb3bbc |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
eb3bbc |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
eb3bbc |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# Create 2 tickets but only 1 has a milestone
|
|
Pierre-Yves Chibon |
eb3bbc |
start = datetime.datetime.utcnow().strftime('%s')
|
|
Pierre-Yves Chibon |
eb3bbc |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
eb3bbc |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
eb3bbc |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
eb3bbc |
title='Issue #1',
|
|
Pierre-Yves Chibon |
eb3bbc |
content='Description',
|
|
Pierre-Yves Chibon |
eb3bbc |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
eb3bbc |
uid='issue#1',
|
|
Pierre-Yves Chibon |
eb3bbc |
private=False,
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
eb3bbc |
self.session.commit()
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
eb3bbc |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
eb3bbc |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
eb3bbc |
title='Issue #2',
|
|
Pierre-Yves Chibon |
eb3bbc |
content='Description',
|
|
Pierre-Yves Chibon |
eb3bbc |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
eb3bbc |
uid='issue#2',
|
|
Pierre-Yves Chibon |
eb3bbc |
private=False,
|
|
Pierre-Yves Chibon |
eb3bbc |
milestone='v1.0',
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
eb3bbc |
self.session.commit()
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# List all opened issues
|
|
Pierre-Yves Chibon |
eb3bbc |
output = self.app.get('/api/0/test/issues')
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eb3bbc |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
eb3bbc |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
eb3bbc |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
eb3bbc |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
eb3bbc |
lcl_issues = copy.deepcopy(LCL_ISSUES)
|
|
Pierre-Yves Chibon |
eb3bbc |
lcl_issues[0]['milestone'] = 'v1.0'
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
eb3bbc |
data,
|
|
Pierre-Yves Chibon |
eb3bbc |
{
|
|
Pierre-Yves Chibon |
eb3bbc |
"args": {
|
|
Pierre-Yves Chibon |
eb3bbc |
"assignee": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"author": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
eb3bbc |
'priority': None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"since": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"status": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"tags": [],
|
|
Pierre-Yves Chibon |
eb3bbc |
},
|
|
Pierre-Yves Chibon |
eb3bbc |
"issues": lcl_issues,
|
|
Pierre-Yves Chibon |
eb3bbc |
"total_issues": 2
|
|
Pierre-Yves Chibon |
eb3bbc |
}
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# List all issues with no milestone
|
|
Pierre-Yves Chibon |
eb3bbc |
output = self.app.get('/api/0/test/issues?no_stones=1')
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eb3bbc |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
eb3bbc |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
eb3bbc |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
eb3bbc |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
eb3bbc |
data,
|
|
Pierre-Yves Chibon |
eb3bbc |
{
|
|
Pierre-Yves Chibon |
eb3bbc |
"args": {
|
|
Pierre-Yves Chibon |
eb3bbc |
"assignee": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"author": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': True,
|
|
Pierre-Yves Chibon |
eb3bbc |
'priority': None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"since": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"status": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"tags": [],
|
|
Pierre-Yves Chibon |
eb3bbc |
},
|
|
Pierre-Yves Chibon |
eb3bbc |
"issues": [lcl_issues[1]],
|
|
Pierre-Yves Chibon |
eb3bbc |
"total_issues": 1
|
|
Pierre-Yves Chibon |
eb3bbc |
}
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# List all issues with a milestone
|
|
Pierre-Yves Chibon |
eb3bbc |
output = self.app.get('/api/0/test/issues?no_stones=0')
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
eb3bbc |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
eb3bbc |
for idx in range(len(data['issues'])):
|
|
Pierre-Yves Chibon |
eb3bbc |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
eb3bbc |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
eb3bbc |
data,
|
|
Pierre-Yves Chibon |
eb3bbc |
{
|
|
Pierre-Yves Chibon |
eb3bbc |
"args": {
|
|
Pierre-Yves Chibon |
eb3bbc |
"assignee": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"author": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': False,
|
|
Pierre-Yves Chibon |
eb3bbc |
'priority': None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"since": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"status": None,
|
|
Pierre-Yves Chibon |
eb3bbc |
"tags": [],
|
|
Pierre-Yves Chibon |
eb3bbc |
},
|
|
Pierre-Yves Chibon |
eb3bbc |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
eb3bbc |
"total_issues": 1
|
|
Pierre-Yves Chibon |
eb3bbc |
}
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Vivek Anand |
f0e3cc |
def test_api_view_issues_since(self):
|
|
Vivek Anand |
f0e3cc |
""" Test the api_view_issues method of the flask api for since option """
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
3dd389 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
3dd389 |
os.path.join(self.path, 'tickets'), bare=True)
|
|
Pierre-Yves Chibon |
3dd389 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
3dd389 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Create 1st tickets
|
|
Pierre-Yves Chibon |
efe4a8 |
start = datetime.datetime.utcnow().strftime('%s')
|
|
Pierre-Yves Chibon |
3dd389 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
3dd389 |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
3dd389 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
3dd389 |
title='Issue #1',
|
|
Pierre-Yves Chibon |
3dd389 |
content='Description',
|
|
Pierre-Yves Chibon |
3dd389 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
3dd389 |
uid='issue#1',
|
|
Pierre-Yves Chibon |
3dd389 |
private=False,
|
|
Pierre-Yves Chibon |
3dd389 |
)
|
|
Pierre-Yves Chibon |
3dd389 |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
3dd389 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
time.sleep(1)
|
|
Pierre-Yves Chibon |
3dd389 |
middle = datetime.datetime.utcnow().strftime('%s')
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Create 2nd tickets
|
|
Pierre-Yves Chibon |
3dd389 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
3dd389 |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
3dd389 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
3dd389 |
title='Issue #2',
|
|
Pierre-Yves Chibon |
3dd389 |
content='Description',
|
|
Pierre-Yves Chibon |
3dd389 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
3dd389 |
uid='issue#2',
|
|
Pierre-Yves Chibon |
3dd389 |
private=False,
|
|
Pierre-Yves Chibon |
3dd389 |
)
|
|
Pierre-Yves Chibon |
3dd389 |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
3dd389 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
time.sleep(1)
|
|
Pierre-Yves Chibon |
3dd389 |
final = datetime.datetime.utcnow().strftime('%s')
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Create private issue
|
|
Pierre-Yves Chibon |
3dd389 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
3dd389 |
id=pagure.lib.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
3dd389 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
3dd389 |
title='Issue #3',
|
|
Pierre-Yves Chibon |
3dd389 |
content='Description',
|
|
Pierre-Yves Chibon |
3dd389 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
3dd389 |
uid='issue#3',
|
|
Pierre-Yves Chibon |
3dd389 |
private=True,
|
|
Pierre-Yves Chibon |
3dd389 |
)
|
|
Pierre-Yves Chibon |
3dd389 |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
3dd389 |
self.session.commit()
|
|
Vivek Anand |
f0e3cc |
|
|
Vivek Anand |
f0e3cc |
# Invalid repo
|
|
Vivek Anand |
f0e3cc |
output = self.app.get('/api/0/foo/issues')
|
|
Vivek Anand |
f0e3cc |
self.assertEqual(output.status_code, 404)
|
|
Vivek Anand |
f0e3cc |
data = json.loads(output.data)
|
|
Vivek Anand |
f0e3cc |
self.assertDictEqual(
|
|
Vivek Anand |
f0e3cc |
data,
|
|
Vivek Anand |
f0e3cc |
{
|
|
Vivek Anand |
f0e3cc |
"error": "Project not found",
|
|
Vivek Anand |
f0e3cc |
"error_code": "ENOPROJECT",
|
|
Vivek Anand |
f0e3cc |
}
|
|
Vivek Anand |
f0e3cc |
)
|
|
Vivek Anand |
f0e3cc |
|
|
Vivek Anand |
f0e3cc |
# List all opened issues
|
|
Vivek Anand |
f0e3cc |
output = self.app.get('/api/0/test/issues')
|
|
Vivek Anand |
f0e3cc |
self.assertEqual(output.status_code, 200)
|
|
Vivek Anand |
f0e3cc |
data = json.loads(output.data)
|
|
Vivek Anand |
f0e3cc |
for idx in range(len(data['issues'])):
|
|
Vivek Anand |
f0e3cc |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Vivek Anand |
f0e3cc |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Vivek Anand |
f0e3cc |
self.assertDictEqual(
|
|
Vivek Anand |
f0e3cc |
data,
|
|
Vivek Anand |
f0e3cc |
{
|
|
Vivek Anand |
f0e3cc |
"args": {
|
|
Vivek Anand |
f0e3cc |
"assignee": None,
|
|
Vivek Anand |
f0e3cc |
"author": None,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Vivek Anand |
f0e3cc |
"since": None,
|
|
Vivek Anand |
f0e3cc |
"status": None,
|
|
Vivek Anand |
f0e3cc |
"tags": []
|
|
Vivek Anand |
f0e3cc |
},
|
|
Pierre-Yves Chibon |
3dd389 |
"issues": LCL_ISSUES,
|
|
Pierre-Yves Chibon |
3dd389 |
"total_issues": 2
|
|
Vivek Anand |
f0e3cc |
}
|
|
Vivek Anand |
f0e3cc |
)
|
|
Vivek Anand |
f0e3cc |
|
|
Pierre-Yves Chibon |
efe4a8 |
time.sleep(1)
|
|
Pierre-Yves Chibon |
3dd389 |
late = datetime.datetime.utcnow().strftime('%s')
|
|
Vivek Anand |
f0e3cc |
|
|
Pierre-Yves Chibon |
3dd389 |
# List all opened issues from the start
|
|
Pierre-Yves Chibon |
3dd389 |
output = self.app.get('/api/0/test/issues?since=%s' % start)
|
|
Vivek Anand |
bb317c |
self.assertEqual(output.status_code, 200)
|
|
Vivek Anand |
bb317c |
data = json.loads(output.data)
|
|
Vivek Anand |
bb317c |
for idx in range(len(data['issues'])):
|
|
Vivek Anand |
bb317c |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
3dd389 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Vivek Anand |
bb317c |
self.assertDictEqual(
|
|
Vivek Anand |
bb317c |
data,
|
|
Vivek Anand |
bb317c |
{
|
|
Vivek Anand |
bb317c |
"args": {
|
|
Vivek Anand |
bb317c |
"assignee": None,
|
|
Vivek Anand |
bb317c |
"author": None,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
efe4a8 |
"since": start,
|
|
Vivek Anand |
bb317c |
"status": None,
|
|
Vivek Anand |
bb317c |
"tags": []
|
|
Vivek Anand |
bb317c |
},
|
|
Pierre-Yves Chibon |
3dd389 |
"issues": LCL_ISSUES,
|
|
Pierre-Yves Chibon |
3dd389 |
"total_issues": 2
|
|
Vivek Anand |
bb317c |
}
|
|
Vivek Anand |
bb317c |
)
|
|
Vivek Anand |
bb317c |
|
|
Pierre-Yves Chibon |
3dd389 |
# List all opened issues from the middle
|
|
Pierre-Yves Chibon |
3dd389 |
output = self.app.get('/api/0/test/issues?since=%s' % middle)
|
|
Vivek Anand |
bb317c |
self.assertEqual(output.status_code, 200)
|
|
Vivek Anand |
bb317c |
data = json.loads(output.data)
|
|
Vivek Anand |
bb317c |
for idx in range(len(data['issues'])):
|
|
Vivek Anand |
bb317c |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Pierre-Yves Chibon |
3dd389 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Vivek Anand |
bb317c |
self.assertDictEqual(
|
|
Vivek Anand |
bb317c |
data,
|
|
Vivek Anand |
bb317c |
{
|
|
Vivek Anand |
bb317c |
"args": {
|
|
Vivek Anand |
bb317c |
"assignee": None,
|
|
Vivek Anand |
bb317c |
"author": None,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
3dd389 |
"since": middle,
|
|
Vivek Anand |
bb317c |
"status": None,
|
|
Vivek Anand |
bb317c |
"tags": []
|
|
Vivek Anand |
bb317c |
},
|
|
Pierre-Yves Chibon |
3dd389 |
"issues": LCL_ISSUES[:1],
|
|
Pierre-Yves Chibon |
3dd389 |
"total_issues": 1
|
|
Vivek Anand |
bb317c |
}
|
|
Vivek Anand |
bb317c |
)
|
|
Vivek Anand |
bb317c |
|
|
Pierre-Yves Chibon |
3dd389 |
# List all opened issues at the end
|
|
Pierre-Yves Chibon |
3dd389 |
output = self.app.get('/api/0/test/issues?since=%s' % final)
|
|
Vivek Anand |
e83d2d |
self.assertEqual(output.status_code, 200)
|
|
Vivek Anand |
e83d2d |
data = json.loads(output.data)
|
|
Vivek Anand |
e83d2d |
for idx in range(len(data['issues'])):
|
|
Vivek Anand |
e83d2d |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Vivek Anand |
fd9758 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Vivek Anand |
fd9758 |
self.assertDictEqual(
|
|
Vivek Anand |
fd9758 |
data,
|
|
Vivek Anand |
fd9758 |
{
|
|
Vivek Anand |
fd9758 |
"args": {
|
|
Vivek Anand |
fd9758 |
"assignee": None,
|
|
Vivek Anand |
fd9758 |
"author": None,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
3dd389 |
"since": final,
|
|
Pierre-Yves Chibon |
3dd389 |
"status": None,
|
|
Vivek Anand |
268cca |
"tags": []
|
|
Vivek Anand |
268cca |
},
|
|
Vivek Anand |
268cca |
"issues": [],
|
|
Vivek Anand |
268cca |
"total_issues": 0
|
|
Vivek Anand |
268cca |
}
|
|
Vivek Anand |
268cca |
)
|
|
Vivek Anand |
268cca |
|
|
Pierre-Yves Chibon |
3dd389 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Test since for a value before creation of issues
|
|
Vivek Anand |
e73fe3 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
3dd389 |
'/api/0/test/issues?since=%s' % final, headers=headers)
|
|
Vivek Anand |
e73fe3 |
self.assertEqual(output.status_code, 200)
|
|
Vivek Anand |
e73fe3 |
data = json.loads(output.data)
|
|
Vivek Anand |
e73fe3 |
for idx in range(len(data['issues'])):
|
|
Vivek Anand |
e73fe3 |
data['issues'][idx]['last_updated'] = '1431414800'
|
|
Vivek Anand |
e73fe3 |
data['issues'][idx]['date_created'] = '1431414800'
|
|
Vivek Anand |
e73fe3 |
self.assertDictEqual(
|
|
Vivek Anand |
e73fe3 |
data,
|
|
Vivek Anand |
e73fe3 |
{
|
|
Vivek Anand |
e73fe3 |
"args": {
|
|
Vivek Anand |
e73fe3 |
"assignee": None,
|
|
Vivek Anand |
e73fe3 |
"author": None,
|
|
Pierre-Yves Chibon |
406464 |
'milestones': [],
|
|
Pierre-Yves Chibon |
eb3bbc |
'no_stones': None,
|
|
Pierre-Yves Chibon |
e34a6f |
'priority': None,
|
|
Pierre-Yves Chibon |
3dd389 |
"since": final,
|
|
Pierre-Yves Chibon |
3dd389 |
"status": None,
|
|
Vivek Anand |
e73fe3 |
"tags": []
|
|
Vivek Anand |
e73fe3 |
},
|
|
Pierre-Yves Chibon |
3dd389 |
"issues": [{
|
|
Pierre-Yves Chibon |
3dd389 |
'assignee': None,
|
|
Pierre-Yves Chibon |
3dd389 |
'blocks': [],
|
|
Pierre-Yves Chibon |
3dd389 |
'close_status': None,
|
|
Pierre-Yves Chibon |
3dd389 |
'closed_at': None,
|
|
Pierre-Yves Chibon |
3dd389 |
'comments': [],
|
|
Pierre-Yves Chibon |
3dd389 |
'content': 'Description',
|
|
Pierre-Yves Chibon |
3dd389 |
'custom_fields': [],
|
|
Pierre-Yves Chibon |
3dd389 |
'date_created': '1431414800',
|
|
Pierre-Yves Chibon |
3dd389 |
'depends': [],
|
|
Pierre-Yves Chibon |
3dd389 |
'id': 3,
|
|
Pierre-Yves Chibon |
3dd389 |
'last_updated': '1431414800',
|
|
Pierre-Yves Chibon |
3dd389 |
'milestone': None,
|
|
Pierre-Yves Chibon |
3dd389 |
'priority': None,
|
|
Pierre-Yves Chibon |
3dd389 |
'private': True,
|
|
Pierre-Yves Chibon |
3dd389 |
'status': 'Open',
|
|
Pierre-Yves Chibon |
3dd389 |
'tags': [],
|
|
Pierre-Yves Chibon |
3dd389 |
'title': 'Issue #3',
|
|
Pierre-Yves Chibon |
3dd389 |
'user': {'fullname': 'PY C', 'name': 'pingou'}}
|
|
Pierre-Yves Chibon |
3dd389 |
],
|
|
Pierre-Yves Chibon |
3dd389 |
"total_issues": 1
|
|
Vivek Anand |
e73fe3 |
}
|
|
Vivek Anand |
e73fe3 |
)
|
|
Vivek Anand |
e73fe3 |
|
|
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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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 |
|
|
Martin Basti |
14aa9a |
def test_api_change_milestone_issue(self):
|
|
Martin Basti |
14aa9a |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Martin Basti |
14aa9a |
tests.create_projects(self.session)
|
|
Martin Basti |
14aa9a |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Martin Basti |
14aa9a |
tests.create_tokens(self.session)
|
|
Martin Basti |
14aa9a |
tests.create_tokens_acl(self.session)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Set some milestones to the project
|
|
Farhaan Bukhsh |
7c4229 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Martin Basti |
14aa9a |
repo.milestones = {'v1.0': None, 'v2.0': 'Soon'}
|
|
Martin Basti |
14aa9a |
self.session.add(repo)
|
|
Martin Basti |
14aa9a |
self.session.commit()
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Invalid project
|
|
Martin Basti |
14aa9a |
output = self.app.post('/api/0/foo/issue/1/milestone', headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 404)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"error": "Project not found",
|
|
Martin Basti |
14aa9a |
"error_code": "ENOPROJECT",
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid token, wrong project
|
|
Martin Basti |
14aa9a |
output = self.app.post('/api/0/test2/issue/1/milestone', headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 401)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Martin Basti |
14aa9a |
data['error_code'])
|
|
Martin Basti |
14aa9a |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# No issue
|
|
Martin Basti |
14aa9a |
output = self.app.post('/api/0/test/issue/1/milestone', headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 404)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"error": "Issue not found",
|
|
Martin Basti |
14aa9a |
"error_code": "ENOISSUE",
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Create normal issue
|
|
Farhaan Bukhsh |
7c4229 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Martin Basti |
14aa9a |
msg = pagure.lib.new_issue(
|
|
Martin Basti |
14aa9a |
session=self.session,
|
|
Martin Basti |
14aa9a |
repo=repo,
|
|
Martin Basti |
14aa9a |
title='Test issue #1',
|
|
Martin Basti |
14aa9a |
content='We should work on this',
|
|
Martin Basti |
14aa9a |
user='pingou',
|
|
Martin Basti |
14aa9a |
ticketfolder=None,
|
|
Martin Basti |
14aa9a |
private=False,
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
self.session.commit()
|
|
Martin Basti |
14aa9a |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Check milestone before
|
|
Farhaan Bukhsh |
7c4229 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Martin Basti |
14aa9a |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
data = {
|
|
Martin Basti |
14aa9a |
'milestone': '',
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid request but no milestone specified
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/test/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{'message': 'No changes'}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# No change
|
|
Farhaan Bukhsh |
7c4229 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Martin Basti |
14aa9a |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
data = {
|
|
Martin Basti |
14aa9a |
'milestone': 'milestone-1-0',
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Invalid milestone specified
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/test/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 400)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"error": "Invalid or incomplete input submited",
|
|
Martin Basti |
14aa9a |
"error_code": "EINVALIDREQ",
|
|
Martin Basti |
14aa9a |
"errors": {
|
|
Martin Basti |
14aa9a |
"milestone": [
|
|
Martin Basti |
14aa9a |
"Not a valid choice"
|
|
Martin Basti |
14aa9a |
]
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
data = {
|
|
Martin Basti |
14aa9a |
'milestone': 'v1.0',
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/test/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"message": [
|
|
Martin Basti |
14aa9a |
"Issue set to the milestone: v1.0"
|
|
Martin Basti |
14aa9a |
]
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# remove milestone
|
|
Martin Basti |
14aa9a |
data = {
|
|
Martin Basti |
14aa9a |
'milestone': '',
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/test/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"message": [
|
|
Martin Basti |
14aa9a |
"Issue set to the milestone: None (was: v1.0)"
|
|
Martin Basti |
14aa9a |
]
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Change recorded
|
|
Farhaan Bukhsh |
7c4229 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Martin Basti |
14aa9a |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
data = {
|
|
Martin Basti |
14aa9a |
'milestone': 'v1.0',
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/test/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"message": [
|
|
Martin Basti |
14aa9a |
"Issue set to the milestone: v1.0"
|
|
Martin Basti |
14aa9a |
]
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# remove milestone by using no milestone in JSON
|
|
Martin Basti |
14aa9a |
data = {}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/test/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
Martin Basti |
14aa9a |
"message": [
|
|
Martin Basti |
14aa9a |
"Issue set to the milestone: None (was: v1.0)"
|
|
Martin Basti |
14aa9a |
]
|
|
Martin Basti |
14aa9a |
}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Change recorded
|
|
Farhaan Bukhsh |
7c4229 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Martin Basti |
14aa9a |
issue = pagure.lib.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
headers = {'Authorization': 'token pingou_foo'}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Un-authorized issue
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Martin Basti |
14aa9a |
'/api/0/foo/issue/1/milestone', data=data, headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 401)
|
|
Martin Basti |
14aa9a |
data = json.loads(output.data)
|
|
Martin Basti |
14aa9a |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.name,
|
|
Martin Basti |
14aa9a |
data['error_code'])
|
|
Martin Basti |
14aa9a |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data['error'])
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
5aca93 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
5aca93 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
91e044 |
def test_api_view_issue_comment(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
91e044 |
""" Test the api_view_issue_comment endpoint. """
|
|
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 |
91e044 |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
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 |
91e044 |
# Create normal issue in test
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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 |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
headers = {'Authorization': 'token aaabbbcccddd'}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
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
|
|
Farhaan Bukhsh |
e498a1 |
repo = pagure.get_authorized_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 |
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 |
91e044 |
@patch('pagure.lib.git.update_git')
|
|
Pierre-Yves Chibon |
91e044 |
@patch('pagure.lib.notify.send_email')
|
|
Pierre-Yves Chibon |
91e044 |
def test_api_view_issue_comment_private(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
91e044 |
""" Test the api_view_issue_comment endpoint. """
|
|
Pierre-Yves Chibon |
91e044 |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
91e044 |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
91e044 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
91e044 |
tests.create_projects_git(os.path.join(self.path, 'tickets'))
|
|
Pierre-Yves Chibon |
91e044 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
91e044 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
91e044 |
|
|
Pierre-Yves Chibon |
91e044 |
# Create normal issue in test
|
|
Pierre-Yves Chibon |
91e044 |
repo = pagure.get_authorized_project(self.session, 'test')
|
|
Pierre-Yves Chibon |
91e044 |
msg = pagure.lib.new_issue(
|
|
Pierre-Yves Chibon |
91e044 |
session=self.session,
|
|
Pierre-Yves Chibon |
91e044 |
repo=repo,
|
|
Pierre-Yves Chibon |
91e044 |
title='Test issue #1',
|
|
Pierre-Yves Chibon |
91e044 |
content='We should work on this',
|
|
Pierre-Yves Chibon |
91e044 |
user='foo',
|
|
Pierre-Yves Chibon |
91e044 |
ticketfolder=None,
|
|
Pierre-Yves Chibon |
91e044 |
private=True,
|
|
Pierre-Yves Chibon |
91e044 |
issue_uid='aaabbbccc#1',
|
|
Pierre-Yves Chibon |
91e044 |
)
|
|
Pierre-Yves Chibon |
91e044 |
self.session.commit()
|
|
Pierre-Yves Chibon |
91e044 |
self.assertEqual(msg.title, 'Test issue #1')
|
|
Pierre-Yves Chibon |
91e044 |
|
|
Pierre-Yves Chibon |
91e044 |
# Create a token for another user
|
|
Pierre-Yves Chibon |
91e044 |
item = pagure.lib.model.Token(
|
|
Pierre-Yves Chibon |
91e044 |
id='foo_token_2',
|
|
Pierre-Yves Chibon |
91e044 |
user_id=2,
|
|
Pierre-Yves Chibon |
91e044 |
project_id=1,
|
|
Pierre-Yves Chibon |
91e044 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
91e044 |
+ datetime.timedelta(days=30)
|
|
Pierre-Yves Chibon |
91e044 |
)
|
|
Pierre-Yves Chibon |
91e044 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
91e044 |
self.session.commit()
|
|
Pierre-Yves Chibon |
91e044 |
tests.create_tokens_acl(self.session, token_id='foo_token_2')
|
|
Pierre-Yves Chibon |
91e044 |
|
|
Pierre-Yves Chibon |
91e044 |
# Add a comment to that issue
|
|
Pierre-Yves Chibon |
91e044 |
data = {
|
|
Pierre-Yves Chibon |
91e044 |
'comment': 'This is a very interesting question',
|
|
Pierre-Yves Chibon |
91e044 |
}
|
|
Pierre-Yves Chibon |
91e044 |
headers = {'Authorization': 'token foo_token_2'}
|
|
Pierre-Yves Chibon |
91e044 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
91e044 |
'/api/0/test/issue/1/comment', data=data, headers=headers)
|
|
Pierre-Yves Chibon |
91e044 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
91e044 |
data = json.loads(output.data)
|
|
Pierre-Yves Chibon |
91e044 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
91e044 |
data,
|
|
Pierre-Yves Chibon |
91e044 |
{'message': 'Comment added'}
|
|
Pierre-Yves Chibon |
91e044 |
)
|
|
Pierre-Yves Chibon |
91e044 |
|
|
Pierre-Yves Chibon |
91e044 |
# Private issue - no auth
|
|
Pierre-Yves Chibon |
91e044 |
output = self.app.get('/api/0/test/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 - Invalid token
|
|
Pierre-Yves Chibon |
91e044 |
headers = {'Authorization': 'token aaabbbcccdddee'}
|
|
Pierre-Yves Chibon |
91e044 |
output = self.app.get('/api/0/test/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 |
91e044 |
headers = {'Authorization': 'token foo_token_2'}
|
|
Pierre-Yves Chibon |
91e044 |
output = self.app.get('/api/0/test/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 |
91e044 |
headers = {'Authorization': 'token foo_token_2'}
|
|
Pierre-Yves Chibon |
91e044 |
output = self.app.get('/api/0/test/issue/1/comment/1', 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 |
91e044 |
"id": 1,
|
|
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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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 |
)
|
|
Farhaan Bukhsh |
72e9db |
# No change
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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 |
)
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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 |
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
72e9db |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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 |
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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 |
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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 |
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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
|
|
Farhaan Bukhsh |
481209 |
repo = pagure.get_authorized_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 |
a8f1ac |
['unused data for non-list type', '', 'ack, nack , needs review'],
|
|
Mark Reynolds |
a8f1ac |
[None, None, None])
|
|
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 |
|
|
Farhaan Bukhsh |
20a697 |
repo = pagure.get_authorized_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 |
|
|
Farhaan Bukhsh |
20a697 |
repo = pagure.get_authorized_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 |
|
|
Farhaan Bukhsh |
20a697 |
repo = pagure.get_authorized_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 |
84589e |
"message": "Custom field bugzilla reset "
|
|
Pierre-Yves Chibon |
84589e |
"(from https://bugzilla.redhat.com/1234)"
|
|
Pierre-Yves Chibon |
7bbefe |
}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Farhaan Bukhsh |
20a697 |
repo = pagure.get_authorized_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 |
393f31 |
unittest.main(verbosity=2)
|