Blame tests/test_progit_flask_ui_issues.py

Pierre-Yves Chibon a52cca
# -*- coding: utf-8 -*-
Pierre-Yves Chibon a52cca
Pierre-Yves Chibon a52cca
"""
Pierre-Yves Chibon a52cca
 (c) 2015 - 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
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
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 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 a52cca
Pierre-Yves Chibon fe5017
        pagure.APP.config['GIT_FOLDER'] = tests.HERE
Pierre-Yves Chibon fe5017
        pagure.APP.config['FORK_FOLDER'] = os.path.join(
Pierre-Yves Chibon a52cca
            tests.HERE, 'forks')
Pierre-Yves Chibon fe5017
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Pierre-Yves Chibon a52cca
            tests.HERE, 'tickets')
Pierre-Yves Chibon fe5017
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Pierre-Yves Chibon a52cca
            tests.HERE, '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 a52cca
        output = self.app.get('/foo/new_issue')
Pierre-Yves Chibon a52cca
        self.assertEqual(output.status_code, 302)
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 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 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 a52cca
                'This field is required.'), 0)
Pierre-Yves Chibon a52cca
            self.assertTrue(
Pierre-Yves Chibon 45cb3d
                '\n                      No user "username" found'
Pierre-Yves Chibon a52cca
                in output.data)
Pierre-Yves Chibon a52cca
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 45cb3d
                '\n                      Issue created', output.data)
Pierre-Yves Chibon df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon f8911e
            self.assertTrue(
Pierre-Yves Chibon f8911e
                '

test project #1

'
Pierre-Yves Chibon f8911e
                in 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(
Pierre-Yves Chibon 272d30
            os.path.join(tests.HERE, '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
Pierre-Yves Chibon 272d30
            stream = open(os.path.join(tests.HERE, 'placebo.png'), 'r')
Pierre-Yves Chibon 272d30
            data = {
Pierre-Yves Chibon 272d30
                'title': 'Test issue',
Pierre-Yves Chibon 272d30
                'issue_content': 'We really should improve on this issue\n'
Pierre-Yves Chibon 272d30
                    '',
Pierre-Yves Chibon 272d30
                'status': 'Open',
Pierre-Yves Chibon 272d30
                'filestream': stream,
Pierre-Yves Chibon 272d30
                'enctype': 'multipart/form-data',
Pierre-Yves Chibon 272d30
                'csrf_token': csrf_token,
Pierre-Yves Chibon 272d30
            }
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
            output = self.app.post(
Pierre-Yves Chibon 272d30
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 272d30
            stream.close()
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Issue created', output.data)
Pierre-Yves Chibon 272d30
            self.assertTrue(
Pierre-Yves Chibon 272d30
                '

test project #1

'
Pierre-Yves Chibon 272d30
                in output.data)
Pierre-Yves Chibon f8911e
            self.assertTrue(
Pierre-Yves Chibon f8911e
                '

test project #1

'
Pierre-Yves Chibon f8911e
                in 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):
Pierre-Yves Chibon 272d30
            stream = open(os.path.join(tests.HERE, 'placebo.png'), 'r')
Pierre-Yves Chibon 272d30
            data = {
Pierre-Yves Chibon 272d30
                'title': 'Test issue',
Pierre-Yves Chibon 272d30
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 272d30
                'status': 'Open',
Pierre-Yves Chibon 272d30
                'filestream': stream,
Pierre-Yves Chibon 272d30
                'enctype': 'multipart/form-data',
Pierre-Yves Chibon 272d30
                'csrf_token': csrf_token,
Pierre-Yves Chibon 272d30
            }
Pierre-Yves Chibon 272d30
Pierre-Yves Chibon 272d30
            output = self.app.post(
Pierre-Yves Chibon 272d30
                '/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 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 7dfb23
Pierre-Yves Chibon 7dfb23
        output = self.app.get('/test/issues')
Pierre-Yves Chibon 7dfb23
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 7dfb23
        self.assertTrue('

test project #1

' in output.data)
Pierre-Yves Chibon 1a43f3
        self.assertTrue(
Pierre-Yves Chibon 1a43f3
            '

\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 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 df35d8
        self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 1a43f3
        self.assertTrue(
Pierre-Yves Chibon 1a43f3
            '

\n 1 Open Issues' in output.data)

Pierre-Yves Chibon 7dfb23
Pierre-Yves Chibon 7dfb23
        # Status = closed
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 df35d8
        self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 7dfb23
        self.assertTrue(
Pierre-Yves Chibon 1a43f3
            '

\n 0 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 df35d8
        self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 7dfb23
        self.assertTrue(
Pierre-Yves Chibon 1a43f3
            '

\n 0 Closed Issues' in output.data)

Pierre-Yves Chibon 7dfb23
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 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 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 df35d8
        self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 5fee8b
        self.assertTrue(
Pierre-Yves Chibon 3b3f67
            '

Pierre-Yves Chibon 3b3f67
            '">Login 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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 5fee8b
            self.assertFalse(
Pierre-Yves Chibon 5fee8b
                '

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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 871eed
        output = self.app.get('/foo/issue/1/update')
Pierre-Yves Chibon 1deb85
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 5f82f8
Pierre-Yves Chibon 5f82f8
        tests.create_projects(self.session)
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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 5fee8b
                '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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 5fee8b
            data['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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 5fee8b
Pierre-Yves Chibon 4b0f25
            # Add new comment
Pierre-Yves Chibon 4b0f25
            data = {
Pierre-Yves Chibon 4b0f25
                'csrf_token': csrf_token,
Pierre-Yves Chibon 4b0f25
                '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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 4b0f25
            self.assertEqual(
Pierre-Yves Chibon 4b0f25
                output.data.count('
'), 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 4b0f25
                '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 4b0f25
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Tag added: tag2',
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 4b0f25
            self.assertEqual(
Pierre-Yves Chibon 4b0f25
                output.data.count('
'), 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 4b0f25
                '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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 4b0f25
            self.assertEqual(
Pierre-Yves Chibon 4b0f25
                output.data.count('
'), 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 4b0f25
                '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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 4b0f25
            self.assertEqual(
Pierre-Yves Chibon 4b0f25
                output.data.count('
'), 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 5fee8b
            self.session, repo, issueid=2)
Pierre-Yves Chibon 5fee8b
        parent_issue.status = 'Open'
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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in 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 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 e2164c
            self.assertTrue(
Pierre-Yves Chibon e2164c
                '

test project #1

'
Pierre-Yves Chibon e2164c
                in 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 e2164c
            self.assertTrue(
Pierre-Yves Chibon e2164c
                '

test project #1

'
Pierre-Yves Chibon e2164c
                in 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 e2164c
            self.assertEqual(
Pierre-Yves Chibon e2164c
                output.data.count('
'), 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 e2164c
            self.assertTrue(
Pierre-Yves Chibon e2164c
                '

test project #1

'
Pierre-Yves Chibon e2164c
                in 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 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 3c91f0
            self.assertTrue(
Pierre-Yves Chibon 3c91f0
                '

test project #1

'
Pierre-Yves Chibon 3c91f0
                in 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 3c91f0
            self.assertTrue(
Pierre-Yves Chibon 3c91f0
                '

test project #1

'
Pierre-Yves Chibon 3c91f0
                in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Dependency added',
Pierre-Yves Chibon 45cb3d
                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 3c91f0
            self.assertTrue(
Pierre-Yves Chibon 3c91f0
                '

test project #1

'
Pierre-Yves Chibon 3c91f0
                in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertNotIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Dependency added', 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 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 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 e6906a
            self.assertTrue(
Pierre-Yves Chibon e6906a
                '

test project #1

'
Pierre-Yves Chibon e6906a
                in 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 e6906a
            self.assertTrue(
Pierre-Yves Chibon e6906a
                '

test project #1

'
Pierre-Yves Chibon e6906a
                in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Dependency added',
Pierre-Yves Chibon 45cb3d
                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 e6906a
            self.assertTrue(
Pierre-Yves Chibon e6906a
                '

test project #1

'
Pierre-Yves Chibon e6906a
                in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertNotIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Dependency added',
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. """
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(
Pierre-Yves Chibon ca67cd
            os.path.join(tests.HERE, '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 ca67cd
            self.assertTrue(
Pierre-Yves Chibon ca67cd
                '

test project #1

'
Pierre-Yves Chibon ca67cd
                in 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 ca67cd
            # Attach a file to a ticket
Pierre-Yves Chibon ca67cd
            stream = open(os.path.join(tests.HERE, 'placebo.png'), 'rb')
Pierre-Yves Chibon ca67cd
            data = {
Pierre-Yves Chibon ca67cd
                'csrf_token': csrf_token,
Pierre-Yves Chibon ca67cd
                'filestream': stream,
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
            stream.close()
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(
Pierre-Yves Chibon 47316a
            os.path.join(tests.HERE, '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 161728
        output = self.app.get('/foo/issue/1/edit')
Pierre-Yves Chibon 161728
        self.assertEqual(output.status_code, 302)
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 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 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 1a43f3
                '<small>\n                      This field is required'</small>
Pierre-Yves Chibon 1a43f3
                '. \n                    '), 1)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 1a43f3
                '<small>\n                      Not a valid choice'</small>
Pierre-Yves Chibon 1a43f3
                ' \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 1a43f3
                '<small>\n                      This field is required'</small>
Pierre-Yves Chibon 1a43f3
                '. \n                    '), 0)
Pierre-Yves Chibon 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 1a43f3
                '<small>\n                      Not a valid choice'</small>
Pierre-Yves Chibon 1a43f3
                '. \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 161728
            self.assertEqual(output.data.count(
Pierre-Yves Chibon 1a43f3
                '
\n'
Pierre-Yves Chibon 1a43f3
                '        

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 aa7f0a
        output = self.app.get('/foo/tag/foo/edit')
Pierre-Yves Chibon aa7f0a
        self.assertEqual(output.status_code, 302)
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)
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 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):
Pierre-Yves Chibon aa7f0a
            output = self.app.get('/test/tag/tag1/edit')
Pierre-Yves Chibon aa7f0a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon aa7f0a
            self.assertTrue('

Edit tag: tag1

' in output.data)
Pierre-Yves Chibon aa7f0a
            self.assertTrue(
Pierre-Yves Chibon aa7f0a
                '

Enter in the field below the new name for the tag: '

Pierre-Yves Chibon aa7f0a
                '"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
Pierre-Yves Chibon aa7f0a
            data = {'tag': 'tag2'}
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)
Pierre-Yves Chibon aa7f0a
            self.assertTrue('

Edit tag: tag1

' in output.data)
Pierre-Yves Chibon aa7f0a
            self.assertTrue(
Pierre-Yves Chibon aa7f0a
                '

Enter in the field below the new name for the tag: '

Pierre-Yves Chibon aa7f0a
                '"tag1"

' in output.data)
Pierre-Yves Chibon aa7f0a
Pierre-Yves Chibon aa7f0a
            data['csrf_token'] = csrf_token
Ghost-script ac44e3
            tests.create_projects_git(tests.HERE)
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 df35d8
            self.assertTrue(
Pierre-Yves Chibon df35d8
                '

test project #1

'
Pierre-Yves Chibon df35d8
                in output.data)
Pierre-Yves Chibon 45cb3d
            self.assertIn(
Pierre-Yves Chibon 45cb3d
                '\n                      Edited tag: tag1 to tag2',
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 269165
        output = self.app.post('/foo/droptag/')
Pierre-Yves Chibon 269165
        self.assertEqual(output.status_code, 302)
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)
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 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):
Ghost-script ac44e3
            tests.create_projects_git(tests.HERE)
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)
Pierre-Yves Chibon 4a0d3b
        tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 4a0d3b
        tests.create_projects_git(os.path.join(tests.HERE, '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 4a0d3b
                '<title>Issue #1 - test - Pagure</title>', 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 4a0d3b
                '<title>Issue #1 - test - Pagure</title>', 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 45cb3d
                '\n                      Issue deleted', 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 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 d256ab
            self.assertTrue(
Pierre-Yves Chibon d256ab
                '

test project #1

'
Pierre-Yves Chibon d256ab
                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
            # 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 d256ab
            self.assertTrue(
Pierre-Yves Chibon d256ab
                '

test project #1

'
Pierre-Yves Chibon d256ab
                in 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 d256ab
            self.assertEqual(
Pierre-Yves Chibon d256ab
                output.data.count('
'), 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 d256ab
        self.assertEqual(issue.comments[0].comment, '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 d256ab
            self.assertTrue(
Pierre-Yves Chibon d256ab
                '

test project #1

'
Pierre-Yves Chibon d256ab
                in 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 d256ab
            self.assertTrue(
Pierre-Yves Chibon d256ab
                '

test project #1

'
Pierre-Yves Chibon d256ab
                in 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 d256ab
            self.assertTrue(
Pierre-Yves Chibon d256ab
                '

test project #1

'
Pierre-Yves Chibon d256ab
                in 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 a52cca
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)