Blame tests/test_pagure_flask_ui_priorities.py

Pierre-Yves Chibon af88e9
# -*- coding: utf-8 -*-
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
"""
Pierre-Yves Chibon 77bdcd
 (c) 2016-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
 Authors:
Pierre-Yves Chibon af88e9
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
"""
Pierre-Yves Chibon af88e9
Aurélien Bompard 626417
from __future__ import unicode_literals
Aurélien Bompard 626417
Pierre-Yves Chibon af88e9
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon af88e9
import pkg_resources
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
import datetime
Pierre-Yves Chibon af88e9
import json
Pierre-Yves Chibon af88e9
import unittest
Pierre-Yves Chibon af88e9
import shutil
Pierre-Yves Chibon af88e9
import sys
Pierre-Yves Chibon af88e9
import tempfile
Pierre-Yves Chibon af88e9
import os
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
import pygit2
Pierre-Yves Chibon dff667
from mock import patch, MagicMock
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon af88e9
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon af88e9
Farhaan Bukhsh 72e9db
import pagure
Pierre-Yves Chibon af88e9
import pagure.lib
Pierre-Yves Chibon af88e9
import tests
Pierre-Yves Chibon af88e9
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
class PagureFlaskPrioritiestests(tests.Modeltests):
Pierre-Yves Chibon af88e9
    """ Tests for the behavior of priorities in pagure """
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon af88e9
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon af88e9
    def test_ticket_with_no_priority(self, p_send_email, p_ugt):
Pierre-Yves Chibon af88e9
        """ Test creating a ticket without priority. """
Pierre-Yves Chibon af88e9
        p_send_email.return_value = True
Pierre-Yves Chibon af88e9
        p_ugt.return_value = True
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        user = tests.FakeUser()
Pierre-Yves Chibon af88e9
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            # Get the CSRF token
Pierre-Yves Chibon af88e9
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon af88e9
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon af88e9
            self.assertTrue(
Ryan Lerch 7230c1
                '

New Issue

\n'
Aurélien Bompard 626417
                in output_text)
