Blame tests/test_pagure_flask_ui_issues.py

Pierre-Yves Chibon a52cca
# -*- coding: utf-8 -*-
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
"""
Pierre-Yves Chibon 2fa745
 (c) 2015-2017 - Copyright Red Hat Inc
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
 Authors:
Pierre-Yves Chibon a52cca
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
"""
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon a52cca
import pkg_resources
Pierre-Yves Chibon a52cca
Patrick Uiterwijk 198c68
from unittest.case import SkipTest
Pierre-Yves Chibon a52cca
import json
Pierre-Yves Chibon a52cca
import unittest
Pierre-Yves Chibon a52cca
import shutil
Pierre-Yves Chibon a52cca
import sys
Pierre-Yves Chibon a52cca
import os
Patrick Uiterwijk 198c68
try:
Patrick Uiterwijk 198c68
    import pyclamd
Patrick Uiterwijk 198c68
except:
Patrick Uiterwijk 198c68
    pyclamd = None
Patrick Uiterwijk 78afb3
import tempfile
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
import pygit2
Pierre-Yves Chibon a52cca
from mock import patch
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon a52cca
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon fe5017
import pagure.lib
Pierre-Yves Chibon a52cca
import tests
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon fe5017
class PagureFlaskIssuestests(tests.Modeltests):
Pierre-Yves Chibon fe5017
    """ Tests for flask issues controller of pagure """
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
    def setUp(self):
Pierre-Yves Chibon a52cca
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon fe5017
        super(PagureFlaskIssuestests, self).setUp()
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon fe5017
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon a3f29c
        # TODO: Figure a way to enable this test on jenkins
Pierre-Yves Chibon a3f29c
        if not os.environ.get('BUILD_ID'):
Pierre-Yves Chibon a3f29c
            pagure.APP.config['VIRUS_SCAN_ATTACHMENTS'] = True
Pierre-Yves Chibon fe5017
        pagure.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.issues.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 9fae46
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon a52cca
Jeremy Cline 20109f
        pagure.APP.config['GIT_FOLDER'] = self.path
Pierre-Yves Chibon fe5017
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'tickets')
Pierre-Yves Chibon fe5017
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'docs')
Pierre-Yves Chibon fe5017
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon a52cca
    def test_new_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon a52cca
        """ Test the new_issue endpoint. """
Pierre-Yves Chibon a52cca
        p_send_email.return_value = True
Pierre-Yves Chibon a52cca
        p_ugt.return_value = True
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon dec404
        # No Git repo
Pierre-Yves Chibon a52cca
        output = self.app.get('/foo/new_issue')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon a52cca
            output = self.app.get('/foo/new_issue')
Pierre-Yves Chibon a52cca
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
            tests.create_projects_git(
Jeremy Cline 20109f
                os.path.join(self.path), bare=True)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon a52cca
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n New issue'
Pierre-Yves Chibon 1a43f3
                in output.data)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            csrf_token = output.data.split(
Pierre-Yves Chibon a52cca
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            data = {
Pierre-Yves Chibon a52cca
            }
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            # Insufficient input
Pierre-Yves Chibon a52cca
            output = self.app.post('/test/new_issue', data=data)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n New issue'
Pierre-Yves Chibon 1a43f3
                in output.data)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 51f121
                'This field is required.'), 2)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            data['title'] = 'Test issue'
Pierre-Yves Chibon a52cca
            output = self.app.post('/test/new_issue', data=data)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n New issue'
Pierre-Yves Chibon 1a43f3
                in output.data)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 51f121
                'This field is required.'), 1)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            data['issue_content'] = 'We really should improve on this issue'
Pierre-Yves Chibon a52cca
            data['status'] = 'Open'
Pierre-Yves Chibon a52cca
            output = self.app.post('/test/new_issue', data=data)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n New issue'
Pierre-Yves Chibon 1a43f3
                in output.data)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 45cb3d
                '\n                      This field is required.'),
Pierre-Yves Chibon 45cb3d
                0)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
            # Invalid user
Pierre-Yves Chibon a52cca
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon a52cca
            output = self.app.post('/test/new_issue', data=data)
Pierre-Yves Chibon 5e3437
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5e3437
            self.assertIn(
Pierre-Yves Chibon 5e3437
                '

No such user found in the database: username

',
Pierre-Yves Chibon 5e3437
                output.data)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon dec404
        # User not logged in
Pierre-Yves Chibon dec404
        output = self.app.get('/test/new_issue')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon dec404
Pierre-Yves Chibon a52cca
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon a52cca
            output = self.app.post(
Pierre-Yves Chibon a52cca
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon a52cca
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon 9e69c0
        # Project w/o issue tracker
Pierre-Yves Chibon 9e69c0
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 9e69c0
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 9e69c0
        self.session.add(repo)
Pierre-Yves Chibon 9e69c0
        self.session.commit()
Pierre-Yves Chibon 9e69c0
Pierre-Yves Chibon 9e69c0
        user.username = 'pingou'
Pierre-Yves Chibon 9e69c0
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 9e69c0
            output = self.app.post(
Pierre-Yves Chibon 9e69c0
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 9e69c0
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 9e69c0
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 272d30
    def test_new_issue_w_file(self, p_send_email, p_ugt):
Pierre-Yves Chibon 272d30
        """ Test the new_issue endpoint with a file. """
Pierre-Yves Chibon 272d30
        p_send_email.return_value = True
Pierre-Yves Chibon 272d30
        p_ugt.return_value = True
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
        tests.create_projects(self.session)
Pierre-Yves Chibon 272d30
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path, 'tickets'), bare=True)
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
        user = tests.FakeUser()
Pierre-Yves Chibon 272d30
        user.username = 'pingou'
