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 af88e9
 (c) 2016 - 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
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 af88e9
from mock import patch
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
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
    def setUp(self):
Pierre-Yves Chibon af88e9
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon af88e9
        super(PagureFlaskPrioritiestests, self).setUp()
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon af88e9
        pagure.SESSION = self.session
Pierre-Yves Chibon af88e9
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon af88e9
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon af88e9
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon af88e9
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon af88e9
        pagure.ui.issues.SESSION = self.session
Pierre-Yves Chibon af88e9
Jeremy Cline 20109f
        pagure.APP.config['GIT_FOLDER'] = self.path
Pierre-Yves Chibon af88e9
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'requests')
Pierre-Yves Chibon af88e9
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'tickets')
Pierre-Yves Chibon af88e9
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'docs')
Pierre-Yves Chibon af88e9
        self.app = pagure.APP.test_client()
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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        user = tests.FakeUser()
Pierre-Yves Chibon af88e9
        user.username = 'pingou'
Pierre-Yves Chibon af88e9
        with tests.user_set(pagure.APP, 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)
Pierre-Yves Chibon af88e9
            self.assertTrue(
Pierre-Yves Chibon af88e9
                '
\n New issue'
Pierre-Yves Chibon af88e9
                in output.data)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            csrf_token = output.data.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)
Pierre-Yves Chibon af88e9
            self.assertIn(
Pierre-Yves Chibon af88e9
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon af88e9
                output.data)
Pierre-Yves Chibon af88e9
            self.assertIn(
Pierre-Yves Chibon af88e9
                '
Pierre-Yves Chibon af88e9
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon af88e9
                output.data)
Pierre-Yves Chibon af88e9
            self.assertNotIn('
', output.data)
Pierre-Yves Chibon af88e9
            self.assertNotIn('<option value="1">High</option>', output.data)
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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
        # Set some priorities
Pierre-Yves Chibon af88e9
        repo = pagure.lib.get_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 af88e9
        with tests.user_set(pagure.APP, 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)
Pierre-Yves Chibon af88e9
            self.assertTrue(
Pierre-Yves Chibon af88e9
                '
\n New issue'
Pierre-Yves Chibon af88e9
                in output.data)
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
            csrf_token = output.data.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)
Pierre-Yves Chibon af88e9
            self.assertIn(
Pierre-Yves Chibon af88e9
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon af88e9
                output.data)
Pierre-Yves Chibon af88e9
            self.assertIn(
Pierre-Yves Chibon af88e9
                '
Pierre-Yves Chibon af88e9
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon af88e9
                output.data)
Pierre-Yves Chibon af88e9
            self.assertIn('
', output.data)
Pierre-Yves Chibon af88e9
            self.assertIn('<option value="1">High</option>', output.data)
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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
        # Set some priorities
Pierre-Yves Chibon 3d1519
        repo = pagure.lib.get_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 3d1519
        with tests.user_set(pagure.APP, 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)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
Pierre-Yves Chibon 3d1519
            csrf_token = output.data.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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- None, no CSRF
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priority recorded
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon c63cca
            self.assertEqual(repo.priorities, {u'': u'', u'1': u'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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priority recorded
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Pierre-Yves Chibon c63cca
                {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '\n'
Pierre-Yves Chibon 3d1519
                '                      Priorities weights and titles are '
Pierre-Yves Chibon 3d1519
                'not of the same length', output.data)            # Check the result of the action -- Priorities un-changed
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Pierre-Yves Chibon c63cca
                {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '\n'
Pierre-Yves Chibon 3d1519
                '                      Priorities weights must be numbers',
Pierre-Yves Chibon 3d1519
                output.data)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priorities un-changed
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Pierre-Yves Chibon c63cca
                {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '\n'
Pierre-Yves Chibon 3d1519
                '                      Priority weight 2 is present 2 times',
Pierre-Yves Chibon 3d1519
                output.data)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priorities un-changed
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Pierre-Yves Chibon c63cca
                {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'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)
Pierre-Yves Chibon 3d1519
            # Check the redirect
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 3d1519
            self.assertIn(
Pierre-Yves Chibon 3d1519
                '\n'
Pierre-Yves Chibon 3d1519
                '                      Priority Normal is present 2 times',
Pierre-Yves Chibon 3d1519
                output.data)
Pierre-Yves Chibon 3d1519
            # Check the result of the action -- Priorities un-changed
Pierre-Yves Chibon 3d1519
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 3d1519
            self.assertEqual(
Pierre-Yves Chibon 3d1519
                repo.priorities,
Pierre-Yves Chibon c63cca
                {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'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 068320
        with tests.user_set(pagure.APP, 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)
Pierre-Yves Chibon 7b3aee
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
        # Start from scrach on priorities
Pierre-Yves Chibon 7b3aee
        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 7b3aee
        with tests.user_set(pagure.APP, 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)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Pierre-Yves Chibon 7b3aee
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            csrf_token = output.data.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)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Pierre-Yves Chibon 7b3aee
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Check the result of the action -- Priority recorded
Pierre-Yves Chibon 7b3aee
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(
Pierre-Yves Chibon 7b3aee
                repo.priorities,
Pierre-Yves Chibon 7b3aee
                {u'': u'', u'1': u'High', u'2': u'Normal', u'3': u'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)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Pierre-Yves Chibon 7b3aee
                '<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon 7b3aee
                output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Pierre-Yves Chibon 7b3aee
                '
Pierre-Yves Chibon 7b3aee
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 7b3aee
                output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn('
', output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn('<option value="1">High</option>', output.data)
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)
Pierre-Yves Chibon 7b3aee
            self.assertIn('
', output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn('<option value="1">High</option>', output.data)
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)
Pierre-Yves Chibon 7b3aee
            self.assertIn(
Pierre-Yves Chibon 7b3aee
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 7b3aee
            self.assertIn('

Settings for test

', output.data)
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)
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)
Pierre-Yves Chibon 7b3aee
            self.assertNotIn('
', output.data)
Pierre-Yves Chibon 7b3aee
            self.assertNotIn('<option value="1">High</option>', output.data)
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon 7b3aee
            # Check the result of the action -- Priority recorded
Pierre-Yves Chibon 7b3aee
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 7b3aee
            self.assertEqual(repo.priorities, {})
Pierre-Yves Chibon 7b3aee
Pierre-Yves Chibon af88e9
Pierre-Yves Chibon af88e9
if __name__ == '__main__':
Pierre-Yves Chibon af88e9
    SUITE = unittest.TestLoader().loadTestsFromTestCase(
Pierre-Yves Chibon af88e9
        PagureFlaskPrioritiestests)
Pierre-Yves Chibon af88e9
    unittest.TextTestRunner(verbosity=2).run(SUITE)