Blame tests/test_pagure_flask_ui_issues_open_access.py

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 3821e6
from __future__ import unicode_literals
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 3821e6
import pkg_resources
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 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 3821e6
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 3821e6
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
import pagure
Pierre-Yves Chibon 3821e6
import pagure.lib
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 3821e6
        tests.create_projects_git(
Pierre-Yves Chibon 3821e6
            os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 3821e6
        tests.create_projects_git(
Pierre-Yves Chibon 3821e6
            os.path.join(self.path, 'tickets'), bare=True)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        settings = repo.settings
Pierre-Yves Chibon 3821e6
        settings['open_metadata_access_to_all'] = True
Pierre-Yves Chibon 3821e6
        repo.settings = settings
Pierre-Yves Chibon 3821e6
        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 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        user.username = 'foo'
Pierre-Yves Chibon 3821e6
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 3821e6
            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 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Tags', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '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 3821e6
                    'title': 'Test issue3',
Pierre-Yves Chibon 3821e6
                    'issue_content': 'We really should improve on this issue\n',
Pierre-Yves Chibon 3821e6
                    'status': 'Open',
Pierre-Yves Chibon 3821e6
                    'assignee': 'foo',
Pierre-Yves Chibon 3821e6
                    'milestone': 'v2.0',
Pierre-Yves Chibon 3821e6
                    'tag': 'tag2',
Pierre-Yves Chibon 3821e6
                    'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                }
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/new_issue', data=data, follow_redirects=True)
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 3821e6
                '<title>Issue #1: Test issue3 - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
                output_text)
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 3821e6
                'value="tag2" />', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                'placeholder="username"\n              value="foo" />\n',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                'href="/test/roadmap/v2.0/"',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        user.username = 'foo'
Pierre-Yves Chibon 3821e6
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 3821e6
            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 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Tags', output_text)
Pierre-Yves Chibon 3821e6
            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 3821e6
                    'title': 'Test issue3',
Pierre-Yves Chibon 3821e6
                    'issue_content': 'We really should improve on this issue\n',
Pierre-Yves Chibon 3821e6
                    'status': 'Open',
Pierre-Yves Chibon 3821e6
                    'assignee': 'foo',
Pierre-Yves Chibon 3821e6
                    'milestone': 'v2.0',
Pierre-Yves Chibon 3821e6
                    'tag': 'tag2',
Pierre-Yves Chibon 3821e6
                    'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                }
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/new_issue', data=data, follow_redirects=True)
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 3821e6
                '<title>Issue #1: Test issue3 - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
                output_text)
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 3821e6
                'value="tag2" />', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                'placeholder="username"\n              value="foo" />\n',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
'
Pierre-Yves Chibon 3821e6
                '\n              '
Pierre-Yves Chibon 3821e6
                '\n                '
Pierre-Yves Chibon 3821e6
                '\n                  v2.0\n', output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        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 3821e6
            output_text)
Pierre-Yves Chibon 3821e6
        self.assertIn(
Pierre-Yves Chibon 3821e6
            ''
Pierre-Yves Chibon 3821e6
            'Login\n          to comment on this ticket.',
Pierre-Yves Chibon 3821e6
            output_text)
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
            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 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertFalse(
Pierre-Yves Chibon 3821e6
                'Login to comment on this ticket.'
Pierre-Yves Chibon 3821e6
                in output_text)
Pierre-Yves Chibon 3821e6
            # Not author nor admin but open_access = take
Pierre-Yves Chibon 3821e6
            self.assertIn('function take_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn('function drop_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                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
        # Create private issue
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
            private=True,
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Not logged in
Pierre-Yves Chibon 3821e6
        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 3821e6
            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 3821e6
        user.username = 'foo'
Pierre-Yves Chibon 3821e6
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 3821e6
            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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        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
        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
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        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 3821e6
            output_text)