Pierre-Yves Chibon af88e9
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon af88e9
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            data = {
Pierre-Yves Chibon af88e9
                'title': 'Test issue',
Pierre-Yves Chibon af88e9
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon af88e9
                'status': 'Open',
Pierre-Yves Chibon af88e9
                'csrf_token': csrf_token,
Pierre-Yves Chibon af88e9
            }
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            # Create the issue
Pierre-Yves Chibon af88e9
            output = self.app.post(
Pierre-Yves Chibon af88e9
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon af88e9
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon af88e9
            self.assertIn(
Pierre-Yves Chibon af88e9
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon af88e9
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon af88e9
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertNotIn('
', output_text)
Aurélien Bompard 626417
            self.assertNotIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon af88e9
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon af88e9
    def test_ticket_with_priorities(self, p_send_email, p_ugt):
Pierre-Yves Chibon af88e9
        """ Test creating a ticket with priorities. """
Pierre-Yves Chibon af88e9
        p_send_email.return_value = True
Pierre-Yves Chibon af88e9
        p_ugt.return_value = True
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        # Set some priorities
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon af88e9
        repo.priorities = {'1': 'High', '2': 'Normal'}
Pierre-Yves Chibon af88e9
        self.session.add(repo)
Pierre-Yves Chibon af88e9
        self.session.commit()
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        user = tests.FakeUser()
Pierre-Yves Chibon af88e9
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            # Get the CSRF token
Pierre-Yves Chibon af88e9
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon af88e9
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon af88e9
            self.assertTrue(
Ryan Lerch 7230c1
                '

New Issue

\n'
Aurélien Bompard 626417
                in output_text)
Pierre-Yves Chibon af88e9
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon af88e9
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            data = {
Pierre-Yves Chibon af88e9
                'title': 'Test issue',
Pierre-Yves Chibon af88e9
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon af88e9
                'status': 'Open',
Pierre-Yves Chibon af88e9
                'csrf_token': csrf_token,
Pierre-Yves Chibon af88e9
            }
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            # Create the issue
Pierre-Yves Chibon af88e9
            output = self.app.post(
Pierre-Yves Chibon af88e9
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon af88e9
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon af88e9
            self.assertIn(
Pierre-Yves Chibon af88e9
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon af88e9
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon af88e9
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon 3d1519
    def test_update_priorities(self):
Pierre-Yves Chibon 3d1519
        """ Test updating priorities of a repo. """
Pierre-Yves Chibon 3d1519
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
        # Set some priorities
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
        user = tests.FakeUser()
Pierre-Yves Chibon 3d1519
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            # Get the CSRF token
Pierre-Yves Chibon 3d1519
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 3d1519
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': 1,
Pierre-Yves Chibon 3d1519
                'priority_title': 'High',
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- None, no CSRF
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': 1,
Pierre-Yves Chibon 3d1519
                'priority_title': 'High',
Pierre-Yves Chibon 3d1519
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Aurélien Bompard 626417
            self.assertEqual(repo.priorities, {'': '', '1': 'High'})
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': [1, 2, 3],
Pierre-Yves Chibon 3d1519
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 3d1519
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Patrick Uiterwijk a764eb
            # Check the ordering
Patrick Uiterwijk a764eb
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('High') < output_text.find('Normal'))
Patrick Uiterwijk a764eb
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('Normal') < output_text.find('Low'))
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 3d1519
            )
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            # Check error - less weigths than titles
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': [1, 2],
Pierre-Yves Chibon 3d1519
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 3d1519
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Ryan Lerch 90916a
                'Priorities weights and titles are '
Aurélien Bompard 626417
                'not of the same length', output_text)
Pierre-Yves Chibon b130e5
            # Check the result of the action -- Priorities un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 3d1519
            )
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            # Check error - weigths must be integer
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': [1, 2, 'c'],
Pierre-Yves Chibon 3d1519
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 3d1519
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Ryan Lerch 90916a
                'Priorities weights must be numbers',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priorities un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 3d1519
            )
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            # Check error - Twice the same priority weigth
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': [1, 2, 2],
Pierre-Yves Chibon 3d1519
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 3d1519
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Ryan Lerch 90916a
                'Priority weight 2 is present 2 times',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priorities un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 3d1519
            )
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            # Check error - Twice the same priority title
Pierre-Yves Chibon 3d1519
            data = {
Pierre-Yves Chibon 3d1519
                'priority_weigth': [1, 2, 3],
Pierre-Yves Chibon 3d1519
                'priority_title': ['High', 'Normal', 'Normal'],
Pierre-Yves Chibon 3d1519
                'csrf_token': csrf_token,
Pierre-Yves Chibon 3d1519
            }
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Ryan Lerch 90916a
                'Priority Normal is present 2 times',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priorities un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 3d1519
            )
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon 3d1519
            settings = repo.settings
Pierre-Yves Chibon 3d1519
            settings['issue_tracker'] = False
Pierre-Yves Chibon 3d1519
            repo.settings = settings
Pierre-Yves Chibon 3d1519
            self.session.add(repo)
Pierre-Yves Chibon 3d1519
            self.session.commit()
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            output = self.app.post(
Pierre-Yves Chibon 3d1519
                '/test/update/priorities', data=data)
Pierre-Yves Chibon 3d1519
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 068320
            # Check for an invalid project
Pierre-Yves Chibon 068320
            output = self.app.post(
Pierre-Yves Chibon 068320
                '/foo/update/priorities', data=data)
Pierre-Yves Chibon 068320
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 068320
Pierre-Yves Chibon 068320
        # Check for a non-admin user
Pierre-Yves Chibon 068320
        settings = repo.settings
Pierre-Yves Chibon 068320
        settings['issue_tracker'] = True
Pierre-Yves Chibon 068320
        repo.settings = settings
Pierre-Yves Chibon 068320
        self.session.add(repo)
Pierre-Yves Chibon 068320
        self.session.commit()
