|
Pierre-Yves Chibon |
3821e6 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
"""
|
|
Pierre-Yves Chibon |
3821e6 |
(c) 2015-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
Authors:
|
|
Pierre-Yves Chibon |
3821e6 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
"""
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
from unittest.case import SkipTest
|
|
Pierre-Yves Chibon |
3821e6 |
import json
|
|
Pierre-Yves Chibon |
3821e6 |
import unittest
|
|
Pierre-Yves Chibon |
3821e6 |
import shutil
|
|
Pierre-Yves Chibon |
3821e6 |
import sys
|
|
Pierre-Yves Chibon |
3821e6 |
import os
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
3821e6 |
try:
|
|
Pierre-Yves Chibon |
3821e6 |
import pyclamd
|
|
Pierre-Yves Chibon |
3821e6 |
except ImportError:
|
|
Pierre-Yves Chibon |
3821e6 |
pyclamd = None
|
|
Pierre-Yves Chibon |
3821e6 |
import six
|
|
Pierre-Yves Chibon |
3821e6 |
import tempfile
|
|
Pierre-Yves Chibon |
3821e6 |
import re
|
|
Pierre-Yves Chibon |
3821e6 |
from datetime import datetime, timedelta
|
|
Pierre-Yves Chibon |
3821e6 |
from six.moves.urllib.parse import urlparse, parse_qs
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
import pygit2
|
|
Pierre-Yves Chibon |
3821e6 |
from bs4 import BeautifulSoup
|
|
Pierre-Yves Chibon |
3821e6 |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
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 |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
import pagure
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
3821e6 |
import tests
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
class PagureFlaskIssuesOpenAccesstests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Tests for flask issues controller of pagure """
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
def setUp(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
3821e6 |
super(PagureFlaskIssuesOpenAccesstests, self).setUp()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
3821e6 |
tests.create_projects_git(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(self.path, "tickets"), bare=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
3821e6 |
settings = repo.settings
|
|
Pierre-Yves Chibon |
73d120 |
settings["open_metadata_access_to_all"] = True
|
|
Pierre-Yves Chibon |
3821e6 |
repo.settings = settings
|
|
Pierre-Yves Chibon |
73d120 |
repo.milestones = {"v1.0": "", "v2.0": "Tomorrow!"}
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_new_issue_with_metadata(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the new_issue endpoint when the user has access to the
|
|
Pierre-Yves Chibon |
3821e6 |
project. """
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/new_issue")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'New Issue\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Tags", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Assignee", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Test issue3",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "We really should improve on this issue\n",
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": "foo",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": "v2.0",
|
|
Pierre-Yves Chibon |
73d120 |
"tag": "tag2",
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/new_issue", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue3 - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
'href="/test/issue/1/edit" title="Edit this issue">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# Check the metadata
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'title="comma separated list of tags"\n '
|
|
Pierre-Yves Chibon |
73d120 |
'value="tag2" />',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'placeholder="username"\n value="foo" />\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn('href="/test/roadmap/v2.0/"', output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_new_issue_with_metadata_not_user(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the new_issue endpoint when the user does not have access
|
|
Pierre-Yves Chibon |
3821e6 |
to the project but still tries to.
|
|
Pierre-Yves Chibon |
3821e6 |
"""
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/new_issue")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'New Issue\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Tags", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Assignee", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"title": "Test issue3",
|
|
Pierre-Yves Chibon |
73d120 |
"issue_content": "We really should improve on this issue\n",
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Open",
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": "foo",
|
|
Pierre-Yves Chibon |
73d120 |
"milestone": "v2.0",
|
|
Pierre-Yves Chibon |
73d120 |
"tag": "tag2",
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/new_issue", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue3 - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
'href="/test/issue/1/edit" title="Edit this issue">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# Check the metadata
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'title="comma separated list of tags"\n '
|
|
Pierre-Yves Chibon |
73d120 |
'value="tag2" />',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'placeholder="username"\n value="foo" />\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
''
|
|
Pierre-Yves Chibon |
73d120 |
"\n "
|
|
Pierre-Yves Chibon |
3821e6 |
'\n '
|
|
Pierre-Yves Chibon |
73d120 |
"\n v2.0\n",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_view_issue(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the view_issue endpoint. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
# Not authentified = No edit
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
'href="/test/issue/1/edit" title="Edit this issue">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
''
|
|
Pierre-Yves Chibon |
73d120 |
"Login\n to comment on this ticket.",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
# Not author nor admin = No edit
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' title="Delete this ticket">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
3821e6 |
'Login to comment on this ticket.'
|
|
Pierre-Yves Chibon |
73d120 |
in output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# Not author nor admin but open_access = take
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("function take_issue(){", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertNotIn("function drop_issue(){", output_text)
|
|
Julen Landa Alustiza |
0cafab |
self.assertIn('
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# 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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
private=True,
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Not logged in
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/2")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Wrong user
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/2")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# another user
|
|
Pierre-Yves Chibon |
73d120 |
user.username = "foo"
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/2")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Project w/o issue tracker
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.settings = {"issue_tracker": False}
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_view_issue_user_ticket(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the view_issue endpoint. """
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
# Not authentified = No edit
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
'href="/test/issue/1/edit" title="Edit this issue">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertTrue(
|
|
Pierre-Yves Chibon |
3821e6 |
''
|
|
Pierre-Yves Chibon |
73d120 |
"Login\n to comment on this ticket." in output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add user 'foo' with ticket access on repo
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.add_user_to_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, repo, new_user="foo", user="pingou", access="ticket"
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "User added")
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
# Not author nor admin = No edit
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' title="Delete this ticket">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
3821e6 |
'Login to comment on this ticket.'
|
|
Pierre-Yves Chibon |
73d120 |
in output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# user has ticket = take ok
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("function take_issue(){", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("function drop_issue(){", output_text)
|
|
Julen Landa Alustiza |
0cafab |
self.assertIn('
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_view_issue_custom_field_user_ticket(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the view_issue endpoint. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add user 'foo' with ticket access on repo
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.add_user_to_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, repo, new_user="foo", user="pingou", access="ticket"
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "User added")
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# 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 |
3821e6 |
self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "List of custom fields updated")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# User with no rights
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' title="Delete this ticket">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# user no ACLs but open_access = take action/button - no drop
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("function take_issue(){", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertNotIn("function drop_issue(){", output_text)
|
|
Julen Landa Alustiza |
0cafab |
self.assertIn('
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# user no ACLs = no metadata form
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
'name="bugzilla" id="bugzilla"/>',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
'id="reviewstatus>',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
'class="form-control" name="upstream" id="upstream"/>',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' title="Delete this ticket">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'Login to comment on this ticket.',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# user has ticket = take ok
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("function take_issue(){", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("function drop_issue(){", output_text)
|
|
Julen Landa Alustiza |
0cafab |
self.assertIn('
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# user has ticket == Sees the metadata
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
'name="bugzilla" id="bugzilla"/>',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' name="reviewstatus"\n'
|
|
Pierre-Yves Chibon |
3821e6 |
' id="reviewstatus">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
'class="form-control" name="upstream" id="upstream"/>',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_view_issue_non_ascii_milestone(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the view_issue endpoint with non-ascii milestone. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
stone = "käpy"
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add a non-ascii milestone to the issue but project has no milestone
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
930073 |
message = pagure.lib.query.edit_issue(
|
|
Pierre-Yves Chibon |
3821e6 |
self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
issue=issue,
|
|
Pierre-Yves Chibon |
3821e6 |
milestone=stone,
|
|
Pierre-Yves Chibon |
3821e6 |
private=False,
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(message, ["Issue set to the milestone: k\xe4py"])
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# View the issue
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>", output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(stone, output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_view_issue_list_no_data(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the view_issue endpoint when the issue has a custom field
|
|
Pierre-Yves Chibon |
3821e6 |
of type list with no data attached. """
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add custom fields to the project
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.set_custom_key_fields(
|
|
Pierre-Yves Chibon |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
project=repo,
|
|
Pierre-Yves Chibon |
73d120 |
fields=["test1"],
|
|
Pierre-Yves Chibon |
73d120 |
types=["list"],
|
|
Pierre-Yves Chibon |
3821e6 |
data=[None],
|
|
Pierre-Yves Chibon |
73d120 |
notify=[None],
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "List of custom fields updated")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.new_issue(
|
|
Pierre-Yves Chibon |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Big problÈm!",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this",
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Big problÈm!")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Assign a value to the custom key on that ticket
|
|
Pierre-Yves Chibon |
930073 |
cfield = pagure.lib.query.get_custom_key(
|
|
Pierre-Yves Chibon |
73d120 |
session=self.session, project=repo, keyname="test1"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
930073 |
msg = pagure.lib.query.set_custom_key_value(
|
|
Pierre-Yves Chibon |
73d120 |
session=self.session, issue=msg, key=cfield, value="item"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg, "Custom field test1 adjusted to item")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_update_issue(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the update_issue endpoint. """
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1/update")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 302)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output_text.count('title="PY C (pingou)"'), 1)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
data = {"status": "Closed", "close_status": "fixed"}
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Invalid repo
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/bar/issue/1/update", data=data)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Non-existing issue
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/test/issue/100/update", data=data)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>' in output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Right status, wrong csrf
|
|
Pierre-Yves Chibon |
73d120 |
data["close_status"] = "Fixed"
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertFalse(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>' in output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# status update - blocked, open_access doesn't allow changing status
|
|
Pierre-Yves Chibon |
73d120 |
data["csrf_token"] = csrf_token
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Issue close_status updated to: Fixed", output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Issue status updated to: Closed (was: Open)", output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add new comment
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Fixed",
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "Woohoo a second comment!",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment added", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertNotIn("No changes to edit", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Woohoo a second comment! ", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(output_text.count('comment_body">'), 2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
# 1: one for the original comment
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(output_text.count('title="PY C (pingou)"'), 1)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add new tag
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Fixed",
|
|
Pierre-Yves Chibon |
73d120 |
"tag": "tag2",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Woohoo a second comment! ", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(output_text.count('comment_body">'), 2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Assign issue to an non-existent user
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Fixed",
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": "ralph",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("No user "ralph" found", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Woohoo a second comment! ", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(output_text.count('comment_body">'), 2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Assign issue properly
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Fixed",
|
|
Pierre-Yves Chibon |
73d120 |
"assignee": "pingou",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Issue assigned to pingou", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Woohoo a second comment! ", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(output_text.count('comment_body">'), 2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create another issue with a dependency
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Reset the status of the first issue
|
|
Pierre-Yves Chibon |
930073 |
parent_issue = pagure.lib.query.search_issues(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, repo, issueid=1
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
parent_issue.status = "Open"
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.add(parent_issue)
|
|
Pierre-Yves Chibon |
3821e6 |
# Add the dependency relationship
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.add(parent_issue)
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
|
|
Pierre-Yves Chibon |
3821e6 |
issue.parents.append(parent_issue)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.add(issue)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
data["csrf_token"] = csrf_token
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/2/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #2: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/2/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
"You cannot close a ticket "
|
|
Pierre-Yves Chibon |
73d120 |
"that has ticket depending that are still open.",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Open">Open</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# 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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
private=True,
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Wrong user
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/3/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Project w/o issue tracker
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
73d120 |
repo.settings = {"issue_tracker": False}
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.add(repo)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3821e6 |
# Repo not set-up for issue tracker
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.post("/test/issue/1/update", data=data)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_update_issue_depend(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test adding dependency via the update_issue endpoint. """
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this again",
|
|
Pierre-Yves Chibon |
73d120 |
user="foo",
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #2")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add a dependent ticket
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "depending": "2"}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add an invalid dependent ticket
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "depending": "2,abc"}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertNotIn("Successfully edited issue #1", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
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 |
3821e6 |
self.assertEqual(issue.depending_text, [2])
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(issue.blocking_text, [])
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_update_issue_block(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test adding blocked issue via the update_issue endpoint. """
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
repo=repo,
|
|
Pierre-Yves Chibon |
73d120 |
title="Test issue #2",
|
|
Pierre-Yves Chibon |
73d120 |
content="We should work on this again",
|
|
Pierre-Yves Chibon |
73d120 |
user="foo",
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue #2")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# User is not an admin of the project
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add a dependent ticket
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "blocking": "2"}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
repo = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
issue = pagure.lib.query.search_issues(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, repo, issueid=1
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(issue.depending_text, [])
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(issue.blocking_text, [2])
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add an invalid dependent ticket
|
|
Pierre-Yves Chibon |
73d120 |
data = {"csrf_token": csrf_token, "blocking": "2,abc"}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertNotIn("Successfully edited issue #1", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
self.assertEqual(issue.depending_text, [])
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(issue.blocking_text, [2])
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_update_issue_edit_comment(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test the issues edit comment endpoint """
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' href="/test/issue/1/edit" title="Edit this issue">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add new comment
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "Woohoo a second comment!",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
3821e6 |
' href="/test/issue/1/edit" title="Edit this issue">\n',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment added", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Woohoo a second comment! ", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(output_text.count('comment_body">'), 2)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
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 |
3821e6 |
self.assertEqual(len(issue.comments), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.comments[0].comment, "Woohoo a second comment!")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"edit_comment": 1,
|
|
Pierre-Yves Chibon |
73d120 |
"update_comment": "Updated comment",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser()
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3821e6 |
# Wrong issue id
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/3/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 404)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Wrong user
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 403)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3821e6 |
# Edit comment
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment updated", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
self.assertEqual(len(issue.comments), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.comments[0].comment, "Updated comment")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1/comment/1/edit")
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("<title>test - Pagure</title>", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertTrue('' in output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertTrue('<section class="edit_comment">' in output_text)</section>
|
|
Pierre-Yves Chibon |
aede19 |
self.assertIn(
|
|
Pierre-Yves Chibon |
aede19 |
'
|
|
Julen Landa Alustiza |
0cafab |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
data["csrf_token"] = csrf_token
|
|
Pierre-Yves Chibon |
73d120 |
data["update_comment"] = "Second update"
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Edit the comment with the other endpoint
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/comment/1/edit",
|
|
Pierre-Yves Chibon |
3821e6 |
data=data,
|
|
Pierre-Yves Chibon |
73d120 |
follow_redirects=True,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment updated", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
self.assertEqual(len(issue.comments), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.comments[0].comment, "Second update")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Create another issue from someone else
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(len(issue.comments), 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.status, "Open")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(len(issue.comments), 0)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.status, "Open")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "Nevermind figured it out",
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Invalid",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add a comment and close the ticket #1
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertNotIn("Successfully edited issue #1\n", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment added", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
aede19 |
'
|
|
Julen Landa Alustiza |
0cafab |
"issue-metadata-display editmetadatatoggle pointer inline-block"
|
|
Pierre-Yves Chibon |
aede19 |
'">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "Nevermind figured it out",
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Invalid",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add a comment and close the ticket #2
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/2/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Issue close_status updated to: Invalid", output_text
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment added", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"Issue status updated to: Closed (was: Open)", output_text
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
aede19 |
'
|
|
Julen Landa Alustiza |
0cafab |
"issue-metadata-display editmetadatatoggle pointer inline-block"
|
|
Pierre-Yves Chibon |
aede19 |
'">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Ticket #1 has one more comment and is still open
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=1)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(len(issue.comments), 2)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.status, "Open")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Ticket #2 has one less comment and is closed
|
|
Pierre-Yves Chibon |
930073 |
issue = pagure.lib.query.search_issues(self.session, repo, issueid=2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(len(issue.comments), 2)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.comments[0].comment, "Nevermind figured it out")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
3821e6 |
issue.comments[1].comment,
|
|
Pierre-Yves Chibon |
73d120 |
"**Metadata Update from @foo**:\n"
|
|
Pierre-Yves Chibon |
73d120 |
"- Issue close_status updated to: Invalid\n"
|
|
Pierre-Yves Chibon |
73d120 |
"- Issue status updated to: Closed (was: Open)",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(issue.status, "Closed")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.update_git", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
3821e6 |
def test_view_issue_closed(self):
|
|
Pierre-Yves Chibon |
3821e6 |
""" Test viewing a closed issue. """
|
|
Pierre-Yves Chibon |
3821e6 |
# Create issues to play with
|
|
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 |
3821e6 |
session=self.session,
|
|
Pierre-Yves Chibon |
3821e6 |
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 |
3821e6 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.session.commit()
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(msg.title, "Test issue")
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
3821e6 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/issue/1")
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
csrf_token = self.get_csrf(output=output)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
# Add new comment
|
|
Pierre-Yves Chibon |
3821e6 |
data = {
|
|
Pierre-Yves Chibon |
73d120 |
"csrf_token": csrf_token,
|
|
Pierre-Yves Chibon |
73d120 |
"status": "Closed",
|
|
Pierre-Yves Chibon |
73d120 |
"close_status": "Fixed",
|
|
Pierre-Yves Chibon |
73d120 |
"comment": "Woohoo a second comment!",
|
|
Pierre-Yves Chibon |
3821e6 |
}
|
|
Pierre-Yves Chibon |
3821e6 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/test/issue/1/update", data=data, follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
3821e6 |
output_text = output.get_data(as_text=True)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"<title>Issue #1: Test issue - test - Pagure</title>",
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
3821e6 |
'
|
|
Pierre-Yves Chibon |
73d120 |
' href="/test/issue/1/edit" title="Edit this issue">',
|
|
Pierre-Yves Chibon |
73d120 |
output_text,
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Comment added", output_text)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertIn("Woohoo a second comment! ", output_text)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertEqual(output_text.count('comment_body">'), 2)
|
|
Pierre-Yves Chibon |
3821e6 |
self.assertNotIn(
|
|
Pierre-Yves Chibon |
73d120 |
'<option selected="" value="Fixed">Fixed</option>', output_text
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
3821e6 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
3821e6 |
unittest.main(verbosity=2)
|