Pierre-Yves Chibon 3821e6
        self.assertTrue(
Pierre-Yves Chibon 3821e6
            ''
Pierre-Yves Chibon 3821e6
            'Login\n          to comment on this ticket.'
Pierre-Yves Chibon 3821e6
            in output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Create issues to play with
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.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 3821e6
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 3821e6
            self.session,
Pierre-Yves Chibon 3821e6
            repo,
Pierre-Yves Chibon 3821e6
            new_user='foo',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
            access='ticket',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 3821e6
        self.session.commit()
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
            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 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertFalse(
Pierre-Yves Chibon 3821e6
                'Login to comment on this ticket.'
Pierre-Yves Chibon 3821e6
                in output_text)
Pierre-Yves Chibon 3821e6
            # user has ticket = take ok
Pierre-Yves Chibon 3821e6
            self.assertIn('function take_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('function drop_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 3821e6
            self.session,
Pierre-Yves Chibon 3821e6
            repo,
Pierre-Yves Chibon 3821e6
            new_user='foo',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
            access='ticket',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.set_custom_key_fields(
Pierre-Yves Chibon 3821e6
            self.session,
Pierre-Yves Chibon 3821e6
            repo,
Pierre-Yves Chibon 3821e6
            ['bugzilla', 'upstream', 'reviewstatus'],
Pierre-Yves Chibon 3821e6
            ['link', 'boolean', 'list'],
Pierre-Yves Chibon 3821e6
            ['unused data for non-list type', '', 'ack, nack ,  needs review'],
Pierre-Yves Chibon 3821e6
            [None, None, None])
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        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 3821e6
            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 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            # user no ACLs but open_access = take action/button - no drop
Pierre-Yves Chibon 3821e6
            self.assertIn('function take_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn('function drop_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
                'name="bugzilla" id="bugzilla"/>', output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                'id="reviewstatus>', output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                'class="form-control" name="upstream" id="upstream"/>',
Pierre-Yves Chibon 3821e6
                output_text)
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
            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 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                '                title="Delete this ticket">\n',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'Login to comment on this ticket.',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            # user has ticket = take ok
Pierre-Yves Chibon 3821e6
            self.assertIn('function take_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('function drop_issue(){', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
                'name="bugzilla" id="bugzilla"/>', output_text)
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 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                'class="form-control" name="upstream" id="upstream"/>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        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
        stone = 'käpy'
Pierre-Yves Chibon 3821e6
        # Create issues to play with
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        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 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        message = pagure.lib.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 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.assertEqual(
Pierre-Yves Chibon 3821e6
            message,
Pierre-Yves Chibon 3821e6
            [
Pierre-Yves Chibon 3821e6
                'Issue set to the milestone: k\xe4py'
Pierre-Yves Chibon 3821e6
            ]
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # View the issue
Pierre-Yves Chibon 3821e6
        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 3821e6
            '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
            output_text)
Pierre-Yves Chibon 3821e6
        self.assertIn(stone, output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Add custom fields to the project
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.set_custom_key_fields(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            project=repo,
Pierre-Yves Chibon 3821e6
            fields=['test1'],
Pierre-Yves Chibon 3821e6
            types=['list'],
Pierre-Yves Chibon 3821e6
            data=[None],
Pierre-Yves Chibon 3821e6
            notify=[None]
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg, 'List of custom fields updated')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Create issues to play with
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Big problÈm!',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        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 3821e6
        cfield = pagure.lib.get_custom_key(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            project=repo,
Pierre-Yves Chibon 3821e6
            keyname='test1')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.set_custom_key_value(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            issue=msg,
Pierre-Yves Chibon 3821e6
            key=cfield,
Pierre-Yves Chibon 3821e6
            value='item')
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg, 'Custom field test1 adjusted to item')
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
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 3821e6
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
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
            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 3821e6
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                'close_status': 'fixed'
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Invalid repo
Pierre-Yves Chibon 3821e6
            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 3821e6
            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 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertFalse(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 3821e6
                in output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Right status, wrong csrf
Pierre-Yves Chibon 3821e6
            data['close_status'] = 'Fixed'
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertFalse(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 3821e6
                in output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # status update - blocked, open_access doesn't allow changing status
Pierre-Yves Chibon 3821e6
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'Issue close_status updated to: Fixed',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'Issue status updated to: Closed (was: Open)',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Add new comment
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                'close_status': 'Fixed',
Pierre-Yves Chibon 3821e6
                'comment': 'Woohoo a second comment!',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                'Comment added',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'No changes to edit',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '

Woohoo a second comment!

',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertEqual(
Pierre-Yves Chibon 3821e6
                output_text.count('comment_body">'), 2)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            # 1: one for the original comment
Pierre-Yves Chibon 3821e6
            self.assertEqual(
Pierre-Yves Chibon 3821e6
                output_text.count('title="PY C (pingou)"'),
Pierre-Yves Chibon 3821e6
                1)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Add new tag
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                'close_status': 'Fixed',
Pierre-Yves Chibon 3821e6
                'tag': 'tag2',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '

Woohoo a second comment!

',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertEqual(
Pierre-Yves Chibon 3821e6
                output_text.count('comment_body">'), 2)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Assign issue to an non-existent user
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                'close_status': 'Fixed',
Pierre-Yves Chibon 3821e6
                'assignee': 'ralph',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                'No user "ralph" found',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '

Woohoo a second comment!

',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertEqual(
Pierre-Yves Chibon 3821e6
                output_text.count('comment_body">'), 2)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Assign issue properly
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                'close_status': 'Fixed',
Pierre-Yves Chibon 3821e6
                'assignee': 'pingou',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Issue assigned to pingou', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '

Woohoo a second comment!

', output_text)
Pierre-Yves Chibon 3821e6
            self.assertEqual(
Pierre-Yves Chibon 3821e6
                output_text.count('comment_body">'), 2)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Fixed">Fixed</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Create another issue with a dependency
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Reset the status of the first issue
Pierre-Yves Chibon 3821e6
        parent_issue = pagure.lib.search_issues(
Pierre-Yves Chibon 3821e6
            self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        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 3821e6
        issue = pagure.lib.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 3821e6
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/2/update', data=data, follow_redirects=True)
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
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/2/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'You cannot close a ticket '
Pierre-Yves Chibon 3821e6
                'that has ticket depending that are still open.',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '<option selected="" value="Open">Open</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        # Create private issue
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
            private=True,
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        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 3821e6
                '/test/issue/3/update', data=data, follow_redirects=True)
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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        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 3821e6
            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 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue #2',
Pierre-Yves Chibon 3821e6
            content='We should work on this again',
Pierre-Yves Chibon 3821e6
            user='foo',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue #2')
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
            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 3821e6
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                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
            # Add a dependent ticket
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'depending': '2',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            # Add an invalid dependent ticket
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'depending': '2,abc',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'Successfully edited issue #1',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.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 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue #2',
Pierre-Yves Chibon 3821e6
            content='We should work on this again',
Pierre-Yves Chibon 3821e6
            user='foo',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        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 3821e6
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon 3821e6
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 3821e6
            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 3821e6
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output.get_data(as_text=True))
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 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'blocking': '2',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 3821e6
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output.get_data(as_text=True))
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
            issue = pagure.lib.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 3821e6
            # Add an invalid dependent ticket
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'blocking': '2,abc',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                'Successfully edited issue #1',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.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 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
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
            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 3821e6
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
                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
            # Add new comment
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'comment': 'Woohoo a second comment!',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
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 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Comment added', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '

Woohoo a second comment!

',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertEqual(
Pierre-Yves Chibon 3821e6
                output_text.count('comment_body">'), 2)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(
Pierre-Yves Chibon 3821e6
            issue.comments[0].comment,
Pierre-Yves Chibon 3821e6
            'Woohoo a second comment!')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        data = {
Pierre-Yves Chibon 3821e6
            'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
            'edit_comment': 1,
Pierre-Yves Chibon 3821e6
            '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 3821e6
                '/test/issue/3/update', data=data, follow_redirects=True)
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 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 3821e6
            self.assertEqual(output.status_code, 403)
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
            # Edit comment
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Comment updated', output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon 3821e6
        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 3821e6
            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 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '<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 3821e6
            self.assertTrue(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                in 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['csrf_token'] = csrf_token
Pierre-Yves Chibon 3821e6
            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 3821e6
                '/test/issue/1/comment/1/edit',
Pierre-Yves Chibon 3821e6
                data=data,
Pierre-Yves Chibon 3821e6
                follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Comment updated', output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon 3821e6
        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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='foo',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(issue.status, 'Open')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 0)
Pierre-Yves Chibon 3821e6
        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 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'comment': 'Nevermind figured it out',
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                '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 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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('Successfully edited issue #1\n', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Comment added', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Pierre-Yves Chibon 3821e6
                '',