Pierre-Yves Chibon 068320
Pierre-Yves Chibon 068320
        user.username = 'ralph'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 068320
            output = self.app.post(
Pierre-Yves Chibon 068320
                '/test/update/priorities', data=data)
Pierre-Yves Chibon 068320
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 068320
Pierre-Yves Chibon 7b3aee
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 7b3aee
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 7b3aee
    def test_reset_priorities(self, p_send_email, p_ugt):
Pierre-Yves Chibon 7b3aee
        """ Test resetting the priorities of a repo. """
Pierre-Yves Chibon 7b3aee
        p_send_email.return_value = True
Pierre-Yves Chibon 7b3aee
        p_ugt.return_value = True
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
        # Start from scrach on priorities
Farhaan Bukhsh 940880
        repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 7b3aee
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
        user = tests.FakeUser()
Pierre-Yves Chibon 7b3aee
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Get the CSRF token
Pierre-Yves Chibon 7b3aee
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 7b3aee
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 7b3aee
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Set some priorities
Pierre-Yves Chibon 7b3aee
            data = {
Pierre-Yves Chibon 7b3aee
                'priority_weigth': [1, 2, 3],
Pierre-Yves Chibon 7b3aee
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 7b3aee
                'csrf_token': csrf_token,
Pierre-Yves Chibon 7b3aee
            }