Pierre-Yves Chibon 272d30
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 272d30
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon 272d30
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n New issue'
Pierre-Yves Chibon 1a43f3
                in output.data)
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
            csrf_token = output.data.split(
Pierre-Yves Chibon 272d30
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 272d30
Jeremy Cline 2eaa12
            with open(os.path.join(tests.HERE, 'placebo.png'), 'r') as stream:
Jeremy Cline 2eaa12
                data = {
Jeremy Cline 2eaa12
                    'title': 'Test issue',
Jeremy Cline 2eaa12
                    'issue_content': 'We really should improve on this issue\n'
Jeremy Cline 2eaa12
                                     '',
Jeremy Cline 2eaa12
                    'status': 'Open',
Jeremy Cline 2eaa12
                    'filestream': stream,
Jeremy Cline 2eaa12
                    'enctype': 'multipart/form-data',
Jeremy Cline 2eaa12
                    'csrf_token': csrf_token,
Jeremy Cline 2eaa12
                }
Jeremy Cline 2eaa12
Jeremy Cline 2eaa12
                output = self.app.post(
Jeremy Cline 2eaa12
                    '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 65e932
            # Check the image was uploaded
Pierre-Yves Chibon 65e932
            self.assertIn(
Pierre-Yves Chibon 65e932
                'href="/test/issue/raw/files/'
Pierre-Yves Chibon 65e932
                '8a06845923010b27bfd8e7e75acff7badc40d1021b4'
Pierre-Yves Chibon 65e932
                '994e01f5e11ca40bc3abe',
Pierre-Yves Chibon 65e932
                output.data)
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
        # Project w/o issue tracker
Pierre-Yves Chibon 272d30
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 272d30
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 272d30
        self.session.add(repo)
Pierre-Yves Chibon 272d30
        self.session.commit()
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
        user.username = 'pingou'
Pierre-Yves Chibon 272d30
        with tests.user_set(pagure.APP, user):
Jeremy Cline 2eaa12
            with open(os.path.join(tests.HERE, 'placebo.png'), 'r') as stream:
Jeremy Cline 2eaa12
                data = {
Jeremy Cline 2eaa12
                    'title': 'Test issue',
Jeremy Cline 2eaa12
                    'issue_content': 'We really should improve on this issue',
Jeremy Cline 2eaa12
                    'status': 'Open',
Jeremy Cline 2eaa12
                    'filestream': stream,
Jeremy Cline 2eaa12
                    'enctype': 'multipart/form-data',
Jeremy Cline 2eaa12
                    'csrf_token': csrf_token,
Jeremy Cline 2eaa12
                }
Jeremy Cline 2eaa12
Jeremy Cline 2eaa12
                output = self.app.post(
Jeremy Cline 2eaa12
                    '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 272d30
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 65e932
        # Project with a namespace
Pierre-Yves Chibon 65e932
        user = tests.FakeUser()
Pierre-Yves Chibon 65e932
        user.username = 'pingou'
Pierre-Yves Chibon 65e932
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 65e932
            output = self.app.get('/somenamespace/test3/new_issue')
Pierre-Yves Chibon 65e932
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 65e932
            self.assertTrue(
Pierre-Yves Chibon 65e932
                '
\n New issue'
Pierre-Yves Chibon 65e932
                in output.data)
Pierre-Yves Chibon 65e932
Pierre-Yves Chibon 65e932
            csrf_token = output.data.split(
Pierre-Yves Chibon 65e932
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 65e932
Pierre-Yves Chibon 65e932
            with open(os.path.join(tests.HERE, 'placebo.png'), 'r') as stream:
Pierre-Yves Chibon 65e932
                data = {
Pierre-Yves Chibon 65e932
                    'title': 'Test issue3',
Pierre-Yves Chibon 65e932
                    'issue_content': 'We really should improve on this issue\n'
Pierre-Yves Chibon 65e932
                                     '',
Pierre-Yves Chibon 65e932
                    'status': 'Open',
Pierre-Yves Chibon 65e932
                    'filestream': stream,
Pierre-Yves Chibon 65e932
                    'enctype': 'multipart/form-data',
Pierre-Yves Chibon 65e932
                    'csrf_token': csrf_token,
Pierre-Yves Chibon 65e932
                }
Pierre-Yves Chibon 65e932
Pierre-Yves Chibon 65e932
                output = self.app.post(
Pierre-Yves Chibon 65e932
                    '/somenamespace/test3/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 65e932
Pierre-Yves Chibon 65e932
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 65e932
            self.assertIn(
Pierre-Yves Chibon 65e932
                '<title>Issue #1: Test issue3 - test3 - Pagure</title>',
Pierre-Yves Chibon 65e932
                output.data)
Pierre-Yves Chibon 65e932
            self.assertIn(
Pierre-Yves Chibon 65e932
                '
Pierre-Yves Chibon 65e932
                'href="/somenamespace/test3/issue/1/edit" '
Pierre-Yves Chibon 65e932
                'title="Edit this issue">',
Pierre-Yves Chibon 65e932
                output.data)
Pierre-Yves Chibon 65e932
            # Check the image was uploaded
Pierre-Yves Chibon 65e932
            self.assertIn(
Pierre-Yves Chibon 65e932
                'href="/somenamespace/test3/issue/raw/files/'
Pierre-Yves Chibon 65e932
                '8a06845923010b27bfd8e7e75acff7badc40d1021b4'
Pierre-Yves Chibon 65e932
                '994e01f5e11ca40bc3abe',
Pierre-Yves Chibon 65e932
                output.data)
Pierre-Yves Chibon 65e932
Pierre-Yves Chibon 272d30
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 272d30
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 7dfb23
    def test_view_issues(self, p_send_email, p_ugt):
Pierre-Yves Chibon 7dfb23
        """ Test the view_issues endpoint. """
Pierre-Yves Chibon 7dfb23
        p_send_email.return_value = True
Pierre-Yves Chibon 7dfb23
        p_ugt.return_value = True
Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/foo/issues')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/test/issues')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            'div class="projectinfo m-t-1 m-b-1">\ntest project #1        '
Pierre-Yves Chibon 98f2af
            '', output.data)
Pierre-Yves Chibon 1a43f3
        self.assertTrue(
Pierre-Yves Chibon 265436
            '

\n 0 Open Issues' in output.data)

Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        # Create issues to play with
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 7dfb23
            session=self.session,
Pierre-Yves Chibon 7dfb23
            repo=repo,
Pierre-Yves Chibon 7dfb23
            title='Test issue',
Pierre-Yves Chibon 7dfb23
            content='We should work on this',
Pierre-Yves Chibon 7dfb23
            user='pingou',
Pierre-Yves Chibon 7dfb23
            ticketfolder=None
Pierre-Yves Chibon 7dfb23
        )
Pierre-Yves Chibon 7dfb23
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 59d698
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 59d698
            session=self.session,
Pierre-Yves Chibon 59d698
            repo=repo,
Pierre-Yves Chibon 59d698
            title='Test invalid issue',
Pierre-Yves Chibon 59d698
            content='This really is not related',
Pierre-Yves Chibon 59d698
            user='pingou',
Pierre-Yves Chibon fad6c1
            status='Closed',
Pierre-Yves Chibon fad6c1
            close_status='Invalid',
Pierre-Yves Chibon 59d698
            ticketfolder=None
Pierre-Yves Chibon 59d698
        )
Pierre-Yves Chibon 59d698
        self.session.commit()
Pierre-Yves Chibon 59d698
        self.assertEqual(msg.title, 'Test invalid issue')
Pierre-Yves Chibon 59d698
Pierre-Yves Chibon 7dfb23
        # Whole list
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/test/issues')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
Pierre-Yves Chibon 1a43f3
        self.assertTrue(
Pierre-Yves Chibon 265436
            '

\n 1 Open Issues' in output.data)

Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 59d698
        # Status = closed (all but open)
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/test/issues?status=cloSED')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
Pierre-Yves Chibon 7dfb23
        self.assertTrue(
Pierre-Yves Chibon 59d698
            '

\n 1 Closed Issues' in output.data)

Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        # Status = fixed
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/test/issues?status=fixed')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
Pierre-Yves Chibon 7dfb23
        self.assertTrue(
Pierre-Yves Chibon 265436
            '

\n 0 Closed Issues' in output.data)

Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 59d698
        # Status = Invalid
Pierre-Yves Chibon 59d698
        output = self.app.get('/test/issues?status=Invalid')
Pierre-Yves Chibon 59d698
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 59d698
        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
Pierre-Yves Chibon 59d698
        self.assertTrue(
Pierre-Yves Chibon 59d698
            '

\n 1 Closed Issues' in output.data)

Pierre-Yves Chibon 59d698
Pierre-Yves Chibon 59d698
        # All tickets
Pierre-Yves Chibon 59d698
        output = self.app.get('/test/issues?status=all')
Pierre-Yves Chibon 59d698
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 59d698
        self.assertIn('<title>Issues - test - Pagure</title>', output.data)
Pierre-Yves Chibon 59d698
        self.assertTrue(
Pierre-Yves Chibon 59d698
            '

\n 2 Issues' in output.data)

Pierre-Yves Chibon 59d698
Pierre-Yves Chibon 5803a7
        # New issue button is shown
Pierre-Yves Chibon 5803a7
        user = tests.FakeUser()
Pierre-Yves Chibon 5803a7
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5803a7
            output = self.app.get('/test')
Pierre-Yves Chibon 5803a7
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5803a7
            self.assertIn(
Pierre-Yves Chibon 5803a7
                'class="btn btn-success btn-sm">New Issue',
Pierre-Yves Chibon 5803a7
                output.data)
Pierre-Yves Chibon 5803a7
Pierre-Yves Chibon 7dfb23
        # Project w/o issue tracker
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 932d90
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 7dfb23
        self.session.add(repo)
Pierre-Yves Chibon 7dfb23
        self.session.commit()
Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/test/issues')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 5803a7
        # New issue button is hidden
Pierre-Yves Chibon 5803a7
        user = tests.FakeUser()
Pierre-Yves Chibon 5803a7
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5803a7
            output = self.app.get('/test')
Pierre-Yves Chibon 5803a7
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5803a7
            self.assertNotIn(
Pierre-Yves Chibon 5803a7
                'class="btn btn-success btn-sm">New Issue',
Pierre-Yves Chibon 5803a7
                output.data)
Pierre-Yves Chibon 5803a7
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 5fee8b
    def test_view_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon 5fee8b
        """ Test the view_issue endpoint. """
Pierre-Yves Chibon 5fee8b
        p_send_email.return_value = True
Pierre-Yves Chibon 5fee8b
        p_ugt.return_value = True
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        output = self.app.get('/foo/issue/1')
Pierre-Yves Chibon 5fee8b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 5fee8b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        # Create issues to play with
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 5fee8b
            session=self.session,
Pierre-Yves Chibon 5fee8b
            repo=repo,
Pierre-Yves Chibon 5fee8b
            title='Test issue',
Pierre-Yves Chibon 5fee8b
            content='We should work on this',
Pierre-Yves Chibon 5fee8b
            user='pingou',
Pierre-Yves Chibon 5fee8b
            ticketfolder=None
Pierre-Yves Chibon 5fee8b
        )
Pierre-Yves Chibon 5fee8b
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 5fee8b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon be8411
        # Not authentified = No edit
Pierre-Yves Chibon be8411
        self.assertNotIn(
Pierre-Yves Chibon 161817
            '
Pierre-Yves Chibon 161817
            'title="Edit this issue">',
Pierre-Yves Chibon 98f2af
            output.data)
Pierre-Yves Chibon 5fee8b
        self.assertTrue(
Pierre-Yves Chibon 744ae7
            ''
Pierre-Yves Chibon 744ae7
            'Login\n            to comment on this ticket.'
Pierre-Yves Chibon 5fee8b
            in output.data)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5fee8b
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 5fee8b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon be8411
            # Not author nor admin = No edit
Pierre-Yves Chibon be8411
            self.assertNotIn(
Pierre-Yves Chibon e26ce6
                '
Pierre-Yves Chibon e26ce6
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon e26ce6
                output.data)
Pierre-Yves Chibon e26ce6
            self.assertNotIn(
Pierre-Yves Chibon e26ce6
                '
Pierre-Yves Chibon e26ce6
                output.data)
Pierre-Yves Chibon e26ce6
            self.assertNotIn('title="Delete this ticket">', output.data)
Pierre-Yves Chibon 5fee8b
            self.assertFalse(
Pierre-Yves Chibon 744ae7
                'Login to comment on this ticket.'
Pierre-Yves Chibon 5fee8b
                in output.data)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5f82f8
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 5f82f8
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon e26ce6
            self.assertIn(
Pierre-Yves Chibon e26ce6
                '
Pierre-Yves Chibon e26ce6
                output.data)
Pierre-Yves Chibon e26ce6
            self.assertIn('title="Delete this ticket">', output.data)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 5f82f8
            csrf_token = output.data.split(
Pierre-Yves Chibon 5f82f8
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 395039
        # Create private issue
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 395039
            session=self.session,
Pierre-Yves Chibon 395039
            repo=repo,
Pierre-Yves Chibon 395039
            title='Test issue',
Pierre-Yves Chibon 395039
            content='We should work on this',
Pierre-Yves Chibon 395039
            user='pingou',
Pierre-Yves Chibon 395039
            ticketfolder=None,
Pierre-Yves Chibon 395039
            private=True,
Pierre-Yves Chibon 395039
        )
Pierre-Yves Chibon 395039
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 395039
Pierre-Yves Chibon 395039
        # Not logged in
Pierre-Yves Chibon 395039
        output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 395039
        self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 395039
Pierre-Yves Chibon 395039
        # Wrong user
Pierre-Yves Chibon 395039
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 395039
            output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 395039
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 395039
Pierre-Yves Chibon 395039
        # reporter
Pierre-Yves Chibon 395039
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 395039
            output = self.app.get('/test/issue/2')
Pierre-Yves Chibon 395039
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
Pierre-Yves Chibon 98f2af
                'title="Private issue">', output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/2/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 395039
Pierre-Yves Chibon b565c1
        # Project w/o issue tracker
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 932d90
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon b565c1
        self.session.add(repo)
Pierre-Yves Chibon b565c1
        self.session.commit()
Pierre-Yves Chibon b565c1
Pierre-Yves Chibon b565c1
        output = self.app.get('/test/issue/1')
Pierre-Yves Chibon b565c1
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 5f82f8
    def test_update_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon 5f82f8
        """ Test the update_issue endpoint. """
Pierre-Yves Chibon 5f82f8
        p_send_email.return_value = True
Pierre-Yves Chibon 5f82f8
        p_ugt.return_value = True
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 80e240
        # No Git repo
Pierre-Yves Chibon 871eed
        output = self.app.get('/foo/issue/1/update')
Pierre-Yves Chibon 80e240
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 5f82f8
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 871eed
        output = self.app.get('/test/issue/1/update')
Pierre-Yves Chibon 1deb85
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 5f82f8
        # Create issues to play with
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 5f82f8
            session=self.session,
Pierre-Yves Chibon 5f82f8
            repo=repo,
Pierre-Yves Chibon 5f82f8
            title='Test issue',
Pierre-Yves Chibon 5f82f8
            content='We should work on this',
Pierre-Yves Chibon 5f82f8
            user='pingou',
Pierre-Yves Chibon 5f82f8
            ticketfolder=None
Pierre-Yves Chibon 5f82f8
        )
Pierre-Yves Chibon 5f82f8
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 5f82f8
        user = tests.FakeUser()
Pierre-Yves Chibon 5f82f8
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5f82f8
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 5f82f8
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 5fee8b
            csrf_token = output.data.split(
Pierre-Yves Chibon 5fee8b
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
            data = {
Pierre-Yves Chibon 2aa887
                'status': 'Closed',
Pierre-Yves Chibon 2aa887
                'close_status': 'fixed'
Pierre-Yves Chibon 5fee8b
            }
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon e2164c
            # Invalid repo
Pierre-Yves Chibon e2164c
            output = self.app.post('/bar/issue/1/update', data=data)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
            # Non-existing issue
Pierre-Yves Chibon e2164c
            output = self.app.post('/test/issue/100/update', data=data)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon 5f82f8
            output = self.app.post(
Pierre-Yves Chibon 5f82f8
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 5fee8b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 5fee8b
            self.assertFalse(
Pierre-Yves Chibon 5fee8b
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 5fee8b
                in output.data)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 247fc2
            # Right status, wrong csrf
Pierre-Yves Chibon 2aa887
            data['close_status'] = 'Fixed'
Pierre-Yves Chibon 5f82f8
            output = self.app.post(
Pierre-Yves Chibon 5f82f8
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 5fee8b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 5f82f8
            self.assertFalse(
Pierre-Yves Chibon 5fee8b
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 5fee8b
                in output.data)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 247fc2
            # working status update
Pierre-Yves Chibon 5fee8b
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 5fee8b
            output = self.app.post(
Pierre-Yves Chibon 5f82f8
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 5fee8b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Successfully edited issue #1',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 5fee8b
            self.assertTrue(
Pierre-Yves Chibon 5fee8b
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 5fee8b
                in output.data)
Pierre-Yves Chibon 247fc2
            self.assertIn(
Jeremy Cline 099538
                '<small>

'

</small>
Pierre-Yves Chibon 2aa887
                '@pingou changed the status to Closed'
Pierre-Yves Chibon 260ea2
                '

'.format(
Pierre-Yves Chibon 260ea2
                    app_url=pagure.APP.config['APP_URL'].rstrip('/')),
Pierre-Yves Chibon 247fc2
                output.data)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 4b0f25
            # Add new comment
Pierre-Yves Chibon 4b0f25
            data = {
Pierre-Yves Chibon 4b0f25
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2aa887
                'status': 'Closed',
Pierre-Yves Chibon 2aa887
                'close_status': 'Fixed',
Pierre-Yves Chibon 4b0f25
                'comment': 'Woohoo a second comment !',
Pierre-Yves Chibon 4b0f25
            }
Pierre-Yves Chibon 4b0f25
            output = self.app.post(
Pierre-Yves Chibon 4b0f25
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 4b0f25
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Comment added',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertNotIn(
Pierre-Yves Chibon 45cb3d
                '\n                      No changes to edit',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '

Woohoo a second comment !

' in output.data)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 2)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 4b0f25
                in output.data)
Pierre-Yves Chibon 4b0f25
Pierre-Yves Chibon 4b0f25
            # Add new tag
Pierre-Yves Chibon 4b0f25
            data = {
Pierre-Yves Chibon 4b0f25
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2aa887
                'status': 'Closed',
Pierre-Yves Chibon 2aa887
                'close_status': 'Fixed',
Pierre-Yves Chibon b53d8c
                'tag': 'tag2',
Pierre-Yves Chibon 4b0f25
            }
Pierre-Yves Chibon 4b0f25
            output = self.app.post(
Pierre-Yves Chibon 4b0f25
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 4b0f25
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '

Woohoo a second comment !

' in output.data)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 2)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 4b0f25
                in output.data)
Pierre-Yves Chibon 4b0f25
Pierre-Yves Chibon 4b0f25
            # Assign issue to an non-existent user
Pierre-Yves Chibon 4b0f25
            data = {
Pierre-Yves Chibon 4b0f25
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2aa887
                'status': 'Closed',
Pierre-Yves Chibon 2aa887
                'close_status': 'Fixed',
Pierre-Yves Chibon 4b0f25
                'assignee': 'ralph',
Pierre-Yves Chibon 4b0f25
            }
Pierre-Yves Chibon 4b0f25
            output = self.app.post(
Pierre-Yves Chibon 4b0f25
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 4b0f25
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      No user "ralph" found',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '

Woohoo a second comment !

' in output.data)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 2)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 4b0f25
                in output.data)
Pierre-Yves Chibon 4b0f25
Pierre-Yves Chibon 4b0f25
            # Assign issue properly
Pierre-Yves Chibon 4b0f25
            data = {
Pierre-Yves Chibon 4b0f25
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2aa887
                'status': 'Closed',
Pierre-Yves Chibon 2aa887
                'close_status': 'Fixed',
Pierre-Yves Chibon 4b0f25
                'assignee': 'pingou',
Pierre-Yves Chibon 4b0f25
            }
Pierre-Yves Chibon 4b0f25
            output = self.app.post(
Pierre-Yves Chibon 4b0f25
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 4b0f25
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Issue assigned',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '' in output.data)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '

Woohoo a second comment !

' in output.data)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 2)
Pierre-Yves Chibon 4b0f25
            self.assertTrue(
Pierre-Yves Chibon 4b0f25
                '<option selected="" value="Fixed">Fixed</option>'
Pierre-Yves Chibon 4b0f25
                in output.data)
Pierre-Yves Chibon 4b0f25
Pierre-Yves Chibon 5fee8b
        # Create another issue with a dependency
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 5fee8b
            session=self.session,
Pierre-Yves Chibon 5fee8b
            repo=repo,
Pierre-Yves Chibon 5fee8b
            title='Test issue',
Pierre-Yves Chibon 5fee8b
            content='We should work on this',
Pierre-Yves Chibon 5fee8b
            user='pingou',
Pierre-Yves Chibon 5fee8b
            ticketfolder=None
Pierre-Yves Chibon 5fee8b
        )
Pierre-Yves Chibon 5fee8b
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 11d78c
Pierre-Yves Chibon 5fee8b
        # Reset the status of the first issue
Pierre-Yves Chibon fe5017
        parent_issue = pagure.lib.search_issues(
Pierre-Yves Chibon 2aa887
            self.session, repo, issueid=1)
Pierre-Yves Chibon 5fee8b
        parent_issue.status = 'Open'
Pierre-Yves Chibon 2aa887
        self.session.add(parent_issue)
Pierre-Yves Chibon 5fee8b
        # Add the dependency relationship
Pierre-Yves Chibon 5fee8b
        self.session.add(parent_issue)
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 5fee8b
        issue.parents.append(parent_issue)
Pierre-Yves Chibon 5fee8b
        self.session.add(issue)
Pierre-Yves Chibon 5fee8b
        self.session.commit()
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 5fee8b
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 5fee8b
            output = self.app.post(
Pierre-Yves Chibon 5f82f8
                '/test/issue/2/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 5fee8b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #2: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/2/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      You cannot close a ticket '
Pierre-Yves Chibon 45cb3d
                'that has ticket depending that are still open.',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 5fee8b
            self.assertTrue(
Pierre-Yves Chibon 5fee8b
                '<option selected="" value="Open">Open</option>'
Pierre-Yves Chibon 5fee8b
                in output.data)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon 395039
        # Create private issue
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 395039
            session=self.session,
Pierre-Yves Chibon 395039
            repo=repo,
Pierre-Yves Chibon 395039
            title='Test issue',
Pierre-Yves Chibon 395039
            content='We should work on this',
Pierre-Yves Chibon 395039
            user='pingou',
Pierre-Yves Chibon 395039
            ticketfolder=None,
Pierre-Yves Chibon 395039
            private=True,
Pierre-Yves Chibon 395039
        )
Pierre-Yves Chibon 395039
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 395039
Pierre-Yves Chibon 395039
        # Wrong user
Pierre-Yves Chibon 395039
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 395039
            output = self.app.post(
Pierre-Yves Chibon 395039
                '/test/issue/3/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 395039
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 395039
Pierre-Yves Chibon 5fee8b
        # Project w/o issue tracker
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 932d90
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 5fee8b
        self.session.add(repo)
Pierre-Yves Chibon 5fee8b
        self.session.commit()
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 871eed
            output = self.app.get('/test/issue/1/update')
Pierre-Yves Chibon 1deb85
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 5fee8b
Pierre-Yves Chibon e2164c
            # Repo not set-up for issue tracker
Pierre-Yves Chibon e2164c
            output = self.app.post('/test/issue/1/update', data=data)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon e2164c
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon e2164c
    def test_update_issue_drop_comment(self, p_send_email, p_ugt):
Pierre-Yves Chibon e2164c
        """ Test droping comment via the update_issue endpoint. """
Pierre-Yves Chibon e2164c
        p_send_email.return_value = True
Pierre-Yves Chibon e2164c
        p_ugt.return_value = True
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        # Create issues to play with
Pierre-Yves Chibon e2164c
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e2164c
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon e2164c
            session=self.session,
Pierre-Yves Chibon e2164c
            repo=repo,
Pierre-Yves Chibon e2164c
            title='Test issue',
Pierre-Yves Chibon e2164c
            content='We should work on this',
Pierre-Yves Chibon e2164c
            user='pingou',
Pierre-Yves Chibon e2164c
            ticketfolder=None
Pierre-Yves Chibon e2164c
        )
Pierre-Yves Chibon e2164c
        self.session.commit()
Pierre-Yves Chibon e2164c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        user = tests.FakeUser()
Pierre-Yves Chibon e2164c
        user.username = 'pingou'
Pierre-Yves Chibon e2164c
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon e2164c
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
            csrf_token = output.data.split(
Pierre-Yves Chibon e2164c
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
            # Add new comment
Pierre-Yves Chibon e2164c
            data = {
Pierre-Yves Chibon e2164c
                'csrf_token': csrf_token,
Pierre-Yves Chibon e2164c
                'comment': 'Woohoo a second comment !',
Pierre-Yves Chibon e2164c
            }
Pierre-Yves Chibon e2164c
            output = self.app.post(
Pierre-Yves Chibon e2164c
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Comment added',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon e2164c
            self.assertTrue(
Pierre-Yves Chibon e2164c
                '

Woohoo a second comment !

' in output.data)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 2)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e2164c
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e2164c
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        data = {
Pierre-Yves Chibon e2164c
            'csrf_token': csrf_token,
Pierre-Yves Chibon e2164c
            'drop_comment': 1,
Pierre-Yves Chibon e2164c
        }
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        user = tests.FakeUser()
Pierre-Yves Chibon e2164c
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon e2164c
            # Wrong issue id
Pierre-Yves Chibon e2164c
            output = self.app.post(
Pierre-Yves Chibon e2164c
                '/test/issue/3/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
            # Wrong user
Pierre-Yves Chibon e2164c
            output = self.app.post(
Pierre-Yves Chibon e2164c
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        user = tests.FakeUser()
Pierre-Yves Chibon e2164c
        user.username = 'pingou'
Pierre-Yves Chibon e2164c
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon e2164c
            # Drop the new comment
Pierre-Yves Chibon e2164c
            output = self.app.post(
Pierre-Yves Chibon e2164c
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Comment removed',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
            # Drop non-existant comment
Pierre-Yves Chibon e2164c
            output = self.app.post(
Pierre-Yves Chibon e2164c
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e2164c
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon e2164c
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e2164c
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e2164c
        self.assertEqual(len(issue.comments), 0)
Pierre-Yves Chibon e2164c
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 3c91f0
    def test_update_issue_depend(self, p_send_email, p_ugt):
Pierre-Yves Chibon 3c91f0
        """ Test adding dependency via the update_issue endpoint. """
Pierre-Yves Chibon 3c91f0
        p_send_email.return_value = True
Pierre-Yves Chibon 3c91f0
        p_ugt.return_value = True
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
        # Create issues to play with
Pierre-Yves Chibon 3c91f0
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3c91f0
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3c91f0
            session=self.session,
Pierre-Yves Chibon 3c91f0
            repo=repo,
Pierre-Yves Chibon 3c91f0
            title='Test issue',
Pierre-Yves Chibon 3c91f0
            content='We should work on this',
Pierre-Yves Chibon 3c91f0
            user='pingou',
Pierre-Yves Chibon 3c91f0
            ticketfolder=None
Pierre-Yves Chibon 3c91f0
        )
Pierre-Yves Chibon 3c91f0
        self.session.commit()
Pierre-Yves Chibon 3c91f0
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3c91f0
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 3c91f0
            session=self.session,
Pierre-Yves Chibon 3c91f0
            repo=repo,
Pierre-Yves Chibon 3c91f0
            title='Test issue #2',
Pierre-Yves Chibon 3c91f0
            content='We should work on this again',
Pierre-Yves Chibon 3c91f0
            user='foo',
Pierre-Yves Chibon 3c91f0
            ticketfolder=None
Pierre-Yves Chibon 3c91f0
        )
Pierre-Yves Chibon 3c91f0
        self.session.commit()
Pierre-Yves Chibon 3c91f0
        self.assertEqual(msg.title, 'Test issue #2')
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
        user = tests.FakeUser()
Pierre-Yves Chibon 3c91f0
        user.username = 'pingou'
Pierre-Yves Chibon 3c91f0
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 3c91f0
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 3c91f0
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
            csrf_token = output.data.split(
Pierre-Yves Chibon 3c91f0
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
            # Add a dependent ticket
Pierre-Yves Chibon 3c91f0
            data = {
Pierre-Yves Chibon 3c91f0
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3c91f0
                'depends': '2',
Pierre-Yves Chibon 3c91f0
            }
Pierre-Yves Chibon 3c91f0
            output = self.app.post(
Pierre-Yves Chibon 3c91f0
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 3c91f0
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
            # Add an invalid dependent ticket
Pierre-Yves Chibon 3c91f0
            data = {
Pierre-Yves Chibon 3c91f0
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3c91f0
                'depends': '2,abc',
Pierre-Yves Chibon 3c91f0
            }
Pierre-Yves Chibon 3c91f0
            output = self.app.post(
Pierre-Yves Chibon 3c91f0
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 3c91f0
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertNotIn(
Pierre-Yves Chibon 5b73ec
                '\n                      '
Pierre-Yves Chibon 5b73ec
                'Successfully edited issue #1',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3c91f0
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 3c91f0
        self.assertEqual(issue.depends_text, [2])
Pierre-Yves Chibon 3c91f0
        self.assertEqual(issue.blocks_text, [])
Pierre-Yves Chibon 3c91f0
Pierre-Yves Chibon 3c91f0
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 3c91f0
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon e6906a
    def test_update_issue_block(self, p_send_email, p_ugt):
Pierre-Yves Chibon e6906a
        """ Test adding blocked issue via the update_issue endpoint. """
Pierre-Yves Chibon e6906a
        p_send_email.return_value = True
Pierre-Yves Chibon e6906a
        p_ugt.return_value = True
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
        # Create issues to play with
Pierre-Yves Chibon e6906a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e6906a
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon e6906a
            session=self.session,
Pierre-Yves Chibon e6906a
            repo=repo,
Pierre-Yves Chibon e6906a
            title='Test issue',
Pierre-Yves Chibon e6906a
            content='We should work on this',
Pierre-Yves Chibon e6906a
            user='pingou',
Pierre-Yves Chibon e6906a
            ticketfolder=None
Pierre-Yves Chibon e6906a
        )
Pierre-Yves Chibon e6906a
        self.session.commit()
Pierre-Yves Chibon e6906a
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e6906a
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon e6906a
            session=self.session,
Pierre-Yves Chibon e6906a
            repo=repo,
Pierre-Yves Chibon e6906a
            title='Test issue #2',
Pierre-Yves Chibon e6906a
            content='We should work on this again',
Pierre-Yves Chibon e6906a
            user='foo',
Pierre-Yves Chibon e6906a
            ticketfolder=None
Pierre-Yves Chibon e6906a
        )
Pierre-Yves Chibon e6906a
        self.session.commit()
Pierre-Yves Chibon e6906a
        self.assertEqual(msg.title, 'Test issue #2')
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon 349f0b
        # User is not an admin of the project
Pierre-Yves Chibon 349f0b
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon 349f0b
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 349f0b
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 349f0b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 349f0b
            self.assertIn(
Pierre-Yves Chibon 349f0b
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 349f0b
                output.data)
Pierre-Yves Chibon 349f0b
Pierre-Yves Chibon 349f0b
            csrf_token = output.data.split(
Pierre-Yves Chibon 349f0b
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 349f0b
Pierre-Yves Chibon 349f0b
            # Add a dependent ticket
Pierre-Yves Chibon 349f0b
            data = {
Pierre-Yves Chibon 349f0b
                'csrf_token': csrf_token,
Pierre-Yves Chibon 349f0b
                'blocks': '2',
Pierre-Yves Chibon 349f0b
            }
Pierre-Yves Chibon 349f0b
            output = self.app.post(
Pierre-Yves Chibon 349f0b
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 349f0b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 349f0b
            self.assertIn(
Pierre-Yves Chibon 349f0b
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 349f0b
                output.data)
Pierre-Yves Chibon 349f0b
Pierre-Yves Chibon 349f0b
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 349f0b
            issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 349f0b
            self.assertEqual(issue.depends_text, [])
Pierre-Yves Chibon 349f0b
            self.assertEqual(issue.blocks_text, [])
Pierre-Yves Chibon 349f0b
Pierre-Yves Chibon e6906a
        user = tests.FakeUser()
Pierre-Yves Chibon e6906a
        user.username = 'pingou'
Pierre-Yves Chibon e6906a
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon e6906a
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon e6906a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
            csrf_token = output.data.split(
Pierre-Yves Chibon e6906a
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
            # Add a dependent ticket
Pierre-Yves Chibon e6906a
            data = {
Pierre-Yves Chibon e6906a
                'csrf_token': csrf_token,
Pierre-Yves Chibon e6906a
                'blocks': '2',
Pierre-Yves Chibon e6906a
            }
Pierre-Yves Chibon e6906a
            output = self.app.post(
Pierre-Yves Chibon e6906a
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e6906a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
            # Add an invalid dependent ticket
Pierre-Yves Chibon e6906a
            data = {
Pierre-Yves Chibon e6906a
                'csrf_token': csrf_token,
Pierre-Yves Chibon e6906a
                'blocks': '2,abc',
Pierre-Yves Chibon e6906a
            }
Pierre-Yves Chibon e6906a
            output = self.app.post(
Pierre-Yves Chibon e6906a
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon e6906a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertNotIn(
Pierre-Yves Chibon 5b73ec
                '\n                      '
Pierre-Yves Chibon 5b73ec
                'Successfully edited issue #1',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon e6906a
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon e6906a
        self.assertEqual(issue.depends_text, [])
Pierre-Yves Chibon e6906a
        self.assertEqual(issue.blocks_text, [2])
Pierre-Yves Chibon e6906a
Pierre-Yves Chibon e6906a
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon e6906a
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon ca67cd
    def test_upload_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon ca67cd
        """ Test the upload_issue endpoint. """
Patrick Uiterwijk 198c68
        if not pyclamd:
Patrick Uiterwijk 198c68
            raise SkipTest()
Pierre-Yves Chibon ca67cd
        p_send_email.return_value = True
Pierre-Yves Chibon ca67cd
        p_ugt.return_value = True
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
        tests.create_projects(self.session)
Pierre-Yves Chibon ca67cd
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path, 'tickets'), bare=True)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
        # Create issues to play with
Pierre-Yves Chibon ca67cd
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon ca67cd
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon ca67cd
            session=self.session,
Pierre-Yves Chibon ca67cd
            repo=repo,
Pierre-Yves Chibon ca67cd
            title='Test issue',
Pierre-Yves Chibon ca67cd
            content='We should work on this',
Pierre-Yves Chibon ca67cd
            user='pingou',
Pierre-Yves Chibon ca67cd
            ticketfolder=None
Pierre-Yves Chibon ca67cd
        )
Pierre-Yves Chibon ca67cd
        self.session.commit()
Pierre-Yves Chibon ca67cd
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
        user = tests.FakeUser()
Pierre-Yves Chibon ca67cd
        user.username = 'pingou'
Pierre-Yves Chibon ca67cd
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon ca67cd
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon ca67cd
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
            csrf_token = output.data.split(
Pierre-Yves Chibon ca67cd
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
            output = self.app.post('/foo/issue/1/upload')
Pierre-Yves Chibon ca67cd
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
            output = self.app.post('/test/issue/100/upload')
Pierre-Yves Chibon ca67cd
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
            # Invalid upload
Pierre-Yves Chibon ca67cd
            data = {
Pierre-Yves Chibon ca67cd
                'enctype': 'multipart/form-data',
Pierre-Yves Chibon ca67cd
            }
Pierre-Yves Chibon ca67cd
            output = self.app.post(
Pierre-Yves Chibon ca67cd
                '/test/issue/1/upload', data=data, follow_redirects=True)
Pierre-Yves Chibon ca67cd
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon ca67cd
            json_data = json.loads(output.data)
Pierre-Yves Chibon ca67cd
            exp = {'output': 'notok'}
Pierre-Yves Chibon ca67cd
            self.assertDictEqual(json_data, exp)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon 2da911
            # TODO: Figure a way to enable this test on jenkins
Patrick Uiterwijk 78afb3
            # Try to attach a virus
Pierre-Yves Chibon 2da911
            if not os.environ.get('BUILD_ID'):
Pierre-Yves Chibon 2da911
                with tempfile.NamedTemporaryFile() as eicarfile:
Pierre-Yves Chibon 2da911
                    eicarfile.write(pyclamd.ClamdUnixSocket().EICAR())
Pierre-Yves Chibon 2da911
                    eicarfile.flush()
Jeremy Cline 2eaa12
                    with open(eicarfile.name, 'rb') as stream:
Jeremy Cline 2eaa12
                        data = {
Jeremy Cline 2eaa12
                            'csrf_token': csrf_token,
Jeremy Cline 2eaa12
                            'filestream': stream,
Jeremy Cline 2eaa12
                            'enctype': 'multipart/form-data',
Jeremy Cline 2eaa12
                        }
Jeremy Cline 2eaa12
                        output = self.app.post(
Jeremy Cline 2eaa12
                            '/test/issue/1/upload', data=data, follow_redirects=True)
Pierre-Yves Chibon 2da911
                    self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 2da911
                    json_data = json.loads(output.data)
Pierre-Yves Chibon 2da911
                    exp = {
Pierre-Yves Chibon 2da911
                        'output': 'notok',
Pierre-Yves Chibon 2da911
                    }
Pierre-Yves Chibon 2da911
                    self.assertDictEqual(json_data, exp)
Patrick Uiterwijk 78afb3
Pierre-Yves Chibon ca67cd
            # Attach a file to a ticket
Jeremy Cline 2eaa12
            with open(os.path.join(tests.HERE, 'placebo.png'), 'rb') as stream:
Jeremy Cline 2eaa12
                data = {
Jeremy Cline 2eaa12
                    'csrf_token': csrf_token,
Jeremy Cline 2eaa12
                    'filestream': stream,
Jeremy Cline 2eaa12
                    'enctype': 'multipart/form-data',
Jeremy Cline 2eaa12
                }
Jeremy Cline 2eaa12
                output = self.app.post(
Jeremy Cline 2eaa12
                    '/test/issue/1/upload', data=data, follow_redirects=True)
Pierre-Yves Chibon ca67cd
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon ca67cd
            json_data = json.loads(output.data)
Pierre-Yves Chibon 903c17
Pierre-Yves Chibon be6622
            folder = os.path.dirname(
Pierre-Yves Chibon be6622
                os.path.abspath(__file__))[1:].replace('/', '_')
Pierre-Yves Chibon ca67cd
            exp = {
Pierre-Yves Chibon ca67cd
                'output': 'ok',
Pierre-Yves Chibon ca67cd
                'filelocation': '/test/issue/raw/files/8a06845923010b27bfd8'
Pierre-Yves Chibon ca67cd
                                'e7e75acff7badc40d1021b4994e01f5e11ca40bc3a'
Pierre-Yves Chibon 903c17
                                'be-%s_placebo.png' % folder,
Pierre-Yves Chibon 903c17
                'filename': '%s_placebo.png' % folder,
Pierre-Yves Chibon ca67cd
            }
Pierre-Yves Chibon ca67cd
            self.assertDictEqual(json_data, exp)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
        # Project w/o issue tracker
Pierre-Yves Chibon ca67cd
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon ca67cd
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon ca67cd
        self.session.add(repo)
Pierre-Yves Chibon ca67cd
        self.session.commit()
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon ca67cd
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon ca67cd
            output = self.app.post('/test/issue/1/upload')
Pierre-Yves Chibon ca67cd
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon ca67cd
Pierre-Yves Chibon 47316a
    def test_view_issue_raw_file_empty(self):
Pierre-Yves Chibon 47316a
        """ Test the view_issue_raw_file endpoint. """
Pierre-Yves Chibon 47316a
        # Create the project and git repos
Pierre-Yves Chibon 47316a
        tests.create_projects(self.session)
Pierre-Yves Chibon 47316a
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path, 'tickets'), bare=True)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        # Create issues to play with
Pierre-Yves Chibon 47316a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 47316a
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 47316a
            session=self.session,
Pierre-Yves Chibon 47316a
            repo=repo,
Pierre-Yves Chibon 47316a
            title='Test issue',
Pierre-Yves Chibon 47316a
            content='We should work on this',
Pierre-Yves Chibon 47316a
            user='pingou',
Pierre-Yves Chibon 47316a
            ticketfolder=None
Pierre-Yves Chibon 47316a
        )
Pierre-Yves Chibon 47316a
        self.session.commit()
Pierre-Yves Chibon 47316a
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        url = '/issue/raw/files/8a06845923010b27bfd8'\
Pierre-Yves Chibon 47316a
            'e7e75acff7badc40d1021b4994e01f5e11ca40bc3a'\
Pierre-Yves Chibon 47316a
            'be-home_pierrey_repos_gitrepo_pagure_tests'\
Pierre-Yves Chibon 47316a
            '_placebo.png'
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        output = self.app.get('/foo' + url)
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        output = self.app.get('/test' + url)
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        # Project w/o issue tracker
Pierre-Yves Chibon 47316a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 47316a
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 47316a
        self.session.add(repo)
Pierre-Yves Chibon 47316a
        self.session.commit()
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        output = self.app.get('/test' + url)
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
    def test_view_issue_raw_file(self):
Pierre-Yves Chibon 47316a
        """ Test the view_issue_raw_file endpoint. """
Pierre-Yves Chibon 47316a
        # Create the issue and upload to it
Pierre-Yves Chibon 47316a
        self.test_upload_issue()
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        # Project w/ issue tracker
Pierre-Yves Chibon 47316a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 47316a
        repo.settings = {'issue_tracker': True}
Pierre-Yves Chibon 47316a
        self.session.add(repo)
Pierre-Yves Chibon 47316a
        self.session.commit()
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        url = '/issue/raw/files/8a06845923010b27bfd8'\
Pierre-Yves Chibon 47316a
            'e7e75acff7badc40d1021b4994e01f5e11ca40bc3a'\
Pierre-Yves Chibon be6622
            'be-%s_placebo.png' % os.path.dirname(
Pierre-Yves Chibon be6622
                os.path.abspath(__file__))[1:].replace('/', '_')
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        output = self.app.get('/foo' + url)
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        output = self.app.get('/test/issue/raw/files/test.png')
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        # Access file by name
Pierre-Yves Chibon 47316a
        output = self.app.get('/test' + url)
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        # Project w/o issue tracker
Pierre-Yves Chibon 47316a
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 47316a
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 47316a
        self.session.add(repo)
Pierre-Yves Chibon 47316a
        self.session.commit()
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon 47316a
        output = self.app.get('/test' + url)
Pierre-Yves Chibon 47316a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 47316a
Pierre-Yves Chibon ca67cd
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon ca67cd
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 161728
    def test_edit_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon 161728
        """ Test the edit_issue endpoint. """
Pierre-Yves Chibon 161728
        p_send_email.return_value = True
Pierre-Yves Chibon 161728
        p_ugt.return_value = True
Pierre-Yves Chibon 161728
Pierre-Yves Chibon dec404
        # No Git repo
Pierre-Yves Chibon 161728
        output = self.app.get('/foo/issue/1/edit')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 161728
            output = self.app.get('/foo/issue/1/edit')
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
            tests.create_projects_git(
Jeremy Cline 20109f
                os.path.join(self.path), bare=True)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            output = self.app.get('/test/issue/1/edit')
Pierre-Yves Chibon 6c122a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon dec404
        # User not logged in
Pierre-Yves Chibon dec404
        output = self.app.get('/foo/issue/1/edit')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon dec404
Pierre-Yves Chibon 161728
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 161728
            output = self.app.get('/test/issue/1/edit')
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
        # Create issues to play with
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 161728
            session=self.session,
Pierre-Yves Chibon 161728
            repo=repo,
Pierre-Yves Chibon 161728
            title='Test issue',
Pierre-Yves Chibon 161728
            content='We should work on this',
Pierre-Yves Chibon 161728
            user='pingou',
Pierre-Yves Chibon 161728
            ticketfolder=None
Pierre-Yves Chibon 161728
        )
Pierre-Yves Chibon 161728
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 161728
            output = self.app.get('/test/issue/1/edit')
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 161728
            output = self.app.get('/test/issue/1/edit')
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n Edit '
Pierre-Yves Chibon 1a43f3
                'issue #1\n      ' in output.data)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            csrf_token = output.data.split(
Pierre-Yves Chibon 161728
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            data = {
Pierre-Yves Chibon 161728
                'issue_content': 'We should work on this!'
Pierre-Yves Chibon 161728
            }
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            output = self.app.post('/test/issue/1/edit', data=data)
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n Edit '
Pierre-Yves Chibon 1a43f3
                'issue #1\n      ' in output.data)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon c3b75f
                '<small>\n            This field is required. \n'</small>
Pierre-Yves Chibon c3b75f
                '          '), 1)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon c3b75f
                '<small>\n            Not a valid choice '</small>
Pierre-Yves Chibon c3b75f
                '\n          '), 1)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            data['status'] = 'Open'
Pierre-Yves Chibon 161728
            data['title'] = 'Test issue #1'
Pierre-Yves Chibon 161728
            output = self.app.post('/test/issue/1/edit', data=data)
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
\n Edit '
Pierre-Yves Chibon 1a43f3
                'issue #1\n      ' in output.data)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon c3b75f
                '<small>\n            This field is required. \n'</small>
Pierre-Yves Chibon c3b75f
                '          '), 0)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon c3b75f
                '<small>\n            Not a valid choice '</small>
Pierre-Yves Chibon c3b75f
                '\n          '), 0)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 161728
            output = self.app.post(
Pierre-Yves Chibon 161728
                '/test/issue/1/edit', data=data, follow_redirects=True)
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Successfully edited issue #1',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 0b2052
            self.assertIn(
Pierre-Yves Chibon 0b2052
                '#1\n'
Pierre-Yves Chibon 4fcf92
                '    Test issue #1',
Pierre-Yves Chibon 0b2052
                output.data)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 161728
                '<option selected="" value="Open">Open</option>'), 1)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 1)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon fb3f3e
                '

We should work on this!

'), 1)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
        # Project w/o issue tracker
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 932d90
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 161728
        self.session.add(repo)
Pierre-Yves Chibon 161728
        self.session.commit()
Pierre-Yves Chibon 161728
Pierre-Yves Chibon 161728
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 161728
            output = self.app.post('/test/issue/1/edit', data=data)
Pierre-Yves Chibon 161728
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 161728
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon aa7f0a
    def test_edit_tag(self, p_send_email, p_ugt):
Pierre-Yves Chibon aa7f0a
        """ Test the edit_tag endpoint. """
Pierre-Yves Chibon aa7f0a
        p_send_email.return_value = True
Pierre-Yves Chibon aa7f0a
        p_ugt.return_value = True
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon dec404
        # No Git repo
Pierre-Yves Chibon aa7f0a
        output = self.app.get('/foo/tag/foo/edit')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon aa7f0a
            output = self.app.get('/foo/tag/foo/edit')
Pierre-Yves Chibon aa7f0a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
            tests.create_projects(self.session)
Jeremy Cline 20109f
            tests.create_projects_git(self.path)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
            output = self.app.get('/test/tag/foo/edit')
Pierre-Yves Chibon aa7f0a
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon dec404
        # User not logged in
Pierre-Yves Chibon dec404
        output = self.app.get('/test/tag/foo/edit')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon dec404
Pierre-Yves Chibon aa7f0a
        # Create issues to play with
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon aa7f0a
            session=self.session,
Pierre-Yves Chibon aa7f0a
            repo=repo,
Pierre-Yves Chibon aa7f0a
            title='Test issue',
Pierre-Yves Chibon aa7f0a
            content='We should work on this',
Pierre-Yves Chibon aa7f0a
            user='pingou',
Pierre-Yves Chibon aa7f0a
            ticketfolder=None
Pierre-Yves Chibon aa7f0a
        )
Pierre-Yves Chibon aa7f0a
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
        # Add a tag to the issue
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 668fbd
        msg = pagure.lib.add_tag_obj(
Pierre-Yves Chibon aa7f0a
            session=self.session,
Pierre-Yves Chibon 668fbd
            obj=issue,
Pierre-Yves Chibon df35d8
            tags='tag1',
Pierre-Yves Chibon aa7f0a
            user='pingou',
Pierre-Yves Chibon aa7f0a
            ticketfolder=None)
Pierre-Yves Chibon aa7f0a
        self.session.commit()
Pierre-Yves Chibon df35d8
        self.assertEqual(msg, 'Tag added: tag1')
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
        # Before edit, list tags
Pierre-Yves Chibon fe5017
        tags = pagure.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon aa7f0a
        self.assertEqual([tag.tag for tag in tags], ['tag1'])
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
        # Edit tag
Pierre-Yves Chibon aa7f0a
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
skrzepto 89ada6
            #Edit a tag that doesn't exit
skrzepto 89ada6
            output = self.app.get('/test/tag/does_not_exist/edit')
skrzepto 89ada6
            self.assertEqual(output.status_code, 404)
skrzepto 89ada6
Pierre-Yves Chibon aa7f0a
            output = self.app.get('/test/tag/tag1/edit')
Pierre-Yves Chibon aa7f0a
            self.assertEqual(output.status_code, 200)
Mark Reynolds 403d8f
            self.assertTrue('Edit tag: tag1' in output.data)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
            csrf_token = output.data.split(
Pierre-Yves Chibon aa7f0a
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon aa7f0a
Mark Reynolds 403d8f
            data = {'tag': 'tag2',
Mark Reynolds 403d8f
                    'tag_color': 'DeepSkyBlue'}
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
            output = self.app.post('/test/tag/tag1/edit', data=data)
Pierre-Yves Chibon aa7f0a
            self.assertEqual(output.status_code, 200)
Mark Reynolds 403d8f
            self.assertTrue('Edit tag: tag1' in output.data)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon aa7f0a
            output = self.app.post(
Pierre-Yves Chibon aa7f0a
                '/test/tag/tag1/edit', data=data, follow_redirects=True)
Pierre-Yves Chibon aa7f0a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Mark Reynolds 403d8f
                'Settings - test - Pagure', output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon a8f682
                '\n                      '
Pierre-Yves Chibon a8f682
                'Edited tag: tag1(DeepSkyBlue) to tag2(DeepSkyBlue)',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon 2dec04
        # After edit, list tags
Pierre-Yves Chibon fe5017
        tags = pagure.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon 2dec04
        self.assertEqual([tag.tag for tag in tags], ['tag2'])
Pierre-Yves Chibon 2dec04
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon fe5017
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 269165
    def test_remove_tag(self, p_send_email, p_ugt):
Pierre-Yves Chibon 269165
        """ Test the remove_tag endpoint. """
Pierre-Yves Chibon 269165
        p_send_email.return_value = True
Pierre-Yves Chibon 269165
        p_ugt.return_value = True
Pierre-Yves Chibon 269165
Pierre-Yves Chibon dec404
        # No Git repo
Pierre-Yves Chibon 269165
        output = self.app.post('/foo/droptag/')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 269165
            output = self.app.post('/foo/droptag/')
Pierre-Yves Chibon 269165
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
            tests.create_projects(self.session)
Jeremy Cline 20109f
            tests.create_projects_git(self.path)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
            output = self.app.post('/test/droptag/')
Pierre-Yves Chibon 269165
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon dec404
        # User not logged in
Pierre-Yves Chibon dec404
        output = self.app.post('/test/droptag/')
Pierre-Yves Chibon dec404
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon dec404
Pierre-Yves Chibon 269165
        # Create issues to play with
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 269165
            session=self.session,
Pierre-Yves Chibon 269165
            repo=repo,
Pierre-Yves Chibon 269165
            title='Test issue',
Pierre-Yves Chibon 269165
            content='We should work on this',
Pierre-Yves Chibon 269165
            user='pingou',
Pierre-Yves Chibon 269165
            ticketfolder=None
Pierre-Yves Chibon 269165
        )
Pierre-Yves Chibon 269165
        self.session.commit()
Pierre-Yves Chibon 11d78c
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
        # Add a tag to the issue
Pierre-Yves Chibon fe5017
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 668fbd
        msg = pagure.lib.add_tag_obj(
Pierre-Yves Chibon 269165
            session=self.session,
Pierre-Yves Chibon 668fbd
            obj=issue,
Pierre-Yves Chibon df35d8
            tags='tag1',
Pierre-Yves Chibon 269165
            user='pingou',
Pierre-Yves Chibon 269165
            ticketfolder=None)
Pierre-Yves Chibon 269165
        self.session.commit()
Pierre-Yves Chibon df35d8
        self.assertEqual(msg, 'Tag added: tag1')
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
        # Before edit, list tags
Pierre-Yves Chibon fe5017
        tags = pagure.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon 269165
        self.assertEqual([tag.tag for tag in tags], ['tag1'])
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
        # Edit tag
Pierre-Yves Chibon 269165
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 269165
            output = self.app.post(
Pierre-Yves Chibon 269165
                '/test/droptag/', data={}, follow_redirects=True)
Pierre-Yves Chibon 269165
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 269165
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '<title>Settings - test - Pagure</title>' in output.data)
Pierre-Yves Chibon 1a43f3
            self.assertTrue("

Settings for test

" in output.data)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
            csrf_token = output.data.split(
Pierre-Yves Chibon 269165
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
            data = {'tag': 'tag1'}
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
            output = self.app.post(
Pierre-Yves Chibon 269165
                '/test/droptag/', data=data, follow_redirects=True)
Pierre-Yves Chibon 269165
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue("

Settings for test

" in output.data)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 269165
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 269165
            output = self.app.post(
Pierre-Yves Chibon 269165
                '/test/droptag/', data=data, follow_redirects=True)
Pierre-Yves Chibon 269165
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 1a43f3
            self.assertTrue("

Settings for test

" in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Removed tag: tag1',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon 269165
Pierre-Yves Chibon 4a0d3b
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 4a0d3b
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 4a0d3b
    def test_delete_issue(self, p_send_email, p_ugt):
Pierre-Yves Chibon 4a0d3b
        """ Test the delete_issue endpoint. """
Pierre-Yves Chibon 4a0d3b
        p_send_email.return_value = True
Pierre-Yves Chibon 4a0d3b
        p_ugt.return_value = True
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
        tests.create_projects(self.session)
Jeremy Cline 20109f
        tests.create_projects_git(self.path)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path, 'tickets'))
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
        # Create issues to play with
Pierre-Yves Chibon 4a0d3b
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 4a0d3b
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 4a0d3b
            session=self.session,
Pierre-Yves Chibon 4a0d3b
            repo=repo,
Pierre-Yves Chibon 4a0d3b
            title='Test issue',
Pierre-Yves Chibon 4a0d3b
            content='We should work on this',
Pierre-Yves Chibon 4a0d3b
            user='pingou',
Pierre-Yves Chibon 4a0d3b
            ticketfolder=None
Pierre-Yves Chibon 4a0d3b
        )
Pierre-Yves Chibon 4a0d3b
        self.session.commit()
Pierre-Yves Chibon 4a0d3b
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
        user = tests.FakeUser()
Pierre-Yves Chibon 4a0d3b
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 4a0d3b
            output = self.app.post(
Pierre-Yves Chibon 4a0d3b
                '/foo/issue/1/drop', follow_redirects=True)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
            output = self.app.post(
Pierre-Yves Chibon 4a0d3b
                '/test/issue/100/drop', follow_redirects=True)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
            output = self.app.post(
Pierre-Yves Chibon 4a0d3b
                '/test/issue/1/drop', follow_redirects=True)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
        user.username = 'pingou'
Pierre-Yves Chibon 4a0d3b
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 4a0d3b
            output = self.app.post(
Pierre-Yves Chibon 4a0d3b
                '/test/issue/1/drop', follow_redirects=True)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4a0d3b
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
            csrf_token = output.data.split(
Pierre-Yves Chibon 4a0d3b
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
            data = {
Pierre-Yves Chibon 4a0d3b
            }
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
            # No CSRF token
Pierre-Yves Chibon 4a0d3b
            output = self.app.post(
Pierre-Yves Chibon 4a0d3b
                '/test/issue/1/drop', data=data, follow_redirects=True)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4a0d3b
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 4a0d3b
            output = self.app.post(
Pierre-Yves Chibon 4a0d3b
                '/test/issue/1/drop', data=data, follow_redirects=True)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4a0d3b
            self.assertIn(
Pierre-Yves Chibon 4a0d3b
                '<title>Issues - test - Pagure</title>', output.data)
Pierre-Yves Chibon 4a0d3b
            self.assertIn(
Pierre-Yves Chibon 161817
                '\n                      Issue deleted',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
        # Project w/o issue tracker
Pierre-Yves Chibon 4a0d3b
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 4a0d3b
        repo.settings = {'issue_tracker': False}
Pierre-Yves Chibon 4a0d3b
        self.session.add(repo)
Pierre-Yves Chibon 4a0d3b
        self.session.commit()
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon 4a0d3b
        user.username = 'pingou'
Pierre-Yves Chibon 4a0d3b
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 4a0d3b
            output = self.app.post('/test/issue/1/drop', data=data)
Pierre-Yves Chibon 4a0d3b
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 4a0d3b
Pierre-Yves Chibon d256ab
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon d256ab
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon d256ab
    def test_update_issue_edit_comment(self,  p_send_email, p_ugt):
Pierre-Yves Chibon d256ab
        """ Test the issues edit comment endpoint """
Pierre-Yves Chibon d256ab
        p_send_email.return_value = True
Pierre-Yves Chibon d256ab
        p_ugt.return_value = True
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        tests.create_projects(self.session)
Pierre-Yves Chibon 5361ad
        tests.create_projects_git(
Jeremy Cline 20109f
            os.path.join(self.path), bare=True)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        # Create issues to play with
Pierre-Yves Chibon d256ab
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon d256ab
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon d256ab
            session=self.session,
Pierre-Yves Chibon d256ab
            repo=repo,
Pierre-Yves Chibon d256ab
            title='Test issue',
Pierre-Yves Chibon d256ab
            content='We should work on this',
Pierre-Yves Chibon d256ab
            user='pingou',
Pierre-Yves Chibon d256ab
            ticketfolder=None
Pierre-Yves Chibon d256ab
        )
Pierre-Yves Chibon d256ab
        self.session.commit()
Pierre-Yves Chibon d256ab
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        user = tests.FakeUser()
Pierre-Yves Chibon d256ab
        user.username = 'pingou'
Pierre-Yves Chibon d256ab
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon d256ab
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon d256ab
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
            csrf_token = output.data.split(
Pierre-Yves Chibon d256ab
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
            # Add new comment
Pierre-Yves Chibon d256ab
            data = {
Pierre-Yves Chibon d256ab
                'csrf_token': csrf_token,
Pierre-Yves Chibon d256ab
                'comment': 'Woohoo a second comment !',
Pierre-Yves Chibon d256ab
            }
Pierre-Yves Chibon d256ab
            output = self.app.post(
Pierre-Yves Chibon d256ab
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon d256ab
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Comment added',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon d256ab
            self.assertTrue(
Pierre-Yves Chibon d256ab
                '

Woohoo a second comment !

' in output.data)
Pierre-Yves Chibon fb3f3e
            self.assertEqual(output.data.count('comment_body">'), 2)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon d256ab
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon d256ab
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon 161817
        self.assertEqual(
Pierre-Yves Chibon 161817
            issue.comments[0].comment,
Pierre-Yves Chibon 161817
            'Woohoo a second comment !')
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        data = {
Pierre-Yves Chibon d256ab
            'csrf_token': csrf_token,
Pierre-Yves Chibon d256ab
            'edit_comment': 1,
Pierre-Yves Chibon d256ab
            'update_comment': 'Updated comment',
Pierre-Yves Chibon d256ab
        }
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        user = tests.FakeUser()
Pierre-Yves Chibon d256ab
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon d256ab
            # Wrong issue id
Pierre-Yves Chibon d256ab
            output = self.app.post(
Pierre-Yves Chibon d256ab
                '/test/issue/3/update', data=data, follow_redirects=True)
Pierre-Yves Chibon d256ab
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
            # Wrong user
Pierre-Yves Chibon d256ab
            output = self.app.post(
Pierre-Yves Chibon d256ab
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon d256ab
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        user = tests.FakeUser()
Pierre-Yves Chibon d256ab
        user.username = 'pingou'
Pierre-Yves Chibon d256ab
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon d256ab
            # Edit comment
Pierre-Yves Chibon d256ab
            output = self.app.post(
Pierre-Yves Chibon d256ab
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon d256ab
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Comment updated',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon d256ab
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon d256ab
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon d256ab
        self.assertEqual(issue.comments[0].comment, 'Updated comment')
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon d256ab
            output = self.app.get('/test/issue/1/comment/1/edit')
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '<title>test - Pagure</title>', output.data)
Pierre-Yves Chibon d256ab
            self.assertTrue('
' in output.data)
Pierre-Yves Chibon d256ab
            self.assertTrue('<section class="edit_comment">' in output.data)</section>
Pierre-Yves Chibon 1a43f3
            self.assertTrue(
Pierre-Yves Chibon 1a43f3
                '
Pierre-Yves Chibon 1a43f3
                in output.data)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
            csrf_token = output.data.split(
Pierre-Yves Chibon d256ab
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon d256ab
            data['update_comment'] = 'Second update'
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
            # Edit the comment with the other endpoint
Pierre-Yves Chibon d256ab
            output = self.app.post(
Pierre-Yves Chibon d256ab
                '/test/issue/1/comment/1/edit',
Pierre-Yves Chibon d256ab
                data=data,
Pierre-Yves Chibon d256ab
                follow_redirects=True)
Pierre-Yves Chibon d256ab
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 744ae7
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 744ae7
                output.data)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 161817
                '
Pierre-Yves Chibon 161817
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 161817
                output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Comment updated',
Pierre-Yves Chibon 45cb3d
                output.data)
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon d256ab
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon d256ab
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon d256ab
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon d256ab
        self.assertEqual(issue.comments[0].comment, 'Second update')
Pierre-Yves Chibon d256ab
Pierre-Yves Chibon 82c8df
        # Create another issue from someone else
Pierre-Yves Chibon 82c8df
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 82c8df
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 82c8df
            session=self.session,
Pierre-Yves Chibon 82c8df
            repo=repo,
Pierre-Yves Chibon 82c8df
            title='Test issue',
Pierre-Yves Chibon 82c8df
            content='We should work on this',
Pierre-Yves Chibon 82c8df
            user='foo',
Pierre-Yves Chibon 82c8df
            ticketfolder=None
Pierre-Yves Chibon 82c8df
        )
Pierre-Yves Chibon 82c8df
        self.session.commit()
Pierre-Yves Chibon 82c8df
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 82c8df
        self.assertEqual(len(issue.comments), 1)
Pierre-Yves Chibon 82c8df
        self.assertEqual(issue.status, 'Open')
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 82c8df
        self.assertEqual(len(issue.comments), 0)
Pierre-Yves Chibon 82c8df
        self.assertEqual(issue.status, 'Open')
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon 82c8df
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 82c8df
            data = {
Pierre-Yves Chibon 82c8df
                'csrf_token' : csrf_token,
Pierre-Yves Chibon 82c8df
                'comment' : 'Nevermind figured it out',
Pierre-Yves Chibon 82c8df
                'status': 'Closed',
Pierre-Yves Chibon 82c8df
                'close_status': 'Invalid'
Pierre-Yves Chibon 82c8df
            }
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
            # Add a comment and close the ticket #1
Pierre-Yves Chibon 82c8df
            output = self.app.post(
Pierre-Yves Chibon 82c8df
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 82c8df
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 82c8df
            self.assertNotIn(
Pierre-Yves Chibon 82c8df
                '\n                      '
Pierre-Yves Chibon 82c8df
                'Successfully edited issue #1\n',
Pierre-Yves Chibon 82c8df
                output.data
Pierre-Yves Chibon 82c8df
            )
Pierre-Yves Chibon 82c8df
            self.assertIn(
Pierre-Yves Chibon 82c8df
                '\n                      Comment added\n',
Pierre-Yves Chibon 82c8df
                output.data
Pierre-Yves Chibon 82c8df
            )
Pierre-Yves Chibon 82c8df
            self.assertNotIn(
Pierre-Yves Chibon 82c8df
                'editmetadatatoggle">\n              Edit Metadata',
Pierre-Yves Chibon 82c8df
                output.data
Pierre-Yves Chibon 82c8df
            )
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
            data = {
Pierre-Yves Chibon 82c8df
                'csrf_token' : csrf_token,
Pierre-Yves Chibon 82c8df
                'comment' : 'Nevermind figured it out',
Pierre-Yves Chibon 82c8df
                'status': 'Closed',
Pierre-Yves Chibon 82c8df
                'close_status': 'Invalid'
Pierre-Yves Chibon 82c8df
            }
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
            # Add a comment and close the ticket #2
Pierre-Yves Chibon 82c8df
            output = self.app.post(
Pierre-Yves Chibon 82c8df
                '/test/issue/2/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 82c8df
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 82c8df
            self.assertIn(
Pierre-Yves Chibon 82c8df
                '\n                      '
Pierre-Yves Chibon 82c8df
                'Successfully edited issue #2\n',
Pierre-Yves Chibon 82c8df
                output.data
Pierre-Yves Chibon 82c8df
            )
Pierre-Yves Chibon 82c8df
            self.assertIn(
Pierre-Yves Chibon 82c8df
                '\n                      Comment added\n',
Pierre-Yves Chibon 82c8df
                output.data
Pierre-Yves Chibon 82c8df
            )
Pierre-Yves Chibon 82c8df
            self.assertIn(
Pierre-Yves Chibon 82c8df
                'editmetadatatoggle">\n              Edit Metadata',
Pierre-Yves Chibon 82c8df
                output.data
Pierre-Yves Chibon 82c8df
            )
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
        # Ticket #1 has one more comment and is still open
Pierre-Yves Chibon 82c8df
        issue = pagure.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 82c8df
        self.assertEqual(len(issue.comments), 2)
Pierre-Yves Chibon 82c8df
        self.assertEqual(issue.status, 'Open')
Pierre-Yves Chibon 82c8df
Pierre-Yves Chibon 82c8df
        # Ticket #2 has one more comment and is closed
Pierre-Yves Chibon 82c8df
        issue = pagure.lib.search_issues(self.session, repo, issueid=2)
Pierre-Yves Chibon 82c8df
        self.assertEqual(len(issue.comments), 2)
Pierre-Yves Chibon 82c8df
        self.assertEqual(issue.status, 'Closed')
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon 2fbe36
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 2fbe36
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 2fbe36
    def test_git_urls(self,  p_send_email, p_ugt):
Pierre-Yves Chibon 2fbe36
        """ Check that the url to the git repo for issues is present/absent when
Pierre-Yves Chibon 2fbe36
        it should.
Pierre-Yves Chibon 2fbe36
        """
Pierre-Yves Chibon 2fbe36
        p_send_email.return_value = True
Pierre-Yves Chibon 2fbe36
        p_ugt.return_value = True
Pierre-Yves Chibon 2fbe36
Pierre-Yves Chibon 2fbe36
        self.test_view_issues()
Pierre-Yves Chibon 2fbe36
Pierre-Yves Chibon 2fbe36
        user = tests.FakeUser()
Pierre-Yves Chibon 2fbe36
        user.username = 'pingou'
Pierre-Yves Chibon 2fbe36
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 2fbe36
            # Check that the git issue URL is present
Pierre-Yves Chibon 2fbe36
            output = self.app.get('/test')
Pierre-Yves Chibon 2fbe36
            self.assertNotIn(
Pierre-Yves Chibon 2fbe36
                '
Issues GIT URLs
', output.data)
Pierre-Yves Chibon 2fbe36
Pierre-Yves Chibon 2fbe36
            # Project w/o issue tracker
Pierre-Yves Chibon 2fbe36
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 2fbe36
            repo.settings = {'issue_tracker': True}
Pierre-Yves Chibon 2fbe36
            self.session.add(repo)
Pierre-Yves Chibon 2fbe36
            self.session.commit()
Pierre-Yves Chibon 2fbe36
Pierre-Yves Chibon 2fbe36
            # Check that the git issue URL is gone
Pierre-Yves Chibon 2fbe36
            output = self.app.get('/test')
Pierre-Yves Chibon 2fbe36
            self.assertIn(
Pierre-Yves Chibon 2fbe36
                '
Issues GIT URLs
', output.data)
Pierre-Yves Chibon 2fbe36
Pierre-Yves Chibon 2fa745
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 2fa745
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 2fa745
    def test_update_tags(self, p_send_email, p_ugt):
Pierre-Yves Chibon 2fa745
        """ Test the update_tags endpoint. """
Pierre-Yves Chibon 2fa745
        p_send_email.return_value = True
Pierre-Yves Chibon 2fa745
        p_ugt.return_value = True
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
        # No Git repo
Pierre-Yves Chibon 2fa745
        output = self.app.post('/foo/update/tags')
Pierre-Yves Chibon 2fa745
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
        user = tests.FakeUser()
Pierre-Yves Chibon 2fa745
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 2fa745
            output = self.app.post('/foo/update/tags')
Pierre-Yves Chibon 2fa745
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
            tests.create_projects(self.session)
Pierre-Yves Chibon 2fa745
            tests.create_projects_git(self.path)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
            output = self.app.post('/test/update/tags')
Pierre-Yves Chibon 2fa745
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
        # User not logged in
Pierre-Yves Chibon 2fa745
        output = self.app.post('/test/update/tags')
Pierre-Yves Chibon 2fa745
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
        # Create issues to play with
Pierre-Yves Chibon 2fa745
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 2fa745
        msg = pagure.lib.new_issue(
Pierre-Yves Chibon 2fa745
            session=self.session,
Pierre-Yves Chibon 2fa745
            repo=repo,
Pierre-Yves Chibon 2fa745
            title='Test issue',
Pierre-Yves Chibon 2fa745
            content='We should work on this',
Pierre-Yves Chibon 2fa745
            user='pingou',
Pierre-Yves Chibon 2fa745
            ticketfolder=None
Pierre-Yves Chibon 2fa745
        )
Pierre-Yves Chibon 2fa745
        self.session.commit()
Pierre-Yves Chibon 2fa745
        self.assertEqual(msg.title, 'Test issue')
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
         # Before update, list tags
Pierre-Yves Chibon 2fa745
        tags = pagure.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon 2fa745
        self.assertEqual([tag.tag for tag in tags], [])
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
        user.username = 'pingou'
Pierre-Yves Chibon 2fa745
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 2fa745
            # No CSRF
Pierre-Yves Chibon 2fa745
            data = {
Pierre-Yves Chibon 2fa745
                'tag': 'red',
Pierre-Yves Chibon 2fa745
                'tag_color': '#ff0000'
Pierre-Yves Chibon 2fa745
            }
Pierre-Yves Chibon 2fa745
            output = self.app.post(
Pierre-Yves Chibon 2fa745
                '/test/update/tags', data=data, follow_redirects=True)
Pierre-Yves Chibon 2fa745
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '        
    '
Pierre-Yves Chibon 2fa745
                '\n        ', output.data)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
            csrf_token = output.data.split(
Pierre-Yves Chibon 2fa745
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
            # Invalid color
Pierre-Yves Chibon 2fa745
            data = {
Pierre-Yves Chibon 2fa745
                'tag': 'red',
Pierre-Yves Chibon 2fa745
                'tag_color': 'red',
Pierre-Yves Chibon 2fa745
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2fa745
            }
Pierre-Yves Chibon 2fa745
            output = self.app.post(
Pierre-Yves Chibon 2fa745
                '/test/update/tags', data=data, follow_redirects=True)
Pierre-Yves Chibon 2fa745
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '\n                      '
Pierre-Yves Chibon 2fa745
                'Color: red does not match the expected pattern',
Pierre-Yves Chibon 2fa745
                output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '        
    '
Pierre-Yves Chibon 2fa745
                '\n        ', output.data)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
            # Inconsistent length color
Pierre-Yves Chibon 2fa745
            data = {
Pierre-Yves Chibon 2fa745
                'tag': ['red', 'blue'],
Pierre-Yves Chibon 2fa745
                'tag_color': 'red',
Pierre-Yves Chibon 2fa745
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2fa745
            }
Pierre-Yves Chibon 2fa745
            output = self.app.post(
Pierre-Yves Chibon 2fa745
                '/test/update/tags', data=data, follow_redirects=True)
Pierre-Yves Chibon 2fa745
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '\n                      '
Pierre-Yves Chibon 2fa745
                'Color: red does not match the expected pattern',
Pierre-Yves Chibon 2fa745
                output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '\n                      tags and tag colors'
Pierre-Yves Chibon 2fa745
                ' are not of the same length', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '        
    '
Pierre-Yves Chibon 2fa745
                '\n        ', output.data)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
            # Valid query
Pierre-Yves Chibon 2fa745
            data = {
Pierre-Yves Chibon 2fa745
                'tag': ['red', 'blue'],
Pierre-Yves Chibon 2fa745
                'tag_color': ['#ff0000', '#003cff'],
Pierre-Yves Chibon 2fa745
                'csrf_token': csrf_token,
Pierre-Yves Chibon 2fa745
            }
Pierre-Yves Chibon 2fa745
            output = self.app.post(
Pierre-Yves Chibon 2fa745
                '/test/update/tags', data=data, follow_redirects=True)
Pierre-Yves Chibon 2fa745
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '
Pierre-Yves Chibon 2fa745
                '#003cff">blue', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '<input name="tag" type="hidden" value="blue">',
Pierre-Yves Chibon 2fa745
                output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '
Pierre-Yves Chibon 2fa745
                '#ff0000">red', output.data)
Pierre-Yves Chibon 2fa745
            self.assertIn(
Pierre-Yves Chibon 2fa745
                '<input name="tag" type="hidden" value="red">',
Pierre-Yves Chibon 2fa745
                output.data)
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fa745
        # After update, list tags
Pierre-Yves Chibon 2fa745
        tags = pagure.lib.get_tags_of_project(self.session, repo)
Pierre-Yves Chibon 2fa745
        self.assertEqual([tag.tag for tag in tags], ['blue', 'red'])
Pierre-Yves Chibon 2fa745
Pierre-Yves Chibon 2fbe36
Pierre-Yves Chibon a52cca
if __name__ == '__main__':
Pierre-Yves Chibon fe5017
    SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskIssuestests)
Pierre-Yves Chibon a52cca
    unittest.TextTestRunner(verbosity=2).run(SUITE)