Pierre-Yves Chibon 3821e6
                output_text
Pierre-Yves Chibon 3821e6
            )
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'comment': 'Nevermind figured it out',
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                '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 3821e6
                '/test/issue/2/update', data=data, follow_redirects=True)
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
                'Issue close_status updated to: Invalid',
Pierre-Yves Chibon 3821e6
                output_text
Pierre-Yves Chibon 3821e6
            )
Pierre-Yves Chibon 3821e6
            self.assertIn('Comment added', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                'Issue status updated to: Closed (was: Open)',
Pierre-Yves Chibon 3821e6
                output_text
Pierre-Yves Chibon 3821e6
            )
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                ' editmetadatatoggle" href="javascript:void(0)" style="display: inline-block;">'
Pierre-Yves Chibon 3821e6
                '',
Pierre-Yves Chibon 3821e6
                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 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 2)
Pierre-Yves Chibon 3821e6
        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 3821e6
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 3821e6
        self.assertEqual(len(issue.comments), 2)
Pierre-Yves Chibon 3821e6
        self.assertEqual(
Pierre-Yves Chibon 3821e6
            issue.comments[0].comment,
Pierre-Yves Chibon 3821e6
            'Nevermind figured it out')
Pierre-Yves Chibon 3821e6
        self.assertEqual(
Pierre-Yves Chibon 3821e6
            issue.comments[1].comment,
Pierre-Yves Chibon 3821e6
            '**Metadata Update from @foo**:\n'
Pierre-Yves Chibon 3821e6
            '- Issue close_status updated to: Invalid\n'
Pierre-Yves Chibon 3821e6
            '- Issue status updated to: Closed (was: Open)')
Pierre-Yves Chibon 3821e6
        self.assertEqual(issue.status, 'Closed')
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 3821e6
    @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 3821e6
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3821e6
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3821e6
            session=self.session,
Pierre-Yves Chibon 3821e6
            repo=repo,
Pierre-Yves Chibon 3821e6
            title='Test issue',
Pierre-Yves Chibon 3821e6
            content='We should work on this',
Pierre-Yves Chibon 3821e6
            user='pingou',
Pierre-Yves Chibon 3821e6
        )
Pierre-Yves Chibon 3821e6
        self.session.commit()
Pierre-Yves Chibon 3821e6
        self.assertEqual(msg.title, 'Test issue')
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
            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 3821e6
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                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
            # Add new comment
Pierre-Yves Chibon 3821e6
            data = {
Pierre-Yves Chibon 3821e6
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3821e6
                'status': 'Closed',
Pierre-Yves Chibon 3821e6
                'close_status': 'Fixed',
Pierre-Yves Chibon 3821e6
                'comment': 'Woohoo a second comment!',
Pierre-Yves Chibon 3821e6
            }
Pierre-Yves Chibon 3821e6
            output = self.app.post(
Pierre-Yves Chibon 3821e6
                '/test/issue/1/update', data=data, follow_redirects=True)
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
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertNotIn(
Pierre-Yves Chibon 3821e6
                '
Pierre-Yves Chibon 3821e6
                 ' href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn('Comment added', output_text)
Pierre-Yves Chibon 3821e6
            self.assertIn(
Pierre-Yves Chibon 3821e6
                '

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 3821e6
                '<option selected="" value="Fixed">Fixed</option>',
Pierre-Yves Chibon 3821e6
                output_text)
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
Pierre-Yves Chibon 3821e6
if __name__ == '__main__':
Pierre-Yves Chibon 3821e6
    unittest.main(verbosity=2)