Pierre-Yves Chibon 7b3aee
            output = self.app.post(
Pierre-Yves Chibon 7b3aee
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Farhaan Bukhsh 940880
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(
Pierre-Yves Chibon 7b3aee
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 7b3aee
            )
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Create an issue
Pierre-Yves Chibon 7b3aee
            data = {
Pierre-Yves Chibon 7b3aee
                'title': 'Test issue',
Pierre-Yves Chibon 7b3aee
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 7b3aee
                'status': 'Open',
Pierre-Yves Chibon 7b3aee
                'csrf_token': csrf_token,
Pierre-Yves Chibon 7b3aee
            }
Pierre-Yves Chibon 7b3aee
            output = self.app.post(
Pierre-Yves Chibon 7b3aee
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Pierre-Yves Chibon 7b3aee
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 7b3aee
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Check that the ticket *does* have priorities
Pierre-Yves Chibon 7b3aee
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Reset the priorities
Pierre-Yves Chibon 7b3aee
            data = {
Pierre-Yves Chibon 7b3aee
                'csrf_token': csrf_token,
Pierre-Yves Chibon 7b3aee
            }
Pierre-Yves Chibon 7b3aee
            output = self.app.post(
Pierre-Yves Chibon 7b3aee
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Check that the issue list renders fine
Pierre-Yves Chibon 7b3aee
            output = self.app.get('/test/issues')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Check that the ticket *does not* have priorities
Pierre-Yves Chibon 7b3aee
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertNotIn('
', output_text)
Aurélien Bompard 626417
            self.assertNotIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon b130e5
            # Check the result of the action -- Priority reset
Aurélien Bompard 13bcde
            self.session.commit()
Farhaan Bukhsh 940880
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 138ab4
    def test_reset_priorities_None(self, p_send_email, p_ugt):
Pierre-Yves Chibon 138ab4
        """ Test resetting the priorities of a repo. """
Pierre-Yves Chibon 138ab4
        p_send_email.return_value = True
Pierre-Yves Chibon 138ab4
        p_ugt.return_value = True
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        tests.create_projects(self.session)
Pierre-Yves Chibon 138ab4
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        # Start from scrach on priorities
Pierre-Yves Chibon 138ab4
        repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        user = tests.FakeUser()
Pierre-Yves Chibon 138ab4
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Get the CSRF token
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 138ab4
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set some priorities
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority_weigth': [1, 2, 3],
Pierre-Yves Chibon 138ab4
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 138ab4
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
            self.assertEqual(
Pierre-Yves Chibon 138ab4
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 138ab4
            )
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Create an issue
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'title': 'Test issue',
Pierre-Yves Chibon 138ab4
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 138ab4
                'status': 'Open',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check that the ticket *does* have priorities
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Reset the priorities
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority': None,
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check that the issue list renders fine
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/issues')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check that the ticket *does not* have priorities
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertNotIn('
', output_text)
Aurélien Bompard 626417
            self.assertNotIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 138ab4
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
            self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 138ab4
    def test_set_priority_1_and_back(self):
Pierre-Yves Chibon 138ab4
        """ Test setting the priority of a ticket to 1. """
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        tests.create_projects(self.session)
Pierre-Yves Chibon 138ab4
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        # Start from scrach on priorities
Pierre-Yves Chibon 138ab4
        repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        user = tests.FakeUser()
Pierre-Yves Chibon 138ab4
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Get the CSRF token
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 138ab4
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set some priorities
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority_weigth': [-1, 0, 1, 2, 3],
Pierre-Yves Chibon 138ab4
                'priority_title': [
Pierre-Yves Chibon 138ab4
                    'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 138ab4
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
            self.assertEqual(
Pierre-Yves Chibon 138ab4
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '-1': 'Sky Falling', '0': 'Urgent',
Aurélien Bompard 626417
                 '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 138ab4
            )
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Create an issue
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'title': 'Test issue',
Pierre-Yves Chibon 138ab4
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 138ab4
                'status': 'Open',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check that the ticket *does* have priorities
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option value="-1">Sky Falling</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="0">Urgent</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set the priority to High
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority': '1',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option value="-1">Sky Falling</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="0">Urgent</option>', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option selected="" value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Reset the priority
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority': '',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option value="-1">Sky Falling</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="0">Urgent</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 138ab4
    def test_set_priority_0(self):
Pierre-Yves Chibon 138ab4
        """ Test setting the priority of a ticket to 0. """
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        tests.create_projects(self.session)
Pierre-Yves Chibon 138ab4
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        # Start from scrach on priorities
Pierre-Yves Chibon 138ab4
        repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        user = tests.FakeUser()
Pierre-Yves Chibon 138ab4
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Get the CSRF token
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 138ab4
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set some priorities
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority_weigth': [-1, 0, 1, 2, 3],
Pierre-Yves Chibon 138ab4
                'priority_title': [
Pierre-Yves Chibon 138ab4
                    'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 138ab4
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
            self.assertEqual(
Pierre-Yves Chibon 138ab4
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '-1': 'Sky Falling', '0': 'Urgent',
Aurélien Bompard 626417
                 '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 138ab4
            )
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Create an issue
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'title': 'Test issue',
Pierre-Yves Chibon 138ab4
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 138ab4
                'status': 'Open',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check that the ticket *does* have priorities
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option value="-1">Sky Falling</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="0">Urgent</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set the priority to Urgent
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority': '0',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option value="-1">Sky Falling</option>', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<option selected="" value="0">Urgent</option>',
Aurélien Bompard 626417
                output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 138ab4
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 138ab4
    def test_set_priority_minus1(self):
Pierre-Yves Chibon 138ab4
        """ Test setting the priority of a ticket to -1. """
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        tests.create_projects(self.session)
Pierre-Yves Chibon 138ab4
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        # Start from scrach on priorities
Pierre-Yves Chibon 138ab4
        repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
        user = tests.FakeUser()
Pierre-Yves Chibon 138ab4
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Get the CSRF token
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 138ab4
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set some priorities
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority_weigth': [-1, 0, 1, 2, 3],
Pierre-Yves Chibon 138ab4
                'priority_title': [
Pierre-Yves Chibon 138ab4
                    'Sky Falling', 'Urgent', 'High', 'Normal', 'Low'],
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 138ab4
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 138ab4
            self.assertEqual(
Pierre-Yves Chibon 138ab4
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '-1': 'Sky Falling', '0': 'Urgent',
Aurélien Bompard 626417
                 '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 138ab4
            )
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Create an issue
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'title': 'Test issue',
Pierre-Yves Chibon 138ab4
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 138ab4
                'status': 'Open',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Check that the ticket *does* have priorities
Pierre-Yves Chibon 138ab4
            output = self.app.get('/test/issue/1')
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Aurélien Bompard 626417
                '<option value="-1">Sky Falling</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="0">Urgent</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            # Set the priority to Sky Falling
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            data = {
Pierre-Yves Chibon 138ab4
                'priority': '-1',
Pierre-Yves Chibon 138ab4
                'csrf_token': csrf_token,
Pierre-Yves Chibon 138ab4
            }
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon 138ab4
            output = self.app.post(
Pierre-Yves Chibon 138ab4
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 138ab4
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 138ab4
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Ryan Lerch e85d33
            self.assertIn('
', output_text)
Pierre-Yves Chibon 138ab4
            self.assertIn(
Pierre-Yves Chibon 138ab4
                '<option selected="" value="-1">Sky Falling</option>',
Aurélien Bompard 626417
                output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="0">Urgent</option>', output_text)
Aurélien Bompard 626417
            self.assertIn('<option value="1">High</option>', output_text)
Pierre-Yves Chibon 138ab4
Pierre-Yves Chibon dff667
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon dff667
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon dff667
    def test_default_priority(self):
Pierre-Yves Chibon dff667
        """ Test updating the default priority of a repo. """
Pierre-Yves Chibon dff667
        tests.create_projects(self.session)
Pierre-Yves Chibon dff667
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
        # Check the default priorities
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dff667
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon dff667
        self.assertEqual(repo.default_priority, None)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
        user = tests.FakeUser()
Pierre-Yves Chibon dff667
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            csrf_token = self.get_csrf()
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # Set some priorities
Pierre-Yves Chibon dff667
            data = {
Pierre-Yves Chibon dff667
                'priority_weigth': [1, 2, 3],
Pierre-Yves Chibon dff667
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon dff667
                'csrf_token': csrf_token,
Pierre-Yves Chibon dff667
            }
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon dff667
            # Check the redirect
Pierre-Yves Chibon dff667
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon dff667
            # Check the ordering
Pierre-Yves Chibon dff667
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('High') < output_text.find('Normal'))
Pierre-Yves Chibon dff667
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('Normal') < output_text.find('Low'))
Pierre-Yves Chibon dff667
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dff667
            self.assertEqual(
Pierre-Yves Chibon dff667
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon dff667
            )
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # Try setting the default priority  --  no csrf
Pierre-Yves Chibon dff667
            data = {'priority': 'High'}
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/default_priority', data=data,
Pierre-Yves Chibon dff667
                follow_redirects=True)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon dff667
            # Check the redirect
Pierre-Yves Chibon dff667
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon dff667
            # Check the result of the action -- default_priority no change
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dff667
            self.assertEqual(repo.default_priority, None)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # Try setting the default priority
Pierre-Yves Chibon dff667
            data = {'priority': 'High', 'csrf_token': csrf_token}
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/default_priority', data=data,
Pierre-Yves Chibon dff667
                follow_redirects=True)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon dff667
            # Check the redirect
Pierre-Yves Chibon dff667
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon dff667
            self.assertIn(
Ryan Lerch 90916a
                'Default priority set '
Aurélien Bompard 626417
                'to High', output_text)
Pierre-Yves Chibon dff667
            # Check the result of the action -- default_priority no change
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dff667
            self.assertEqual(repo.default_priority, 'High')
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # Try setting a wrong default priority
Pierre-Yves Chibon dff667
            data = {'priority': 'Smooth', 'csrf_token': csrf_token}
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/default_priority', data=data,
Pierre-Yves Chibon dff667
                follow_redirects=True)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon dff667
            # Check the redirect
Pierre-Yves Chibon dff667
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon dff667
            # Check the result of the action -- default_priority no change
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dff667
            self.assertEqual(repo.default_priority, 'High')
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # reset the default priority
Pierre-Yves Chibon dff667
            data = {'csrf_token': csrf_token, 'priority': ''}
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/default_priority', data=data,
Pierre-Yves Chibon dff667
                follow_redirects=True)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon dff667
            # Check the redirect
Pierre-Yves Chibon dff667
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon dff667
            self.assertIn(
Ryan Lerch 90916a
                'Default priority reset',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon dff667
            # Check the result of the action -- default_priority no change
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon dff667
            self.assertEqual(repo.default_priority, None)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon dff667
            settings = repo.settings
Pierre-Yves Chibon dff667
            settings['issue_tracker'] = False
Pierre-Yves Chibon dff667
            repo.settings = settings
Pierre-Yves Chibon dff667
            self.session.add(repo)
Pierre-Yves Chibon dff667
            self.session.commit()
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/default_priority', data=data)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
            # Check for an invalid project
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/foo/update/default_priority', data=data)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
        # Check for a non-admin user
Pierre-Yves Chibon dff667
        settings = repo.settings
Pierre-Yves Chibon dff667
        settings['issue_tracker'] = True
Pierre-Yves Chibon dff667
        repo.settings = settings
Pierre-Yves Chibon dff667
        self.session.add(repo)
Pierre-Yves Chibon dff667
        self.session.commit()
Pierre-Yves Chibon dff667
Pierre-Yves Chibon dff667
        user.username = 'ralph'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon dff667
            output = self.app.post(
Pierre-Yves Chibon dff667
                '/test/update/default_priority', data=data)
Pierre-Yves Chibon dff667
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon dff667
Pierre-Yves Chibon 606ecb
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 606ecb
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 606ecb
    def test_default_priority_reset_when_updating_priorities(self):
Pierre-Yves Chibon 606ecb
        """ Test updating the default priority of a repo when updating the
Pierre-Yves Chibon 606ecb
        priorities.
Pierre-Yves Chibon 606ecb
        """
Pierre-Yves Chibon 606ecb
        tests.create_projects(self.session)
Pierre-Yves Chibon 606ecb
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 606ecb
        # Check the default priorities
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 606ecb
        self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 606ecb
        self.assertEqual(repo.default_priority, None)
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 606ecb
        user = tests.FakeUser()
Pierre-Yves Chibon 606ecb
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 606ecb
            csrf_token = self.get_csrf()
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 606ecb
            # Set some priorities
Pierre-Yves Chibon 606ecb
            data = {
Pierre-Yves Chibon 606ecb
                'priority_weigth': [1, 2, 3],
Pierre-Yves Chibon 606ecb
                'priority_title': ['High', 'Normal', 'Low'],
Pierre-Yves Chibon 606ecb
                'csrf_token': csrf_token,
Pierre-Yves Chibon 606ecb
            }
Pierre-Yves Chibon 606ecb
            output = self.app.post(
Pierre-Yves Chibon 606ecb
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 606ecb
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 606ecb
            # Check the redirect
Pierre-Yves Chibon 606ecb
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 606ecb
            # Check the ordering
Pierre-Yves Chibon 606ecb
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('High') < output_text.find('Normal'))
Pierre-Yves Chibon 606ecb
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('Normal') < output_text.find('Low'))
Pierre-Yves Chibon 606ecb
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 606ecb
            self.assertEqual(
Pierre-Yves Chibon 606ecb
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'High', '2': 'Normal', '3': 'Low'}
Pierre-Yves Chibon 606ecb
            )
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 606ecb
            # Try setting the default priority
Pierre-Yves Chibon 606ecb
            data = {'priority': 'High', 'csrf_token': csrf_token}
Pierre-Yves Chibon 606ecb
            output = self.app.post(
Pierre-Yves Chibon 606ecb
                '/test/update/default_priority', data=data,
Pierre-Yves Chibon 606ecb
                follow_redirects=True)
Pierre-Yves Chibon 606ecb
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 606ecb
            # Check the redirect
Pierre-Yves Chibon 606ecb
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 606ecb
            self.assertIn(
Ryan Lerch 90916a
                'Default priority set '
Aurélien Bompard 626417
                'to High', output_text)
Pierre-Yves Chibon 606ecb
            # Check the result of the action -- default_priority no change
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 606ecb
            self.assertEqual(repo.default_priority, 'High')
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 606ecb
            # Remove the Hight priority
Pierre-Yves Chibon 606ecb
            data = {
Pierre-Yves Chibon 606ecb
                'priority_weigth': [1, 2],
Pierre-Yves Chibon 606ecb
                'priority_title': ['Normal', 'Low'],
Pierre-Yves Chibon 606ecb
                'csrf_token': csrf_token,
Pierre-Yves Chibon 606ecb
            }
Pierre-Yves Chibon 606ecb
            output = self.app.post(
Pierre-Yves Chibon 606ecb
                '/test/update/priorities', data=data, follow_redirects=True)
Pierre-Yves Chibon 606ecb
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 606ecb
            # Check the redirect
Pierre-Yves Chibon 606ecb
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 606ecb
            self.assertIn(
Ryan Lerch 90916a
                'Priorities updated',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 606ecb
            self.assertIn(
Ryan Lerch 90916a
                'Default priority reset '
Pierre-Yves Chibon 606ecb
                'as it is no longer one of set priorities.',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 606ecb
            # Check the ordering
Pierre-Yves Chibon 606ecb
            self.assertTrue(
Aurélien Bompard 626417
                output_text.find('Normal') < output_text.find('Low'))
Pierre-Yves Chibon 606ecb
            # Check the result of the action -- Priority recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 606ecb
            self.assertEqual(
Pierre-Yves Chibon 606ecb
                repo.priorities,
Aurélien Bompard 626417
                {'': '', '1': 'Normal', '2': 'Low'}
Pierre-Yves Chibon 606ecb
            )
Pierre-Yves Chibon 606ecb
            # Default priority is now None
Pierre-Yves Chibon 606ecb
            self.assertIsNone(repo.default_priority)
Pierre-Yves Chibon 606ecb
Pierre-Yves Chibon 521996
    @patch('pagure.lib.git.update_git', MagicMock(return_value=True))
Pierre-Yves Chibon 521996
    @patch('pagure.lib.notify.send_email', MagicMock(return_value=True))
Pierre-Yves Chibon 521996
    def test_default_priority_on_new_ticket(self):
Pierre-Yves Chibon 521996
        """ Test updating the default priority of a repo. """
Pierre-Yves Chibon 521996
        tests.create_projects(self.session)
Pierre-Yves Chibon 521996
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 521996
Pierre-Yves Chibon 521996
        # Set some priority and the default one
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 521996
        repo.priorities = {'1': 'High', '2': 'Normal'}
Pierre-Yves Chibon 521996
        repo.default_priority = 'Normal'
Pierre-Yves Chibon 521996
        self.session.add(repo)
Pierre-Yves Chibon 521996
        self.session.commit()
Pierre-Yves Chibon 521996
Pierre-Yves Chibon 521996
        # Check the default priorities
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Aurélien Bompard 626417
        self.assertEqual(repo.priorities, {'1': 'High', '2': 'Normal'})
Pierre-Yves Chibon 521996
        self.assertEqual(repo.default_priority, 'Normal')
Pierre-Yves Chibon 521996
Pierre-Yves Chibon 521996
        user = tests.FakeUser()
Pierre-Yves Chibon 521996
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 521996
Pierre-Yves Chibon 521996
            csrf_token = self.get_csrf()
Pierre-Yves Chibon 521996
Pierre-Yves Chibon 521996
            data = {
Pierre-Yves Chibon 521996
                'title': 'Test issue',
Pierre-Yves Chibon 521996
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon 521996
                'status': 'Open',
Pierre-Yves Chibon 521996
                'csrf_token': csrf_token,
Pierre-Yves Chibon 521996
            }
Pierre-Yves Chibon 521996
            output = self.app.post(
Pierre-Yves Chibon 521996
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon 521996
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 521996
            self.assertIn(
Pierre-Yves Chibon 521996
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 521996
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon 521996
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 521996
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 521996
        self.assertEqual(len(repo.issues), 1)
Pierre-Yves Chibon 521996
        self.assertEqual(repo.issues[0].priority, 2)
Pierre-Yves Chibon 521996
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)