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 a52cca
            self.assertTrue('

New issue

' 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 a52cca
            self.assertTrue('

New issue

' 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 a52cca
            self.assertTrue('

New issue

' 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 a52cca
            self.assertTrue('

New issue

' 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
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 a52cca
            self.assertTrue('

New issue

' 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 a52cca
                '
  • 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 a52cca
                self.assertTrue(
    Pierre-Yves Chibon a52cca
                    '
  • Issue created
  • ' in 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 a52cca
                self.assertTrue('

    \n Issues (1)\n

    ' in output.data)
    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 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 7dfb23
            self.assertTrue('

    \n Issues (0)\n

    ' 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 7dfb23
            self.assertTrue('

    \n Issues (1)\n

    ' 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 7dfb23
                '

    \n Closed\n Issues (0)\n

    ' 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 7dfb23
                '

    \n Closed\n Issues (0)\n

    ' 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 719bdd
            repo.save_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 719bdd
            repo.save_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 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 5fee8b
                self.assertTrue(
    Pierre-Yves Chibon 5fee8b
                    '
  • Edited successfully issue #1
  • '
    Pierre-Yves Chibon 5fee8b
                    in 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 4b0f25
                self.assertTrue(
    Pierre-Yves Chibon 4b0f25
                    '
  • Comment added
  • ' in output.data)
    Pierre-Yves Chibon d22433
                self.assertFalse(
    Pierre-Yves Chibon 4b0f25
                    'li class="message">No changes to edit' 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 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 4b0f25
                    'tag': 'tag#2',
    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 df35d8
                self.assertTrue(
    Pierre-Yves Chibon df35d8
                    '
  • Tag added: tag#2
  • ' in output.data)
    Pierre-Yves Chibon d22433
                self.assertFalse(
    Pierre-Yves Chibon 4b0f25
                    'li class="message">No changes to edit' 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 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 4b0f25
                self.assertTrue(
    Pierre-Yves Chibon 4b0f25
                    '
  • No user "ralph" found
  • '
    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 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 4b0f25
                self.assertTrue(
    Pierre-Yves Chibon 4b0f25
                    '
  • Issue assigned
  • ' in 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 5fee8b
                self.assertTrue(
    Pierre-Yves Chibon 5fee8b
                    '
  • You cannot close a ticket that has ticket '
  • Pierre-Yves Chibon 5fee8b
                    'depending that are still open.' in 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 719bdd
            repo.save_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 fe5017
        @patch('pagure.lib.git.update_git')
    Pierre-Yves Chibon fe5017
        @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 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, 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 161728
                self.assertTrue('

    Edit issue #1

    ' 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 161728
                self.assertTrue('

    Edit issue #1

    ' in output.data)
    Pierre-Yves Chibon 161728
                self.assertEqual(output.data.count(
    Pierre-Yves Chibon 161728
                    'This field is required.'), 1)
    Pierre-Yves Chibon 161728
                self.assertEqual(output.data.count(
    Pierre-Yves Chibon 161728
                    'Not a valid choice'), 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 161728
                self.assertTrue('

    Edit issue #1

    ' in output.data)
    Pierre-Yves Chibon 161728
                self.assertEqual(output.data.count(
    Pierre-Yves Chibon 161728
                    'This field is required.'), 0)
    Pierre-Yves Chibon 161728
                self.assertEqual(output.data.count(
    Pierre-Yves Chibon 161728
                    'Not a valid choice'), 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 161728
                self.assertTrue(
    Pierre-Yves Chibon 161728
                    '#1 Test issue #1'
    Pierre-Yves Chibon 161728
                    in 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 56682f
                    '
    \n '
    Pierre-Yves Chibon 161728
                    '

    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 719bdd
            repo.save_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 fe5017
            msg = pagure.lib.add_issue_tag(
    Pierre-Yves Chibon aa7f0a
                session=self.session,
    Pierre-Yves Chibon aa7f0a
                issue=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
    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 aa7f0a
                self.assertTrue(
    Pierre-Yves Chibon aa7f0a
                    '
  • Edited tag: tag1 to tag2
  • '
    Pierre-Yves Chibon aa7f0a
                    in 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 fe5017
            msg = pagure.lib.add_issue_tag(
    Pierre-Yves Chibon 269165
                session=self.session,
    Pierre-Yves Chibon 269165
                issue=issue,
    Pierre-Yves Chibon df35d8
                tags='tag1',
    Pierre-Yves Chibon 269165
                user='pingou',
    Pierre-Yves Chibon 269165
                ticketfolder=None)
    Pierre-Yves Chibon 269165
            self.session.commit()
    Pierre-Yves Chibon df35d8
            self.assertEqual(msg, 'Tag added: tag1')
    Pierre-Yves Chibon 269165
    Pierre-Yves Chibon 269165
            # Before edit, list tags
    Pierre-Yves Chibon fe5017
            tags = pagure.lib.get_tags_of_project(self.session, repo)
    Pierre-Yves Chibon 269165
            self.assertEqual([tag.tag for tag in tags], ['tag1'])
    Pierre-Yves Chibon 269165
    Pierre-Yves Chibon 269165
            # Edit tag
    Pierre-Yves Chibon 269165
            user.username = 'pingou'
    Pierre-Yves Chibon fe5017
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 269165
                output = self.app.post(
    Pierre-Yves Chibon 269165
                    '/test/droptag/', data={}, follow_redirects=True)
    Pierre-Yves Chibon 269165
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 269165
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 269165
                self.assertTrue(
    Pierre-Yves Chibon 269165
                    '
      \n
    ' 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 269165
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 269165
                self.assertTrue(
    Pierre-Yves Chibon 269165
                    '
      \n
    ' 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 269165
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 269165
                self.assertTrue(
    Pierre-Yves Chibon 269165
                    '
  • Removed tag: tag1
  • ' in output.data)
    Pierre-Yves Chibon 269165
    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)