|
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 |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
626417 |
|
|
Adam Williamson |
c74215 |
import arrow
|
|
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 |
ab9abc |
import flask
|
|
Pierre-Yves Chibon |
993597 |
import json
|
|
Pierre-Yves Chibon |
ab9abc |
import munch
|
|
Pierre-Yves Chibon |
ab9abc |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
ab9abc |
from sqlalchemy.exc import SQLAlchemyError
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
73d120 |
sys.path.insert(
|
|
Pierre-Yves Chibon |
73d120 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
993597 |
import tests
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
89a786 |
FULL_ISSUE_LIST = [
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 2,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": {"fullname": "foo bar", "name": "foo"},
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 8,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue1",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 7,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 6,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 5,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 4,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 3,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 2,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": "milestone-1.0",
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
89a786 |
]
|
|
Pierre-Yves Chibon |
993597 |
|
|
Mark Reynolds |
fc57b6 |
|
|
Pierre-Yves Chibon |
bceef0 |
LCL_ISSUES = [
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "Description",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 2,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "Description",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
bceef0 |
]
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
738a56 |
class PagureFlaskApiIssuetests(tests.SimplePagureTest):
|
|
Pierre-Yves Chibon |
993597 |
""" Tests for the flask API of pagure for issue """
|
|
Matt Prahl |
47b044 |
|
|
Matt Prahl |
47b044 |
maxDiff = None
|
|
Matt Prahl |
47b044 |
|
|
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 |
73d120 |
pagure.config.config["TICKETS_FOLDER"] = None
|
|
Pierre-Yves Chibon |
e5c5fc |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_wrong_token(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(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
993597 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/test2/new_issue", headers=headers)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config", {"ENABLE_TICKETS_NAMESPACE": ["foobar"]}
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
def test_api_new_issue_wrong_namespace(self):
|
|
Pierre-Yves Chibon |
cd4df4 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
cd4df4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/somenamespace/test3/new_issue", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
cd4df4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.ETRACKERDISABLED.value, data["error"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.ETRACKERDISABLED.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_no_input(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
993597 |
# No input
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/test/new_issue", headers=headers)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
993597 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
993597 |
data,
|
|
Pierre-Yves Chibon |
993597 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
993597 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_invalid_repo(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"title": "test issue"}
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
f69837 |
# Invalid repo
|
|
Pierre-Yves Chibon |
f69837 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/foo/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
f69837 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f69837 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Pierre-Yves Chibon |
f69837 |
)
|
|
Pierre-Yves Chibon |
f69837 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_invalid_request(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
993597 |
# Incomplete request
|
|
Pierre-Yves Chibon |
993597 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data={}, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
993597 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
993597 |
data,
|
|
Pierre-Yves Chibon |
993597 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
993597 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
993597 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"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 |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
993597 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
993597 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": FULL_ISSUE_LIST[8], "message": "Issue created"}
|
|
Mark Reynolds |
fc57b6 |
)
|
|
Mark Reynolds |
fc57b6 |
|
|
Pierre-Yves Chibon |
92aa95 |
def test_api_new_issue_img(self):
|
|
Pierre-Yves Chibon |
92aa95 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
92aa95 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
92aa95 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
92aa95 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
92aa95 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
92aa95 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
92aa95 |
|
|
Pierre-Yves Chibon |
73d120 |
with open(os.path.join(tests.HERE, "placebo.png"), "rb") as stream:
|
|
Pierre-Yves Chibon |
92aa95 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention ",
|
|
Pierre-Yves Chibon |
73d120 |
"filestream": stream,
|
|
Pierre-Yves Chibon |
92aa95 |
}
|
|
Pierre-Yves Chibon |
92aa95 |
|
|
Pierre-Yves Chibon |
92aa95 |
# Valid request
|
|
Pierre-Yves Chibon |
92aa95 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
92aa95 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
92aa95 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
92aa95 |
|
|
Pierre-Yves Chibon |
92aa95 |
issue = copy.deepcopy(FULL_ISSUE_LIST[8])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
92aa95 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure_tests_placebo.png)](/test/issue/raw/files/"
|
|
Pierre-Yves Chibon |
73d120 |
"8a06845923010b27bfd8e7e75acff7badc40d1021b4994e01f5e11ca"
|
|
Pierre-Yves Chibon |
73d120 |
"40bc3abe",
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["content"],
|
|
Pierre-Yves Chibon |
92aa95 |
)
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["content"] = "This issue needs attention"
|
|
Pierre-Yves Chibon |
92aa95 |
|
|
Pierre-Yves Chibon |
92aa95 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
92aa95 |
)
|
|
Pierre-Yves Chibon |
92aa95 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_invalid_milestone(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
René Genz |
dadd94 |
# Valid request but invalid milestone
|
|
Pierre-Yves Chibon |
2521db |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": ["milestone-1.0"],
|
|
Pierre-Yves Chibon |
2521db |
}
|
|
Pierre-Yves Chibon |
2521db |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
2521db |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
2521db |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
2521db |
data,
|
|
Pierre-Yves Chibon |
2521db |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {"milestone": ["Not a valid choice"]},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
2521db |
)
|
|
Pierre-Yves Chibon |
2521db |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_milestone(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
2521db |
# Set some milestones
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"milestone-1.0": "", "milestone-2.0": "Tomorrow!"}
|
|
Pierre-Yves Chibon |
2521db |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
2521db |
self.session.commit()
|
|
Pierre-Yves Chibon |
2521db |
|
|
Mark Reynolds |
fc57b6 |
# Valid request with milestone
|
|
Mark Reynolds |
fc57b6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": ["milestone-1.0"],
|
|
Mark Reynolds |
fc57b6 |
}
|
|
Mark Reynolds |
fc57b6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Mark Reynolds |
fc57b6 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Mark Reynolds |
fc57b6 |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[7])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Mark Reynolds |
fc57b6 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
993597 |
)
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_public(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Valid request, with private='false'
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": "false",
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[6])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
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 |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[5])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 2
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
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 |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": "False",
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[4])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 3
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
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 |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": 0,
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[3])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 4
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_private(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Private issue: True
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[2])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Private issue: 1
|
|
Pierre-Yves Chibon |
9a9e42 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue1",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": "foo",
|
|
Pierre-Yves Chibon |
9a9e42 |
}
|
|
Pierre-Yves Chibon |
9a9e42 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
2521db |
exp = copy.deepcopy(FULL_ISSUE_LIST[1])
|
|
Pierre-Yves Chibon |
73d120 |
exp["id"] = 2
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"issue": exp, "message": "Issue created"})
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.utils.check_api_acls", MagicMock(return_value=None))
|
|
Pierre-Yves Chibon |
ab9abc |
def test_api_new_issue_raise_db_error(self):
|
|
Pierre-Yves Chibon |
ab9abc |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
ab9abc |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
ab9abc |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ab9abc |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
ab9abc |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
ab9abc |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
ab9abc |
|
|
Pierre-Yves Chibon |
ab9abc |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
ab9abc |
}
|
|
Pierre-Yves Chibon |
ab9abc |
|
|
Pierre-Yves Chibon |
73d120 |
with self._app.test_request_context("/") as ctx:
|
|
Pierre-Yves Chibon |
ab9abc |
flask.g.session = self.session
|
|
Pierre-Yves Chibon |
73d120 |
flask.g.fas_user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
ab9abc |
|
|
Pierre-Yves Chibon |
ab9abc |
with patch(
|
|
Pierre-Yves Chibon |
73d120 |
"flask.g.session.commit",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(side_effect=SQLAlchemyError("DB error")),
|
|
Pierre-Yves Chibon |
73d120 |
):
|
|
Pierre-Yves Chibon |
ab9abc |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ab9abc |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
ab9abc |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
ab9abc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
ab9abc |
data,
|
|
Pierre-Yves Chibon |
ab9abc |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "An error occurred at the database "
|
|
Pierre-Yves Chibon |
73d120 |
"level and prevent the action from reaching "
|
|
Pierre-Yves Chibon |
73d120 |
"completion",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EDBERROR",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
ab9abc |
)
|
|
Pierre-Yves Chibon |
ab9abc |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_no_input(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 |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid token, invalid request - No input
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/test2/new_issue", headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_invalid_user(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Another project, still an invalid request - No input
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/test/new_issue", headers=headers)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_invalid_repo(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
73d120 |
data = {"title": "test issue"}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Invalid repo
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/foo/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_invalid_request(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
1dfd94 |
# Incomplete request
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data={}, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1dfd94 |
data,
|
|
Pierre-Yves Chibon |
1dfd94 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
"title": ["This field is required."],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"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 |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": FULL_ISSUE_LIST[8], "message": "Issue created"}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_milestone(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
2521db |
# Set some milestones
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"milestone-1.0": "", "milestone-2.0": "Tomorrow!"}
|
|
Pierre-Yves Chibon |
2521db |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
2521db |
self.session.commit()
|
|
Pierre-Yves Chibon |
2521db |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request with milestone
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": ["milestone-1.0"],
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[7])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_public(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Valid request, with private='false'
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": "false",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[6])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
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 |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[5])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 2
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
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 |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": "False",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[4])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 3
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
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 |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": 0,
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[4])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 4
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
87bcfe |
def test_api_new_issue_user_token_private(self):
|
|
Pierre-Yves Chibon |
87bcfe |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
87bcfe |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Private issue: True
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[2])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 1
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
1dfd94 |
# Private issue: 1
|
|
Pierre-Yves Chibon |
1dfd94 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue1",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": "foo",
|
|
Pierre-Yves Chibon |
1dfd94 |
}
|
|
Pierre-Yves Chibon |
1dfd94 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
87bcfe |
issue = copy.deepcopy(FULL_ISSUE_LIST[1])
|
|
Pierre-Yves Chibon |
73d120 |
issue["id"] = 2
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
1dfd94 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"issue": issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
1dfd94 |
)
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
0c6a50 |
# Private issue: 'true'
|
|
Pierre-Yves Chibon |
0c6a50 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue1",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"private": "true",
|
|
Pierre-Yves Chibon |
0c6a50 |
}
|
|
Pierre-Yves Chibon |
0c6a50 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0c6a50 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
2521db |
exp = copy.deepcopy(FULL_ISSUE_LIST[1])
|
|
Pierre-Yves Chibon |
73d120 |
exp["id"] = 3
|
|
Pierre-Yves Chibon |
73d120 |
exp["assignee"] = None
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"issue": exp, "message": "Issue created"})
|
|
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 |
73d120 |
output = self.app.get("/api/0/foo/issues")
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# List all opened issues
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Create private issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
9a9e42 |
session=self.session,
|
|
Pierre-Yves Chibon |
9a9e42 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
9a9e42 |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
status="Closed",
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues un-authenticated
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
9a9e42 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
9a9e42 |
data,
|
|
Pierre-Yves Chibon |
9a9e42 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
89a786 |
)
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbccc"}
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Access issues authenticated but non-existing token
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
id="bar_token",
|
|
Pierre-Yves Chibon |
89a786 |
user_id=2,
|
|
Pierre-Yves Chibon |
89a786 |
project_id=1,
|
|
Pierre-Yves Chibon |
73d120 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
73d120 |
+ datetime.timedelta(days=30),
|
|
Pierre-Yves Chibon |
89a786 |
)
|
|
Pierre-Yves Chibon |
89a786 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token bar_token"}
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Access issues authenticated but wrong token
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues", headers=headers)
|
|
Pierre-Yves Chibon |
89a786 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
89a786 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
89a786 |
data,
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
89a786 |
|
|
Pierre-Yves Chibon |
89a786 |
# Access issues authenticated correctly
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues", headers=headers)
|
|
Pierre-Yves Chibon |
89a786 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Mark Reynolds |
fc57b6 |
|
|
Pierre-Yves Chibon |
89a786 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
89a786 |
data,
|
|
Pierre-Yves Chibon |
89a786 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
89a786 |
)
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbccc"}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues authenticated but non-existing token
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
id="bar_token_foo",
|
|
Pierre-Yves Chibon |
9a9e42 |
user_id=2,
|
|
Pierre-Yves Chibon |
9a9e42 |
project_id=1,
|
|
Pierre-Yves Chibon |
73d120 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
73d120 |
+ datetime.timedelta(days=30),
|
|
Pierre-Yves Chibon |
9a9e42 |
)
|
|
Pierre-Yves Chibon |
9a9e42 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token bar_token_foo"}
|
|
Pierre-Yves Chibon |
9a9e42 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues authenticated but wrong token
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues", headers=headers)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
87bcfe |
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
9a9e42 |
# Access issues authenticated correctly
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues", headers=headers)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
13e2e9 |
# List closed issue
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issues?status=Closed", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][0]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][0]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[0]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Pierre-Yves Chibon |
13e2e9 |
# List closed issue
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issues?status=Invalid", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
13e2e9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
13e2e9 |
data,
|
|
Pierre-Yves Chibon |
13e2e9 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Invalid",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 0,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 0,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
13e2e9 |
)
|
|
Pierre-Yves Chibon |
13e2e9 |
|
|
Sayan Chowdhury |
e3c0af |
# List all issues
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?status=All", headers=headers)
|
|
Sayan Chowdhury |
e3c0af |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Sayan Chowdhury |
e3c0af |
self.assertDictEqual(
|
|
Sayan Chowdhury |
e3c0af |
data,
|
|
Sayan Chowdhury |
e3c0af |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "All",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [FULL_ISSUE_LIST[0], FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 2,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Sayan Chowdhury |
e3c0af |
)
|
|
Sayan Chowdhury |
e3c0af |
|
|
Pierre-Yves Chibon |
8351c4 |
def test_api_view_issues_user_token(self):
|
|
Pierre-Yves Chibon |
8351c4 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
8351c4 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
data = {
|
|
Pierre-Yves Chibon |
8351c4 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
8351c4 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
8351c4 |
}
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
# Create an issue
|
|
Pierre-Yves Chibon |
8351c4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
8351c4 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8351c4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8351c4 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8351c4 |
data, {"issue": FULL_ISSUE_LIST[8], "message": "Issue created"}
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
# List all opened issues
|
|
Pierre-Yves Chibon |
8351c4 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8351c4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8351c4 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
8351c4 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
8351c4 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8351c4 |
data,
|
|
Pierre-Yves Chibon |
8351c4 |
{
|
|
Pierre-Yves Chibon |
8351c4 |
"args": {
|
|
Pierre-Yves Chibon |
8351c4 |
"assignee": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"author": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"milestones": [],
|
|
Pierre-Yves Chibon |
8351c4 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"order": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"priority": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"since": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"status": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"tags": [],
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
8351c4 |
"pagination": {
|
|
Pierre-Yves Chibon |
8351c4 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
8351c4 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
8351c4 |
"next": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"page": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
"pages": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
8351c4 |
"prev": None,
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
def test_api_view_issues_private_user_token(self):
|
|
Pierre-Yves Chibon |
8351c4 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
8351c4 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_tokens(self.session, project_id=None)
|
|
Pierre-Yves Chibon |
8351c4 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
data = {
|
|
Pierre-Yves Chibon |
8351c4 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
8351c4 |
"issue_content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
8351c4 |
"private": True
|
|
Pierre-Yves Chibon |
8351c4 |
}
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
# Create an issue
|
|
Pierre-Yves Chibon |
8351c4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
8351c4 |
"/api/0/test/new_issue", data=data, headers=headers
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8351c4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8351c4 |
lcl_issue = copy.deepcopy(FULL_ISSUE_LIST[8])
|
|
Pierre-Yves Chibon |
8351c4 |
lcl_issue["private"] = True
|
|
Pierre-Yves Chibon |
8351c4 |
data["issue"]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
data["issue"]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8351c4 |
data, {"issue": lcl_issue, "message": "Issue created"}
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
# List all opened issues - unauth
|
|
Pierre-Yves Chibon |
8351c4 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8351c4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8351c4 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
8351c4 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
8351c4 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8351c4 |
data,
|
|
Pierre-Yves Chibon |
8351c4 |
{
|
|
Pierre-Yves Chibon |
8351c4 |
"args": {
|
|
Pierre-Yves Chibon |
8351c4 |
"assignee": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"author": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"milestones": [],
|
|
Pierre-Yves Chibon |
8351c4 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"order": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"priority": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"since": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"status": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"tags": [],
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
"issues": [],
|
|
Pierre-Yves Chibon |
8351c4 |
"pagination": {
|
|
Pierre-Yves Chibon |
8351c4 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
8351c4 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
8351c4 |
"next": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"page": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
"pages": 0,
|
|
Pierre-Yves Chibon |
8351c4 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
8351c4 |
"prev": None,
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
"total_issues": 0,
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
# List all opened issues - auth
|
|
Pierre-Yves Chibon |
8351c4 |
output = self.app.get("/api/0/test/issues", headers=headers)
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
8351c4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
8351c4 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
8351c4 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
8351c4 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
8351c4 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
8351c4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
8351c4 |
data,
|
|
Pierre-Yves Chibon |
8351c4 |
{
|
|
Pierre-Yves Chibon |
8351c4 |
"args": {
|
|
Pierre-Yves Chibon |
8351c4 |
"assignee": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"author": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"milestones": [],
|
|
Pierre-Yves Chibon |
8351c4 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"order": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"priority": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"since": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"status": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"tags": [],
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
"issues": [lcl_issue],
|
|
Pierre-Yves Chibon |
8351c4 |
"pagination": {
|
|
Pierre-Yves Chibon |
8351c4 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
8351c4 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
8351c4 |
"next": None,
|
|
Pierre-Yves Chibon |
8351c4 |
"page": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
"pages": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
8351c4 |
"prev": None,
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
8351c4 |
},
|
|
Pierre-Yves Chibon |
8351c4 |
)
|
|
Pierre-Yves Chibon |
8351c4 |
|
|
Pierre-Yves Chibon |
06d37a |
def test_api_view_issues_since_invalid_format(self):
|
|
Pierre-Yves Chibon |
06d37a |
""" Test the api_view_issues method of the flask api. """
|
|
Pierre-Yves Chibon |
06d37a |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
06d37a |
|
|
Pierre-Yves Chibon |
06d37a |
# Invalid repo
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?since=12-13")
|
|
Pierre-Yves Chibon |
06d37a |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
06d37a |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
06d37a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
06d37a |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{"error": "Invalid datetime format", "error_code": "EDATETIME"},
|
|
Pierre-Yves Chibon |
06d37a |
)
|
|
Pierre-Yves Chibon |
06d37a |
|
|
Pierre-Yves Chibon |
06d37a |
def test_api_view_issues_since_invalid_timestamp(self):
|
|
Pierre-Yves Chibon |
06d37a |
""" Test the api_view_issues method of the flask api. """
|
|
Pierre-Yves Chibon |
06d37a |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
06d37a |
|
|
Pierre-Yves Chibon |
06d37a |
# Invalid repo
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?since=100000000000000")
|
|
Pierre-Yves Chibon |
06d37a |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
06d37a |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
06d37a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
06d37a |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{"error": "Invalid timestamp format", "error_code": "ETIMESTAMP"},
|
|
Pierre-Yves Chibon |
06d37a |
)
|
|
Pierre-Yves Chibon |
06d37a |
|
|
Matt Prahl |
47b044 |
def test_api_view_issues_reversed(self):
|
|
Matt Prahl |
47b044 |
""" Test the api_view_issues method of the flask api. in reversed
|
|
Matt Prahl |
47b044 |
order.
|
|
Matt Prahl |
47b044 |
|
|
Matt Prahl |
47b044 |
"""
|
|
Matt Prahl |
47b044 |
self.test_api_new_issue()
|
|
Matt Prahl |
47b044 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Matt Prahl |
47b044 |
|
|
Matt Prahl |
47b044 |
# List issues in reverse order
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?order=asc", headers=headers)
|
|
Matt Prahl |
47b044 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Matt Prahl |
47b044 |
expected = {
|
|
Matt Prahl |
47b044 |
"args": {
|
|
Matt Prahl |
47b044 |
"assignee": None,
|
|
Matt Prahl |
47b044 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": "asc",
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Matt Prahl |
47b044 |
"since": None,
|
|
Matt Prahl |
47b044 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Matt Prahl |
47b044 |
},
|
|
Pierre-Yves Chibon |
87bcfe |
"issues": [FULL_ISSUE_LIST[8]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
6eccc3 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Matt Prahl |
47b044 |
}
|
|
Matt Prahl |
47b044 |
self.assertDictEqual(data, expected)
|
|
Matt Prahl |
47b044 |
|
|
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 |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
bceef0 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
# Create 2 tickets but only 1 has a milestone
|
|
Adam Williamson |
c74215 |
start = arrow.utcnow().timestamp
|
|
Pierre-Yves Chibon |
bceef0 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
bceef0 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
bceef0 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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 |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
bceef0 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
bceef0 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
uid="issue#2",
|
|
Pierre-Yves Chibon |
bceef0 |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
bceef0 |
lcl_issues = copy.deepcopy(LCL_ISSUES)
|
|
Pierre-Yves Chibon |
73d120 |
lcl_issues[0]["milestone"] = "v1.0"
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
bceef0 |
data,
|
|
Pierre-Yves Chibon |
bceef0 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": lcl_issues,
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 2,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
bceef0 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
bceef0 |
# List all issues of the milestone v1.0
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?milestones=v1.0")
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
bceef0 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
bceef0 |
data,
|
|
Pierre-Yves Chibon |
bceef0 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": ["v1.0"],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
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 |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
e34a6f |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
e34a6f |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
e34a6f |
# Create 2 tickets but only 1 has a priority
|
|
Adam Williamson |
c74215 |
start = arrow.utcnow().timestamp
|
|
Pierre-Yves Chibon |
e34a6f |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
e34a6f |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
e34a6f |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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 |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
e34a6f |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
e34a6f |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
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 |
73d120 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
e34a6f |
lcl_issues = copy.deepcopy(LCL_ISSUES)
|
|
Pierre-Yves Chibon |
73d120 |
lcl_issues[0]["priority"] = 1
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e34a6f |
data,
|
|
Pierre-Yves Chibon |
e34a6f |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": lcl_issues,
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 2,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
e34a6f |
)
|
|
Pierre-Yves Chibon |
e34a6f |
|
|
Pierre-Yves Chibon |
f07509 |
# List all issues of the priority high (ie: 1)
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?priority=high")
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
e34a6f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e34a6f |
data,
|
|
Pierre-Yves Chibon |
e34a6f |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": "high",
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
bceef0 |
)
|
|
Pierre-Yves Chibon |
bceef0 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?priority=1")
|
|
Pierre-Yves Chibon |
f07509 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
f07509 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f07509 |
data,
|
|
Pierre-Yves Chibon |
f07509 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": "1",
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
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 |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
output = self.app.get("/api/0/test/issues?priority=foobar")
|
|
Pierre-Yves Chibon |
f07509 |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
f07509 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
f07509 |
data,
|
|
Pierre-Yves Chibon |
f07509 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid priority submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDPRIORITY",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
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 |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
eb3bbc |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# Create 2 tickets but only 1 has a milestone
|
|
Adam Williamson |
c74215 |
start = arrow.utcnow().timestamp
|
|
Pierre-Yves Chibon |
eb3bbc |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
eb3bbc |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
eb3bbc |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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 |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
eb3bbc |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
eb3bbc |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
uid="issue#2",
|
|
Pierre-Yves Chibon |
eb3bbc |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
output = self.app.get("/api/0/test/issues")
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
eb3bbc |
lcl_issues = copy.deepcopy(LCL_ISSUES)
|
|
Pierre-Yves Chibon |
73d120 |
lcl_issues[0]["milestone"] = "v1.0"
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
eb3bbc |
data,
|
|
Pierre-Yves Chibon |
eb3bbc |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": lcl_issues,
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 2,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# List all issues with no milestone
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?no_stones=1")
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
eb3bbc |
data,
|
|
Pierre-Yves Chibon |
eb3bbc |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": True,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [lcl_issues[1]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
eb3bbc |
)
|
|
Pierre-Yves Chibon |
eb3bbc |
|
|
Pierre-Yves Chibon |
eb3bbc |
# List all issues with a milestone
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?no_stones=0")
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Pierre-Yves Chibon |
eb3bbc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
eb3bbc |
data,
|
|
Pierre-Yves Chibon |
eb3bbc |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": False,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [lcl_issues[0]],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
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 |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3dd389 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
3dd389 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Create 1st tickets
|
|
Adam Williamson |
c74215 |
start = arrow.utcnow().timestamp
|
|
Pierre-Yves Chibon |
3dd389 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
3dd389 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
3dd389 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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)
|
|
Adam Williamson |
c74215 |
middle = arrow.utcnow().timestamp
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Create 2nd tickets
|
|
Pierre-Yves Chibon |
3dd389 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
3dd389 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
3dd389 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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)
|
|
Adam Williamson |
c74215 |
final = arrow.utcnow().timestamp
|
|
Pierre-Yves Chibon |
3dd389 |
|
|
Pierre-Yves Chibon |
3dd389 |
# Create private issue
|
|
Pierre-Yves Chibon |
3dd389 |
issue = pagure.lib.model.Issue(
|
|
Pierre-Yves Chibon |
930073 |
id=pagure.lib.query.get_next_id(self.session, repo.id),
|
|
Pierre-Yves Chibon |
3dd389 |
project_id=repo.id,
|
|
Pierre-Yves Chibon |
73d120 |
title="Issue #3",
|
|
Pierre-Yves Chibon |
73d120 |
content="Description",
|
|
Pierre-Yves Chibon |
3dd389 |
user_id=1, # pingou
|
|
Pierre-Yves Chibon |
73d120 |
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
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/foo/issues")
|
|
Vivek Anand |
f0e3cc |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Vivek Anand |
f0e3cc |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Vivek Anand |
f0e3cc |
)
|
|
Vivek Anand |
f0e3cc |
|
|
Vivek Anand |
f0e3cc |
# List all opened issues
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues")
|
|
Vivek Anand |
f0e3cc |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Vivek Anand |
f0e3cc |
self.assertDictEqual(
|
|
Vivek Anand |
f0e3cc |
data,
|
|
Vivek Anand |
f0e3cc |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": LCL_ISSUES,
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 2,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Vivek Anand |
f0e3cc |
)
|
|
Vivek Anand |
f0e3cc |
|
|
Pierre-Yves Chibon |
efe4a8 |
time.sleep(1)
|
|
Adam Williamson |
c74215 |
late = arrow.utcnow().timestamp
|
|
Vivek Anand |
f0e3cc |
|
|
Pierre-Yves Chibon |
3dd389 |
# List all opened issues from the start
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?since=%s" % start)
|
|
Vivek Anand |
bb317c |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Vivek Anand |
bb317c |
self.assertDictEqual(
|
|
Vivek Anand |
bb317c |
data,
|
|
Vivek Anand |
bb317c |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": str(start),
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": LCL_ISSUES,
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 2,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Vivek Anand |
bb317c |
)
|
|
Vivek Anand |
bb317c |
|
|
Pierre-Yves Chibon |
3dd389 |
# List all opened issues from the middle
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?since=%s" % middle)
|
|
Vivek Anand |
bb317c |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Vivek Anand |
bb317c |
self.assertDictEqual(
|
|
Vivek Anand |
bb317c |
data,
|
|
Vivek Anand |
bb317c |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": str(middle),
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": LCL_ISSUES[:1],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Vivek Anand |
bb317c |
)
|
|
Vivek Anand |
bb317c |
|
|
Pierre-Yves Chibon |
3dd389 |
# List all opened issues at the end
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues?since=%s" % final)
|
|
Vivek Anand |
e83d2d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Vivek Anand |
fd9758 |
self.assertDictEqual(
|
|
Vivek Anand |
fd9758 |
data,
|
|
Vivek Anand |
fd9758 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": str(final),
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 0,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 0,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Vivek Anand |
268cca |
)
|
|
Vivek Anand |
268cca |
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"/api/0/test/issues?since=%s" % final, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Vivek Anand |
e73fe3 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
for idx in range(len(data["issues"])):
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["issues"][idx]["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
for k in ["first", "last"]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIsNotNone(data["pagination"][k])
|
|
Pierre-Yves Chibon |
73d120 |
data["pagination"][k] = "http://localhost..."
|
|
Pierre-Yves Chibon |
610db7 |
|
|
Vivek Anand |
e73fe3 |
self.assertDictEqual(
|
|
Vivek Anand |
e73fe3 |
data,
|
|
Vivek Anand |
e73fe3 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"args": {
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"author": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": [],
|
|
Pierre-Yves Chibon |
73d120 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
73d120 |
"order": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"since": str(final),
|
|
Pierre-Yves Chibon |
73d120 |
"status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"issues": [
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "Description",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 3,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Issue #3",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
}
|
|
Pierre-Yves Chibon |
73d120 |
],
|
|
Pierre-Yves Chibon |
73d120 |
"pagination": {
|
|
Pierre-Yves Chibon |
73d120 |
"first": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"last": "http://localhost...",
|
|
Pierre-Yves Chibon |
73d120 |
"next": None,
|
|
Pierre-Yves Chibon |
73d120 |
"page": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"pages": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"per_page": 20,
|
|
Pierre-Yves Chibon |
73d120 |
"prev": None,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
73d120 |
"total_issues": 1,
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
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 |
73d120 |
output = self.app.get("/api/0/foo/issue/1")
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
# Invalid issue for this repo
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test2/issue/1")
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Issue not found", "error_code": "ENOISSUE"}
|
|
Pierre-Yves Chibon |
1c76b9 |
)
|
|
Pierre-Yves Chibon |
1c76b9 |
|
|
Pierre-Yves Chibon |
4a277d |
# Valid issue
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/1")
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
1c76b9 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
1c76b9 |
data,
|
|
Pierre-Yves Chibon |
1c76b9 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "This issue needs attention",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": False,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
1c76b9 |
)
|
|
Pierre-Yves Chibon |
1c76b9 |
|
|
Pierre-Yves Chibon |
4a277d |
# Create private issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
4a277d |
session=self.session,
|
|
Pierre-Yves Chibon |
4a277d |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
4a277d |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc",
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
# Access private issue un-authenticated
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/2")
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 403)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "You are not allowed to view this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EISSUENOTALLOWED",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbccc"}
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
c4fef5 |
# Access private issue authenticated but non-existing token
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/2", headers=headers)
|
|
Pierre-Yves Chibon |
c4fef5 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(data.keys()), ["error", "error_code", "errors"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["errors"], "Invalid token")
|
|
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 |
73d120 |
id="bar_token",
|
|
Pierre-Yves Chibon |
c4fef5 |
user_id=2,
|
|
Pierre-Yves Chibon |
c4fef5 |
project_id=1,
|
|
Pierre-Yves Chibon |
73d120 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
73d120 |
+ datetime.timedelta(days=30),
|
|
Pierre-Yves Chibon |
c4fef5 |
)
|
|
Pierre-Yves Chibon |
c4fef5 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
b130e5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
c4fef5 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token bar_token"}
|
|
Pierre-Yves Chibon |
c4fef5 |
|
|
Pierre-Yves Chibon |
4a277d |
# Access private issue authenticated but wrong token
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/2", headers=headers)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 403)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "You are not allowed to view this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EISSUENOTALLOWED",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
4a277d |
# Access private issue authenticated correctly
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/2", headers=headers)
|
|
Pierre-Yves Chibon |
4a277d |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
7b4f84 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7b4f84 |
data,
|
|
Pierre-Yves Chibon |
7b4f84 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 2,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
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 |
73d120 |
output = self.app.get("/api/0/test/issue/aaabbbccc", headers=headers)
|
|
Pierre-Yves Chibon |
7b4f84 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
data["date_created"] = "1431414800"
|
|
Pierre-Yves Chibon |
73d120 |
data["last_updated"] = "1431414800"
|
|
Pierre-Yves Chibon |
4a277d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
4a277d |
data,
|
|
Pierre-Yves Chibon |
4a277d |
{
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": None,
|
|
Pierre-Yves Chibon |
73d120 |
"blocks": [],
|
|
Pierre-Yves Chibon |
73d120 |
"comments": [],
|
|
Pierre-Yves Chibon |
73d120 |
"content": "We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
"custom_fields": [],
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_at": None,
|
|
Pierre-Yves Chibon |
73d120 |
"closed_by": None,
|
|
Pierre-Yves Chibon |
73d120 |
"depends": [],
|
|
Pierre-Yves Chibon |
73d120 |
"id": 2,
|
|
Pierre-Yves Chibon |
73d120 |
"last_updated": "1431414800",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": None,
|
|
Pierre-Yves Chibon |
73d120 |
"priority": None,
|
|
Pierre-Yves Chibon |
73d120 |
"private": True,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"tags": [],
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
4a277d |
)
|
|
Pierre-Yves Chibon |
4a277d |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_invalid_project(self):
|
|
Martin Basti |
14aa9a |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Martin Basti |
14aa9a |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
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
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Martin Basti |
14aa9a |
self.session.add(repo)
|
|
Martin Basti |
14aa9a |
self.session.commit()
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Invalid project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/foo/issue/1/milestone", headers=headers)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config", {"ENABLE_TICKETS_NAMESPACE": ["foobar"]}
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
def test_api_change_milestone_issue_wrong_namespace(self):
|
|
Pierre-Yves Chibon |
cd4df4 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
cd4df4 |
repo = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test3", namespace="somenamespace"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
cd4df4 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
cd4df4 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
cd4df4 |
session=self.session,
|
|
Pierre-Yves Chibon |
cd4df4 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
cd4df4 |
private=False,
|
|
Pierre-Yves Chibon |
cd4df4 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
cd4df4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/somenamespace/test3/issue/1/milestone", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
cd4df4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.ETRACKERDISABLED.value, data["error"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.ETRACKERDISABLED.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_wrong_token(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Martin Basti |
14aa9a |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test2/issue/1/milestone", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_no_issue(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Martin Basti |
14aa9a |
# No issue
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Issue not found", "error_code": "ENOISSUE"}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_no_milestone(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Martin Basti |
14aa9a |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Martin Basti |
14aa9a |
session=self.session,
|
|
Martin Basti |
14aa9a |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Martin Basti |
14aa9a |
private=False,
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Check milestone before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": ""}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid request but no milestone specified
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "No changes"})
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# No change
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_invalid_milestone(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
0bc20d |
session=self.session,
|
|
Pierre-Yves Chibon |
0bc20d |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
0bc20d |
private=False,
|
|
Pierre-Yves Chibon |
0bc20d |
)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Check milestone before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
0bc20d |
self.assertEqual(issue.milestone, None)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": "milestone-1-0"}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Invalid milestone specified
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Martin Basti |
14aa9a |
data,
|
|
Martin Basti |
14aa9a |
{
|
|
René Genz |
dadd94 |
"error": "Invalid or incomplete input submitted",
|
|
Martin Basti |
14aa9a |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
"errors": {"milestone": ["Not a valid choice"]},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
0bc20d |
session=self.session,
|
|
Pierre-Yves Chibon |
0bc20d |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
0bc20d |
private=False,
|
|
Pierre-Yves Chibon |
0bc20d |
)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Check milestone before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
0bc20d |
self.assertEqual(issue.milestone, None)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": "v1.0"}
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Valid requests
|
|
Pierre-Yves Chibon |
0bc20d |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0bc20d |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
0bc20d |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
0bc20d |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"message": ["Issue set to the milestone: v1.0"]}
|
|
Pierre-Yves Chibon |
0bc20d |
)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_remove_milestone(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
0bc20d |
session=self.session,
|
|
Pierre-Yves Chibon |
0bc20d |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
0bc20d |
private=False,
|
|
Pierre-Yves Chibon |
0bc20d |
)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Check milestone before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
0bc20d |
self.assertEqual(issue.milestone, None)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": "v1.0"}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"message": ["Issue set to the milestone: v1.0"]}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# remove milestone
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": ""}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"message": ["Issue set to the milestone: None (was: v1.0)"]}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Change recorded
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_remove_milestone2(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
0bc20d |
session=self.session,
|
|
Pierre-Yves Chibon |
0bc20d |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
0bc20d |
private=False,
|
|
Pierre-Yves Chibon |
0bc20d |
)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Check milestone before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
0bc20d |
self.assertEqual(issue.milestone, None)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": "v1.0"}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Valid requests
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"message": ["Issue set to the milestone: v1.0"]}
|
|
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(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Martin Basti |
14aa9a |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"message": ["Issue set to the milestone: None (was: v1.0)"]}
|
|
Martin Basti |
14aa9a |
)
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Change recorded
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Martin Basti |
14aa9a |
self.assertEqual(issue.milestone, None)
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
0bc20d |
def test_api_change_milestone_issue_unauthorized(self):
|
|
Pierre-Yves Chibon |
0bc20d |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
0bc20d |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
0bc20d |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
0bc20d |
session=self.session,
|
|
Pierre-Yves Chibon |
0bc20d |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
0bc20d |
private=False,
|
|
Pierre-Yves Chibon |
0bc20d |
)
|
|
Pierre-Yves Chibon |
0bc20d |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
0bc20d |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token pingou_foo"}
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": "v1.0"}
|
|
Martin Basti |
14aa9a |
|
|
Martin Basti |
14aa9a |
# Un-authorized issue
|
|
Martin Basti |
14aa9a |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/foo/issue/1/milestone", data={}, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Martin Basti |
14aa9a |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(data.keys()), ["error", "error_code", "errors"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["errors"], "Invalid token")
|
|
Martin Basti |
14aa9a |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
51514c |
@patch(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.lib.query.add_metadata_update_notif",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(side_effect=pagure.exceptions.PagureException("error")),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
51514c |
def test_api_change_milestone_issue_raises_exception(self):
|
|
Pierre-Yves Chibon |
51514c |
""" Test the api_change_milestone_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
51514c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
51514c |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
51514c |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
51514c |
|
|
Pierre-Yves Chibon |
51514c |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
51514c |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
51514c |
self.session.commit()
|
|
Pierre-Yves Chibon |
51514c |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
51514c |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
51514c |
session=self.session,
|
|
Pierre-Yves Chibon |
51514c |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
51514c |
private=False,
|
|
Pierre-Yves Chibon |
51514c |
)
|
|
Pierre-Yves Chibon |
51514c |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
51514c |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"milestone": "v1.0"}
|
|
Pierre-Yves Chibon |
51514c |
|
|
Pierre-Yves Chibon |
51514c |
# Valid requests
|
|
Pierre-Yves Chibon |
51514c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/milestone", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
51514c |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
51514c |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"error": "error", "error_code": "ENOCODE"})
|
|
Pierre-Yves Chibon |
51514c |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git")
|
|
Pierre-Yves Chibon |
73d120 |
@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 |
73d120 |
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
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
fc6bd4 |
session=self.session,
|
|
Pierre-Yves Chibon |
fc6bd4 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
fc6bd4 |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc1",
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
1dfd94 |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"comment": "This is a very interesting question"}
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# Valid request
|
|
Pierre-Yves Chibon |
fc6bd4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/comment", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
fc6bd4 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
fc6bd4 |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "Comment added",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "pingou",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
fc6bd4 |
)
|
|
Pierre-Yves Chibon |
fc6bd4 |
|
|
Pierre-Yves Chibon |
fc6bd4 |
# One comment added
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
73d120 |
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 |
73d120 |
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 |
73d120 |
output = self.app.get("/api/0/test/issue/1/comment/1")
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "This is a very interesting question",
|
|
Pierre-Yves Chibon |
73d120 |
"comment_date": "2015-07-02 09:22",
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1435821770",
|
|
Pierre-Yves Chibon |
73d120 |
"edited_on": None,
|
|
Pierre-Yves Chibon |
73d120 |
"editor": None,
|
|
Pierre-Yves Chibon |
73d120 |
"notification": False,
|
|
Pierre-Yves Chibon |
73d120 |
"id": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"parent": None,
|
|
Pierre-Yves Chibon |
73d120 |
"reactions": {},
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
896cc0 |
)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
896cc0 |
# Issue and comment exists, using UID
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/aaabbbccc1/comment/1")
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "This is a very interesting question",
|
|
Pierre-Yves Chibon |
73d120 |
"comment_date": "2015-07-02 09:22",
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1435821770",
|
|
Pierre-Yves Chibon |
73d120 |
"edited_on": None,
|
|
Pierre-Yves Chibon |
73d120 |
"editor": None,
|
|
Pierre-Yves Chibon |
73d120 |
"notification": False,
|
|
Pierre-Yves Chibon |
73d120 |
"id": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"parent": None,
|
|
Pierre-Yves Chibon |
73d120 |
"reactions": {},
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "PY C", "name": "pingou"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
896cc0 |
)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git")
|
|
Pierre-Yves Chibon |
73d120 |
@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 |
73d120 |
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 |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
91e044 |
session=self.session,
|
|
Pierre-Yves Chibon |
91e044 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="foo",
|
|
Pierre-Yves Chibon |
91e044 |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc1",
|
|
Pierre-Yves Chibon |
91e044 |
)
|
|
Pierre-Yves Chibon |
91e044 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
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 |
73d120 |
+ 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 |
73d120 |
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 |
73d120 |
data = {"comment": "This is a very interesting question"}
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token foo_token_2"}
|
|
Pierre-Yves Chibon |
91e044 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/comment", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
91e044 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
91e044 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
91e044 |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "Comment added",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "foo",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
91e044 |
)
|
|
Pierre-Yves Chibon |
91e044 |
|
|
Pierre-Yves Chibon |
91e044 |
# Private issue - no auth
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
headers = {"Authorization": "token aaabbbcccdddee"}
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
headers = {"Authorization": "token foo_token_2"}
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
headers = {"Authorization": "token foo_token_2"}
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issue/1/comment/1", headers=headers)
|
|
Pierre-Yves Chibon |
896cc0 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "This is a very interesting question",
|
|
Pierre-Yves Chibon |
73d120 |
"comment_date": "2015-07-02 09:22",
|
|
Pierre-Yves Chibon |
73d120 |
"date_created": "1435821770",
|
|
Pierre-Yves Chibon |
73d120 |
"edited_on": None,
|
|
Pierre-Yves Chibon |
73d120 |
"editor": None,
|
|
Pierre-Yves Chibon |
73d120 |
"notification": False,
|
|
Pierre-Yves Chibon |
73d120 |
"id": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"parent": None,
|
|
Pierre-Yves Chibon |
73d120 |
"reactions": {},
|
|
Pierre-Yves Chibon |
73d120 |
"user": {"fullname": "foo bar", "name": "foo"},
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
896cc0 |
)
|
|
Pierre-Yves Chibon |
896cc0 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch.dict(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.config.config", {"ENABLE_TICKETS_NAMESPACE": ["foobar"]}
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
def test_api_assign_issue_wrong_namespace(self):
|
|
Pierre-Yves Chibon |
cd4df4 |
""" Test the api_new_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Set some milestones to the project
|
|
Pierre-Yves Chibon |
cd4df4 |
repo = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test3", namespace="somenamespace"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": None, "v2.0": "Soon"}
|
|
Pierre-Yves Chibon |
cd4df4 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Create normal issue
|
|
Pierre-Yves Chibon |
cd4df4 |
repo = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test3", namespace="somenamespace"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
cd4df4 |
session=self.session,
|
|
Pierre-Yves Chibon |
cd4df4 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
cd4df4 |
private=False,
|
|
Pierre-Yves Chibon |
cd4df4 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
cd4df4 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
cd4df4 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/somenamespace/test3/issue/1/assign", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
cd4df4 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.ETRACKERDISABLED.value, data["error"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.ETRACKERDISABLED.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
cd4df4 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git")
|
|
Pierre-Yves Chibon |
73d120 |
@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 |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Invalid project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/foo/issue/1/assign", headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Valid token, wrong project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/test2/issue/1/assign", headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# No input
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/test/issue/1/assign", headers=headers)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Issue not found", "error_code": "ENOISSUE"}
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
3d10a7 |
session=self.session,
|
|
Pierre-Yves Chibon |
3d10a7 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
3d10a7 |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc1",
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Check comments before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# No change
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.status, "Open")
|
|
Pierre-Yves Chibon |
538c06 |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": "pingou"}
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# Valid request
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Issue assigned to pingou"})
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
538c06 |
# Un-assign
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Assignee reset"})
|
|
Farhaan Bukhsh |
72e9db |
# No change
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
73d120 |
data = {"assignee": None}
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Nothing to change"})
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
73d120 |
data = {"assignee": "pingou"}
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Issue assigned to pingou"})
|
|
Pierre-Yves Chibon |
538c06 |
|
|
Pierre-Yves Chibon |
538c06 |
# Un-assign
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": ""}
|
|
Pierre-Yves Chibon |
538c06 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
538c06 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Assignee reset"})
|
|
Pierre-Yves Chibon |
538c06 |
|
|
Pierre-Yves Chibon |
538c06 |
# Re-assign for the rest of the tests
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": "pingou"}
|
|
Pierre-Yves Chibon |
3d10a7 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Issue assigned to pingou"})
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# One comment added
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
name="foo",
|
|
Pierre-Yves Chibon |
73d120 |
description="test project #3",
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
id="pingou_foo",
|
|
Pierre-Yves Chibon |
3d10a7 |
user_id=1,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
73d120 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
73d120 |
+ 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 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Give `issue_change_status` to this token when `issue_comment`
|
|
Pierre-Yves Chibon |
3d10a7 |
# is required
|
|
Pierre-Yves Chibon |
73d120 |
item = pagure.lib.model.TokenAcl(token_id="pingou_foo", acl_id=8)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "foo")
|
|
Pierre-Yves Chibon |
3d10a7 |
# Create private issue
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
3d10a7 |
session=self.session,
|
|
Pierre-Yves Chibon |
3d10a7 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="foo",
|
|
Pierre-Yves Chibon |
3d10a7 |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc#2",
|
|
Pierre-Yves Chibon |
3d10a7 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# Check before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "foo")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": "pingou"}
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"/api/0/foo/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(data.keys()), ["error", "error_code", "errors"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
0a54a2 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data["errors"], "Missing ACLs: issue_assign, issue_update"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
3d10a7 |
# No comment added
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "foo")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
73d120 |
id="foo_token2",
|
|
Pierre-Yves Chibon |
3d10a7 |
user_id=2,
|
|
clime |
afed57 |
project_id=4,
|
|
Pierre-Yves Chibon |
73d120 |
expiration=datetime.datetime.utcnow()
|
|
Pierre-Yves Chibon |
73d120 |
+ 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 |
73d120 |
tests.create_tokens_acl(self.session, token_id="foo_token2")
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": "pingou"}
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"/api/0/foo/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3d10a7 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Issue assigned to pingou"})
|
|
Pierre-Yves Chibon |
3d10a7 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git")
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email")
|
|
Pierre-Yves Chibon |
e7f92c |
def test_api_assign_issue_issuer(self, p_send_email, p_ugt):
|
|
Pierre-Yves Chibon |
e7f92c |
""" Test the api_assign_issue method of the flask api. """
|
|
Pierre-Yves Chibon |
e7f92c |
p_send_email.return_value = True
|
|
Pierre-Yves Chibon |
e7f92c |
p_ugt.return_value = True
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
e7f92c |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
e7f92c |
tests.create_tokens(self.session, user_id=2)
|
|
Pierre-Yves Chibon |
e7f92c |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
e7f92c |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
e7f92c |
session=self.session,
|
|
Pierre-Yves Chibon |
e7f92c |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
e7f92c |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc1",
|
|
Pierre-Yves Chibon |
73d120 |
assignee="foo",
|
|
Pierre-Yves Chibon |
e7f92c |
)
|
|
Pierre-Yves Chibon |
e7f92c |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
e7f92c |
# Check comments before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
e7f92c |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
e7f92c |
# Un-assign
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": None}
|
|
Pierre-Yves Chibon |
e7f92c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data={}, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
e7f92c |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "Assignee reset"})
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
e7f92c |
# No longer allowed to self-assign since no access
|
|
Pierre-Yves Chibon |
73d120 |
data = {"assignee": "foo"}
|
|
Pierre-Yves Chibon |
e7f92c |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/assign", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
e7f92c |
self.assertEqual(output.status_code, 403)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e7f92c |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
e7f92c |
data,
|
|
Pierre-Yves Chibon |
e7f92c |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "You are not allowed to view this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EISSUENOTALLOWED",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
e7f92c |
)
|
|
Pierre-Yves Chibon |
e7f92c |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git")
|
|
Pierre-Yves Chibon |
73d120 |
@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 |
73d120 |
user="bar",
|
|
Pierre-Yves Chibon |
73d120 |
fullname="bar foo",
|
|
Pierre-Yves Chibon |
73d120 |
password="foo",
|
|
Pierre-Yves Chibon |
73d120 |
default_email="bar@bar.com",
|
|
Pierre-Yves Chibon |
7e0d44 |
)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
73d120 |
item = pagure.lib.model.UserEmail(user_id=3, 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 |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Invalid project
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/api/0/foo/issue/1/subscribe", headers=headers)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
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 |
73d120 |
"/api/0/test2/issue/1/subscribe", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# No input
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/subscribe", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Issue not found", "error_code": "ENOISSUE"}
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
be459f |
session=self.session,
|
|
Pierre-Yves Chibon |
be459f |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="foo",
|
|
Pierre-Yves Chibon |
be459f |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
issue_uid="aaabbbccc1",
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Check subscribtion before
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
73d120 |
set(["pingou", "foo"]),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
"/api/0/test/issue/1/subscribe", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "You are no longer watching this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "bar",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
data = {}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/subscribe", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "You are no longer watching this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "bar",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# No change
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
73d120 |
set(["pingou", "foo"]),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Subscribe
|
|
Pierre-Yves Chibon |
73d120 |
data = {"status": True}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/subscribe", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "You are now watching this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "bar",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
be459f |
# Subscribe - no changes
|
|
Pierre-Yves Chibon |
73d120 |
data = {"status": True}
|
|
Pierre-Yves Chibon |
be459f |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/subscribe", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "You are now watching this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "bar",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
73d120 |
set(["pingou", "foo", "bar"]),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
"/api/0/test/issue/1/subscribe", data=data, headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
be459f |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
e2c468 |
data["avatar_url"] = "https://seccdn.libravatar.org/avatar/..."
|
|
Pierre-Yves Chibon |
be459f |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
be459f |
data,
|
|
Pierre-Yves Chibon |
73d120 |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "You are no longer watching this issue",
|
|
Pierre-Yves Chibon |
73d120 |
"avatar_url": "https://seccdn.libravatar.org/avatar/...",
|
|
Pierre-Yves Chibon |
73d120 |
"user": "bar",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
be459f |
)
|
|
Pierre-Yves Chibon |
be459f |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7e0d44 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
930073 |
pagure.lib.query.get_watch_list(self.session, issue),
|
|
Pierre-Yves Chibon |
73d120 |
set(["pingou", "foo"]),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
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 |
73d120 |
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 |
73d120 |
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 |
73d120 |
"/api/0/foo/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Project not found", "error_code": "ENOPROJECT"}
|
|
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 |
73d120 |
"/api/0/test2/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(sorted(data.keys()), ["error", "error_code"])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# No issue
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
73d120 |
data, {"error": "Issue not found", "error_code": "ENOISSUE"}
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
7bbefe |
session=self.session,
|
|
Pierre-Yves Chibon |
7bbefe |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
7bbefe |
private=False,
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"/api/0/test/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid custom field submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDISSUEFIELD",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Check the behavior if the project disabled the issue tracker
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
7bbefe |
settings = repo.settings
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
"/api/0/test/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 404)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Issue tracker disabled for this project",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "ETRACKERDISABLED",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
7bbefe |
settings = repo.settings
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
headers = {"Authorization": "token foobar"}
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 401)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(data.keys()), ["error", "error_code", "errors"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(pagure.api.APIERROR.EINVALIDTOK.value, data["error"])
|
|
Pierre-Yves Chibon |
20753d |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
pagure.api.APIERROR.EINVALIDTOK.name, data["error_code"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["errors"], "Invalid token")
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Set some custom fields
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.set_custom_key_fields(
|
|
Pierre-Yves Chibon |
73d120 |
self.session,
|
|
Pierre-Yves Chibon |
73d120 |
repo,
|
|
Pierre-Yves Chibon |
73d120 |
["bugzilla", "upstream", "reviewstatus", "duedate"],
|
|
Pierre-Yves Chibon |
73d120 |
["link", "boolean", "list", "date"],
|
|
Pierre-Yves Chibon |
73d120 |
["", "", "ack, nack , needs review", "2018-10-10"],
|
|
Pierre-Yves Chibon |
73d120 |
[None, None, None, None],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
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 |
73d120 |
sorted(key.data), ["ack", "nack", "needs review"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Mark Reynolds |
e18f6c |
|
|
Karsten Hopp |
063ec0 |
# Check that the duedate date field still has its date
|
|
Karsten Hopp |
063ec0 |
if key.name == "duedate":
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(key.data, "2018-10-10")
|
|
Karsten Hopp |
063ec0 |
|
|
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 |
73d120 |
"/api/0/test/issue/1/custom/bugzilla", headers=headers
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
16b189 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"message": "No changes"})
|
|
Pierre-Yves Chibon |
16b189 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
73d120 |
"/api/0/test/issue/1/custom/bugzilla",
|
|
Pierre-Yves Chibon |
73d120 |
headers=headers,
|
|
Pierre-Yves Chibon |
73d120 |
data={"value": "foobar"},
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid custom field submitted, the value is not "
|
|
Pierre-Yves Chibon |
73d120 |
"a link",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDISSUEFIELD_LINK",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
73d120 |
"/api/0/test/issue/1/custom/bugzilla",
|
|
Pierre-Yves Chibon |
73d120 |
headers=headers,
|
|
Pierre-Yves Chibon |
73d120 |
data={"value": "https://bugzilla.redhat.com/1234"},
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "Custom field bugzilla adjusted to "
|
|
Pierre-Yves Chibon |
a18547 |
"https://bugzilla.redhat.com/1234"
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(len(issue.other_fields), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.other_fields[0].key.name, "bugzilla")
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
issue.other_fields[0].value, "https://bugzilla.redhat.com/1234"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Pierre-Yves Chibon |
7bbefe |
# Reset the value
|
|
Pierre-Yves Chibon |
7bbefe |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/custom/bugzilla",
|
|
Pierre-Yves Chibon |
73d120 |
headers=headers,
|
|
Pierre-Yves Chibon |
73d120 |
data={"value": ""},
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
7bbefe |
self.assertDictEqual(
|
|
Pierre-Yves Chibon |
7bbefe |
data,
|
|
Pierre-Yves Chibon |
7bbefe |
{
|
|
Pierre-Yves Chibon |
73d120 |
"message": "Custom field bugzilla reset "
|
|
Pierre-Yves Chibon |
73d120 |
"(from https://bugzilla.redhat.com/1234)"
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
7bbefe |
)
|
|
Pierre-Yves Chibon |
7bbefe |
|
|
Aurélien Bompard |
13bcde |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.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 |
aa57b3 |
@patch(
|
|
Pierre-Yves Chibon |
73d120 |
"pagure.lib.query.set_custom_key_value",
|
|
Pierre-Yves Chibon |
73d120 |
MagicMock(side_effect=pagure.exceptions.PagureException("error")),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
aa57b3 |
def test_api_update_custom_field_raises_error(self):
|
|
Pierre-Yves Chibon |
aa57b3 |
""" Test the api_update_custom_field method of the flask api. """
|
|
Pierre-Yves Chibon |
aa57b3 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "tickets"))
|
|
Pierre-Yves Chibon |
aa57b3 |
tests.create_tokens(self.session)
|
|
Pierre-Yves Chibon |
aa57b3 |
tests.create_tokens_acl(self.session)
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
73d120 |
headers = {"Authorization": "token aaabbbcccddd"}
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
aa57b3 |
# Create normal issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
aa57b3 |
session=self.session,
|
|
Pierre-Yves Chibon |
aa57b3 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #1",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
aa57b3 |
private=False,
|
|
Pierre-Yves Chibon |
aa57b3 |
)
|
|
Pierre-Yves Chibon |
aa57b3 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #1")
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
aa57b3 |
# Set some custom fields
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.set_custom_key_fields(
|
|
Pierre-Yves Chibon |
73d120 |
self.session,
|
|
Pierre-Yves Chibon |
73d120 |
repo,
|
|
Pierre-Yves Chibon |
73d120 |
["bugzilla", "upstream", "reviewstatus"],
|
|
Pierre-Yves Chibon |
73d120 |
["link", "boolean", "list"],
|
|
Pierre-Yves Chibon |
73d120 |
["unused data for non-list type", "", "ack, nack , needs review"],
|
|
Pierre-Yves Chibon |
73d120 |
[None, None, None],
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
aa57b3 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "List of custom fields updated")
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
aa57b3 |
# Check the project custom fields were correctly set
|
|
Pierre-Yves Chibon |
aa57b3 |
for key in repo.issue_keys:
|
|
Pierre-Yves Chibon |
aa57b3 |
# Check that the bugzilla field correctly had its data removed
|
|
Pierre-Yves Chibon |
aa57b3 |
if key.name == "bugzilla":
|
|
Pierre-Yves Chibon |
aa57b3 |
self.assertIsNone(key.data)
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
aa57b3 |
# Check that the reviewstatus list field still has its list
|
|
Pierre-Yves Chibon |
aa57b3 |
elif key.name == "reviewstatus":
|
|
Pierre-Yves Chibon |
aa57b3 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(key.data), ["ack", "nack", "needs review"]
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
aa57b3 |
# Should work but raises an exception
|
|
Pierre-Yves Chibon |
aa57b3 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/api/0/test/issue/1/custom/bugzilla",
|
|
Pierre-Yves Chibon |
73d120 |
headers=headers,
|
|
Pierre-Yves Chibon |
73d120 |
data={"value": "https://bugzilla.redhat.com/1234"},
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
aa57b3 |
self.assertEqual(output.status_code, 400)
|
|
Pierre-Yves Chibon |
aa57b3 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
73d120 |
self.assertDictEqual(data, {"error": "error", "error_code": "ENOCODE"})
|
|
Pierre-Yves Chibon |
aa57b3 |
|
|
Pierre-Yves Chibon |
cd34fb |
def test_api_view_issues_history_stats(self):
|
|
Pierre-Yves Chibon |
cd34fb |
""" Test the api_view_issues_history_stats method of the flask api. """
|
|
Pierre-Yves Chibon |
cd34fb |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
cd34fb |
|
|
Pierre-Yves Chibon |
cd34fb |
# Create private issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
cd34fb |
session=self.session,
|
|
Pierre-Yves Chibon |
cd34fb |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
cd34fb |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
status="Closed",
|
|
Pierre-Yves Chibon |
cd34fb |
)
|
|
Pierre-Yves Chibon |
cd34fb |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
cd34fb |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/test/issues/history/stats")
|
|
Pierre-Yves Chibon |
cd34fb |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
cd34fb |
|
|
Pierre-Yves Chibon |
cd34fb |
self.assertEqual(len(data), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(len(data["stats"]), 53)
|
|
Pierre-Yves Chibon |
73d120 |
last_key = sorted(data["stats"].keys())[-1]
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["stats"][last_key], 0)
|
|
Pierre-Yves Chibon |
73d120 |
for k in sorted(data["stats"].keys())[:-1]:
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["stats"][k], 0)
|
|
Pierre-Yves Chibon |
cd34fb |
|
|
Pierre-Yves Chibon |
9c6ee5 |
def test_api_view_user_issues_pingou(self):
|
|
Pierre-Yves Chibon |
9c6ee5 |
""" Test the api_view_user_issues method of the flask api for pingou.
|
|
Pierre-Yves Chibon |
9c6ee5 |
"""
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
9c6ee5 |
# Create private issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
9c6ee5 |
session=self.session,
|
|
Pierre-Yves Chibon |
9c6ee5 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
9c6ee5 |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
status="Closed",
|
|
Pierre-Yves Chibon |
9c6ee5 |
)
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/pingou/issues")
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
9c6ee5 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": True,
|
|
Aurélien Bompard |
626417 |
"author": True,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"milestones": [],
|
|
Pierre-Yves Chibon |
9c6ee5 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order_key": None,
|
|
Pierre-Yves Chibon |
5241ac |
"page": 1,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"since": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"status": None,
|
|
Pierre-Yves Chibon |
872898 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
}
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_assigned"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(len(data["issues_created"]), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
9c6ee5 |
# Restrict to a certain, fake milestone
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/pingou/issues?milestones=v1.0")
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
9c6ee5 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": True,
|
|
Aurélien Bompard |
626417 |
"author": True,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Pierre-Yves Chibon |
73d120 |
"milestones": ["v1.0"],
|
|
Pierre-Yves Chibon |
9c6ee5 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order_key": None,
|
|
Pierre-Yves Chibon |
5241ac |
"page": 1,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"since": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"status": None,
|
|
Pierre-Yves Chibon |
872898 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
}
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_assigned"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_created"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
9c6ee5 |
# Restrict to a certain status
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/pingou/issues?status=closed")
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
9c6ee5 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": True,
|
|
Aurélien Bompard |
626417 |
"author": True,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"milestones": [],
|
|
Pierre-Yves Chibon |
9c6ee5 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order_key": None,
|
|
Pierre-Yves Chibon |
5241ac |
"page": 1,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "closed",
|
|
Pierre-Yves Chibon |
872898 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
}
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_assigned"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(len(data["issues_created"]), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
9c6ee5 |
# Restrict to a certain status
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/pingou/issues?status=all")
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
9c6ee5 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": True,
|
|
Aurélien Bompard |
626417 |
"author": True,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"milestones": [],
|
|
Pierre-Yves Chibon |
9c6ee5 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"order_key": None,
|
|
Pierre-Yves Chibon |
5241ac |
"page": 1,
|
|
Pierre-Yves Chibon |
9c6ee5 |
"since": None,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "all",
|
|
Pierre-Yves Chibon |
872898 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
}
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_assigned"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(len(data["issues_created"]), 2)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 2)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
9c6ee5 |
def test_api_view_user_issues_foo(self):
|
|
Pierre-Yves Chibon |
9c6ee5 |
""" Test the api_view_user_issues method of the flask api for foo.
|
|
Pierre-Yves Chibon |
9c6ee5 |
"""
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
9c6ee5 |
# Create private issue
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
9c6ee5 |
session=self.session,
|
|
Pierre-Yves Chibon |
9c6ee5 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
9c6ee5 |
private=True,
|
|
Pierre-Yves Chibon |
73d120 |
status="Closed",
|
|
Pierre-Yves Chibon |
9c6ee5 |
)
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/foo/issues")
|
|
Pierre-Yves Chibon |
9c6ee5 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
9c6ee5 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": True,
|
|
Aurélien Bompard |
626417 |
"author": True,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Aurélien Bompard |
626417 |
"milestones": [],
|
|
Aurélien Bompard |
626417 |
"no_stones": None,
|
|
Aurélien Bompard |
626417 |
"order": None,
|
|
Aurélien Bompard |
626417 |
"order_key": None,
|
|
Aurélien Bompard |
626417 |
"page": 1,
|
|
Aurélien Bompard |
626417 |
"since": None,
|
|
Aurélien Bompard |
626417 |
"status": None,
|
|
Aurélien Bompard |
626417 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
9c6ee5 |
}
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(len(data["issues_assigned"]), 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_created"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
5241ac |
|
|
Pierre-Yves Chibon |
5241ac |
def test_api_view_user_issues_foo_invalid_page(self):
|
|
Pierre-Yves Chibon |
5241ac |
""" Test the api_view_user_issues method of the flask api for foo.
|
|
Pierre-Yves Chibon |
5241ac |
"""
|
|
Pierre-Yves Chibon |
5241ac |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
5241ac |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/foo/issues?page=0")
|
|
Pierre-Yves Chibon |
5241ac |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5241ac |
|
|
Pierre-Yves Chibon |
5241ac |
self.assertEqual(
|
|
Pierre-Yves Chibon |
5241ac |
data,
|
|
Pierre-Yves Chibon |
5241ac |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
5241ac |
)
|
|
Pierre-Yves Chibon |
5241ac |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/foo/issues?page=abc")
|
|
Pierre-Yves Chibon |
5241ac |
self.assertEqual(output.status_code, 400)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
5241ac |
|
|
Pierre-Yves Chibon |
5241ac |
self.assertEqual(
|
|
Pierre-Yves Chibon |
5241ac |
data,
|
|
Pierre-Yves Chibon |
5241ac |
{
|
|
Pierre-Yves Chibon |
73d120 |
"error": "Invalid or incomplete input submitted",
|
|
Pierre-Yves Chibon |
73d120 |
"error_code": "EINVALIDREQ",
|
|
Pierre-Yves Chibon |
73d120 |
},
|
|
Pierre-Yves Chibon |
5241ac |
)
|
|
Pierre-Yves Chibon |
9c6ee5 |
|
|
Pierre-Yves Chibon |
738a56 |
def test_api_view_user_issues_foo_no_assignee(self):
|
|
Pierre-Yves Chibon |
738a56 |
""" Test the api_view_user_issues method of the flask api for foo.
|
|
Pierre-Yves Chibon |
738a56 |
"""
|
|
Pierre-Yves Chibon |
738a56 |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
738a56 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/foo/issues?assignee=0")
|
|
Pierre-Yves Chibon |
738a56 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
738a56 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": False,
|
|
Aurélien Bompard |
626417 |
"author": True,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Aurélien Bompard |
626417 |
"milestones": [],
|
|
Aurélien Bompard |
626417 |
"no_stones": None,
|
|
Aurélien Bompard |
626417 |
"order": None,
|
|
Aurélien Bompard |
626417 |
"order_key": None,
|
|
Aurélien Bompard |
626417 |
"page": 1,
|
|
Aurélien Bompard |
626417 |
"since": None,
|
|
Aurélien Bompard |
626417 |
"status": None,
|
|
Aurélien Bompard |
626417 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
738a56 |
}
|
|
Pierre-Yves Chibon |
738a56 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_assigned"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_created"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
738a56 |
|
|
Pierre-Yves Chibon |
738a56 |
def test_api_view_user_issues_pingou_no_author(self):
|
|
Pierre-Yves Chibon |
738a56 |
""" Test the api_view_user_issues method of the flask api for pingou.
|
|
Pierre-Yves Chibon |
738a56 |
"""
|
|
Pierre-Yves Chibon |
738a56 |
self.test_api_new_issue()
|
|
Pierre-Yves Chibon |
738a56 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/api/0/user/pingou/issues?author=0")
|
|
Pierre-Yves Chibon |
738a56 |
self.assertEqual(output.status_code, 200)
|
|
Aurélien Bompard |
626417 |
data = json.loads(output.get_data(as_text=True))
|
|
Pierre-Yves Chibon |
738a56 |
args = {
|
|
Aurélien Bompard |
626417 |
"assignee": True,
|
|
Aurélien Bompard |
626417 |
"author": False,
|
|
Pierre-Yves Chibon |
872898 |
"closed": None,
|
|
Pierre-Yves Chibon |
872898 |
"created": None,
|
|
Pierre-Yves Chibon |
738a56 |
"milestones": [],
|
|
Pierre-Yves Chibon |
738a56 |
"no_stones": None,
|
|
Pierre-Yves Chibon |
738a56 |
"order": None,
|
|
Pierre-Yves Chibon |
738a56 |
"order_key": None,
|
|
Pierre-Yves Chibon |
738a56 |
"page": 1,
|
|
Pierre-Yves Chibon |
738a56 |
"since": None,
|
|
Pierre-Yves Chibon |
738a56 |
"status": None,
|
|
Pierre-Yves Chibon |
872898 |
"tags": [],
|
|
Pierre-Yves Chibon |
872898 |
"updated": None,
|
|
Pierre-Yves Chibon |
738a56 |
}
|
|
Pierre-Yves Chibon |
738a56 |
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["args"], args)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_assigned"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["issues_created"], [])
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created"], 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_assigned_pages"], 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(data["total_issues_created_pages"], 1)
|
|
Pierre-Yves Chibon |
738a56 |
|
|
Pierre-Yves Chibon |
993597 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Aurélien Bompard |
626417 |
SUITE = unittest.TestLoader().loadTestsFromTestCase(
|
|
Pierre-Yves Chibon |
73d120 |
PagureFlaskApiIssuetests
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Aurélien Bompard |
626417 |
unittest.TextTestRunner(verbosity=2).run(SUITE)
|