Blame tests/test_pagure_flask_ui_roadmap.py

Pierre-Yves Chibon cf560a
# -*- coding: utf-8 -*-
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
"""
Pierre-Yves Chibon f864c8
 (c) 2016-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
 Authors:
Pierre-Yves Chibon cf560a
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
"""
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon cf560a
import pkg_resources
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
import datetime
Pierre-Yves Chibon cf560a
import json
Pierre-Yves Chibon cf560a
import unittest
Pierre-Yves Chibon cf560a
import shutil
Pierre-Yves Chibon cf560a
import sys
Pierre-Yves Chibon cf560a
import tempfile
Pierre-Yves Chibon cf560a
import os
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
import pygit2
Pierre-Yves Chibon cf560a
from mock import patch
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon cf560a
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon cf560a
Farhaan Bukhsh 72e9db
import pagure
Pierre-Yves Chibon cf560a
import pagure.lib
Pierre-Yves Chibon cf560a
import tests
Pierre-Yves Chibon cf560a
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
class PagureFlaskRoadmaptests(tests.Modeltests):
Pierre-Yves Chibon cf560a
    """ Tests for the pagure's roadmap """
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon cf560a
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon cf560a
    def test_ticket_with_no_roadmap(self, p_send_email, p_ugt):
Pierre-Yves Chibon cf560a
        """ Test creating a ticket without roadmap. """
Pierre-Yves Chibon cf560a
        p_send_email.return_value = True
Pierre-Yves Chibon cf560a
        p_ugt.return_value = True
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        user = tests.FakeUser()
Pierre-Yves Chibon cf560a
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Get the CSRF token
Pierre-Yves Chibon cf560a
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertTrue(
Pierre-Yves Chibon 593f0a
                u'
\n New issue'
Pierre-Yves Chibon cf560a
                in output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            csrf_token = output.data.split(
Pierre-Yves Chibon cf560a
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'title': 'Test issue',
Pierre-Yves Chibon cf560a
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon cf560a
                'status': 'Open',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Create the issue
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon cf560a
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon cf560a
    def test_ticket_with_roadmap(self, p_send_email, p_ugt):
Pierre-Yves Chibon cf560a
        """ Test creating a ticket with roadmap. """
Pierre-Yves Chibon cf560a
        p_send_email.return_value = True
Pierre-Yves Chibon cf560a
        p_ugt.return_value = True
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # Set some milestone
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
        repo.milestone = {'v1.0': '', 'v2.0': 'Tomorrow!'}
Pierre-Yves Chibon cf560a
        self.session.add(repo)
Pierre-Yves Chibon cf560a
        self.session.commit()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        user = tests.FakeUser()
Pierre-Yves Chibon cf560a
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Get the CSRF token
Pierre-Yves Chibon cf560a
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertTrue(
Pierre-Yves Chibon cf560a
                u'
\n New issue'
Pierre-Yves Chibon cf560a
                in output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            csrf_token = output.data.split(
Pierre-Yves Chibon cf560a
                u'name="csrf_token" type="hidden" value="')[1].split(u'">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'title': 'Test issue',
Pierre-Yves Chibon cf560a
                'issue_content': 'We really should improve on this issue',
Pierre-Yves Chibon cf560a
                'status': 'Open',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Create the issue
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon cf560a
                u'<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon cf560a
                u'
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Mark the ticket for the roadmap
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'tag': 'roadmap',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/issue/1/update', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon cf560a
                u'<title>Issue #1: Test issue - test - Pagure</title>',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon cf560a
                u'
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon f4fb46
Pierre-Yves Chibon cf560a
    def test_update_milestones(self):
Pierre-Yves Chibon cf560a
        """ Test updating milestones of a repo. """
Pierre-Yves Chibon cf560a
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # Set some milestones
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
        self.assertEqual(repo.milestones, {})
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        user = tests.FakeUser()
Pierre-Yves Chibon cf560a
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Get the CSRF token
Pierre-Yves Chibon cf560a
            output = self.app.get('/test/settings')
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            csrf_token = output.data.split(
Pierre-Yves Chibon cf560a
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': 1,
Pierre-Yves Chibon cf560a
                'milestone_dates': 'Tomorrow',
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon cf560a
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon cf560a
            # 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 cf560a
            self.assertEqual(repo.milestones, {})
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': 1,
Pierre-Yves Chibon cf560a
                'milestone_dates': 'Tomorrow',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'Milestones updated', output.data)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones recorded
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 0619e5
            self.assertEqual(repo.milestones, {u'1': {u'active': False, u'date': None}})
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': ['v1.0', 'v2.0'],
Pierre-Yves Chibon 0619e5
                'milestone_dates_1': 'Tomorrow',
Pierre-Yves Chibon 0619e5
                'milestone_dates_2': '',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'Milestones updated', output.data)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones recorded
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 0619e5
                    u'v1.0': {u'active': False, u'date': None},
Pierre-Yves Chibon 0619e5
                    u'v2.0': {u'active': False, u'date': None}
Pierre-Yves Chibon 0619e5
                }
Pierre-Yves Chibon cf560a
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Check error - less milestones than dates
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': ['v1.0', 'v2.0'],
Pierre-Yves Chibon 0619e5
                'milestone_date_1': 'Tomorrow',
Pierre-Yves Chibon 0619e5
                'milestone_date_2': 'Next week',
Pierre-Yves Chibon 0619e5
                'milestone_date_3': 'Next Year',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 0619e5
                    u'v1.0': {u'active': False, u'date': u'Tomorrow'},
Pierre-Yves Chibon 0619e5
                    u'v2.0': {u'active': False, u'date': u'Next week'}
Pierre-Yves Chibon 0619e5
                }
Pierre-Yves Chibon cf560a
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Check error - Twice the same milestone
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': ['v1.0', 'v2.0', 'v2.0'],
Pierre-Yves Chibon 0619e5
                'milestone_date_1': 'Tomorrow',
Pierre-Yves Chibon 0619e5
                'milestone_date_2': 'Next week',
Pierre-Yves Chibon 0619e5
                'milestone_date_3': 'Next Year',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'\n'
Pierre-Yves Chibon cf560a
                '                      Milestone v2.0 is present 2 times',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 0619e5
                    u'v1.0': {u'active': False, u'date': u'Tomorrow'},
Pierre-Yves Chibon 0619e5
                    u'v2.0': {u'active': False, u'date': u'Next week'}
Pierre-Yves Chibon 0619e5
                }
Pierre-Yves Chibon cf560a
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Check error - Twice the same date
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': ['v1.0', 'v2.0', 'v3.0'],
Pierre-Yves Chibon 0619e5
                'milestone_date_1': 'Tomorrow',
Pierre-Yves Chibon 0619e5
                'milestone_date_2': 'Next week',
Pierre-Yves Chibon 0619e5
                'milestone_date_3': 'Next week',
Pierre-Yves Chibon cf560a
                'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 593f0a
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 593f0a
                u'\n'
Pierre-Yves Chibon 0619e5
                '                      Milestones updated',
Pierre-Yves Chibon cf560a
                output.data)
Pierre-Yves Chibon 0619e5
            # Check the result of the action -- Milestones updated
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 0619e5
                    u'v1.0': {u'active': False, u'date': u'Tomorrow'},
Pierre-Yves Chibon 0619e5
                    u'v2.0': {u'active': False, u'date': u'Next week'},
Pierre-Yves Chibon 0619e5
                    u'v3.0': {u'active': False, u'date': u'Next week'},
Pierre-Yves Chibon 0619e5
                }
Pierre-Yves Chibon cf560a
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Check for an invalid project
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/foo/update/milestones', data=data)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Check the behavior if the project disabled the issue tracker
Pierre-Yves Chibon cf560a
            settings = repo.settings
Pierre-Yves Chibon cf560a
            settings['issue_tracker'] = False
Pierre-Yves Chibon cf560a
            repo.settings = settings
Pierre-Yves Chibon cf560a
            self.session.add(repo)
Pierre-Yves Chibon cf560a
            self.session.commit()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # Check for a non-admin user
Pierre-Yves Chibon cf560a
        settings = repo.settings
Pierre-Yves Chibon cf560a
        settings['issue_tracker'] = True
Pierre-Yves Chibon cf560a
        repo.settings = settings
Pierre-Yves Chibon cf560a
        self.session.add(repo)
Pierre-Yves Chibon cf560a
        self.session.commit()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        user.username = 'ralph'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon cf560a
                '/test/update/milestones', data=data)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
    @patch('pagure.lib.git.update_git')
Pierre-Yves Chibon cf560a
    @patch('pagure.lib.notify.send_email')
Lubomír Sedlář 164359
    def test_milestones_without_dates(self, p_send_email, p_ugt):
Lubomír Sedlář 164359
        """ Test creating two milestones with no dates. """
Lubomír Sedlář 164359
        tests.create_projects(self.session)
Patrick Uiterwijk 170974
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Lubomír Sedlář 164359
Lubomír Sedlář 164359
        user = tests.FakeUser()
Lubomír Sedlář 164359
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Lubomír Sedlář 164359
            # Get the CSRF token
Lubomír Sedlář 164359
            output = self.app.get('/test/settings')
Lubomír Sedlář 164359
            csrf_token = output.data.split(
Lubomír Sedlář 164359
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Lubomír Sedlář 164359
Lubomír Sedlář 164359
            data = {
Lubomír Sedlář 164359
                'milestones': ['v1.0', 'v2.0'],
Lubomír Sedlář 164359
                'milestone_dates': ['', ''],
Lubomír Sedlář 164359
                'csrf_token': csrf_token,
Lubomír Sedlář 164359
            }
Lubomír Sedlář 164359
            output = self.app.post(
Lubomír Sedlář 164359
                '/test/update/milestones', data=data, follow_redirects=True)
Lubomír Sedlář 164359
            self.assertEqual(output.status_code, 200)
Lubomír Sedlář 164359
            # Check the redirect
Lubomír Sedlář 164359
            self.assertIn(
Lubomír Sedlář 164359
                u'<title>Settings - test - Pagure</title>', output.data)
Lubomír Sedlář 164359
            self.assertIn(u'

Settings for test

', output.data)
Lubomír Sedlář 164359
            self.assertIn(u'Milestones updated', output.data)
Lubomír Sedlář 164359
            # Check the result of the action -- Milestones recorded
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon 0619e5
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 0619e5
                    u'v1.0': {u'active': False, u'date': None},
Pierre-Yves Chibon 0619e5
                    u'v2.0': {u'active': False, u'date': None}
Pierre-Yves Chibon 0619e5
                }
Pierre-Yves Chibon 0619e5
            )
Lubomír Sedlář 164359
Lubomír Sedlář 164359
    @patch('pagure.lib.git.update_git')
Lubomír Sedlář 164359
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon cf560a
    def test_roadmap_ui(self, p_send_email, p_ugt):
Pierre-Yves Chibon cf560a
        """ Test viewing the roadmap of a repo. """
Pierre-Yves Chibon cf560a
        p_send_email.return_value = True
Pierre-Yves Chibon cf560a
        p_ugt.return_value = True
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        self.test_update_milestones()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        user = tests.FakeUser()
Pierre-Yves Chibon cf560a
        user.username = 'pingou'
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Get the CSRF token
Pierre-Yves Chibon cf560a
            output = self.app.get('/test/new_issue')
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
            self.assertTrue(
Pierre-Yves Chibon cf560a
                u'
\n New issue'
Pierre-Yves Chibon cf560a
                in output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            csrf_token = output.data.split(
Pierre-Yves Chibon cf560a
                u'name="csrf_token" type="hidden" value="')[1].split(u'">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon c8f269
            # Create an unplanned milestone
Pierre-Yves Chibon c8f269
            data = {
Pierre-Yves Chibon c8f269
                'milestones': ['v1.0', 'v2.0', 'unplanned'],
Pierre-Yves Chibon 0619e5
                'milestone_date_1': 'Tomorrow',
Pierre-Yves Chibon 0619e5
                'milestone_date_2': '',
Pierre-Yves Chibon 0619e5
                'milestone_date_3': '',
Pierre-Yves Chibon f864c8
                'active_milestone_1': True,
Pierre-Yves Chibon f864c8
                'active_milestone_2': True,
Pierre-Yves Chibon f864c8
                'active_milestone_3': True,
Pierre-Yves Chibon c8f269
                'csrf_token': csrf_token,
Pierre-Yves Chibon c8f269
            }
Pierre-Yves Chibon c8f269
            output = self.app.post(
Pierre-Yves Chibon c8f269
                '/test/update/milestones', data=data, follow_redirects=True)
Pierre-Yves Chibon c8f269
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon c8f269
            # Check the redirect
Pierre-Yves Chibon c8f269
            self.assertIn(
Pierre-Yves Chibon c8f269
                u'<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon c8f269
            self.assertIn(u'

Settings for test

', output.data)
Pierre-Yves Chibon c8f269
            self.assertIn(u'Milestones updated', output.data)
Pierre-Yves Chibon c8f269
            # Check the result of the action -- Milestones recorded
Pierre-Yves Chibon b130e5
            self.session = pagure.lib.create_session(self.dbpath)
Farhaan Bukhsh 83f8bc
            repo = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon c8f269
            self.assertEqual(
Pierre-Yves Chibon c8f269
                repo.milestones,
Pierre-Yves Chibon c8f269
                {
Pierre-Yves Chibon f864c8
                    u'unplanned': {u'active': True, u'date': None},
Pierre-Yves Chibon f864c8
                    u'v1.0': {u'active': True, u'date': u'Tomorrow'},
Pierre-Yves Chibon f864c8
                    u'v2.0': {u'active': True, u'date': None}
Pierre-Yves Chibon c8f269
                }
Pierre-Yves Chibon c8f269
            )
Pierre-Yves Chibon c8f269
Pierre-Yves Chibon cf560a
            # Create the issues
Pierre-Yves Chibon cf560a
            for cnt in range(6):
Pierre-Yves Chibon cf560a
                cnt += 1
Pierre-Yves Chibon cf560a
                data = {
Pierre-Yves Chibon cf560a
                    'title': 'Test issue %s' % cnt,
Pierre-Yves Chibon cf560a
                    'issue_content': 'We really should improve on this '
Pierre-Yves Chibon cf560a
                    'issue %s' % cnt,
Pierre-Yves Chibon cf560a
                    'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
                }
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
                output = self.app.post(
Pierre-Yves Chibon cf560a
                    '/test/new_issue', data=data, follow_redirects=True)
Pierre-Yves Chibon cf560a
                self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
                self.assertIn(
Pierre-Yves Chibon cf560a
                    u'<title>Issue #{0}: Test issue {0} - test - '</title>
Pierre-Yves Chibon cf560a
                    'Pagure'.format(cnt),
Pierre-Yves Chibon cf560a
                    output.data)
Pierre-Yves Chibon cf560a
                self.assertIn(
Pierre-Yves Chibon cf560a
                    u'
Pierre-Yves Chibon cf560a
                    'href="/test/issue/%s/edit" title="Edit this '
Pierre-Yves Chibon cf560a
                    'issue">' % cnt,
Pierre-Yves Chibon cf560a
                    output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
                # Mark the ticket for the roadmap
Pierre-Yves Chibon c8f269
                mstone = 'v%s.0' % cnt
Pierre-Yves Chibon c8f269
                if cnt >= 3:
Pierre-Yves Chibon c8f269
                    if (cnt % 3) == 0:
Pierre-Yves Chibon c8f269
                        mstone = 'unplanned'
Pierre-Yves Chibon c8f269
                    else:
Pierre-Yves Chibon c8f269
                        mstone = 'v%s.0' % (cnt % 3)
Pierre-Yves Chibon cf560a
                data = {
Pierre-Yves Chibon c8f269
                    'milestone': mstone,
Pierre-Yves Chibon cf560a
                    'csrf_token': csrf_token,
Pierre-Yves Chibon cf560a
                }
Pierre-Yves Chibon cf560a
                output = self.app.post(
Pierre-Yves Chibon cf560a
                    '/test/issue/%s/update' % cnt, data=data,
Pierre-Yves Chibon cf560a
                    follow_redirects=True)
Pierre-Yves Chibon cf560a
                self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
                self.assertIn(
Pierre-Yves Chibon cf560a
                    u'<title>Issue #{0}: Test issue {0} - test - '</title>
Pierre-Yves Chibon cf560a
                    'Pagure'.format(cnt),
Pierre-Yves Chibon cf560a
                    output.data)
Pierre-Yves Chibon cf560a
                self.assertIn(
Pierre-Yves Chibon cf560a
                    u'
Pierre-Yves Chibon cf560a
                    'href="/test/issue/%s/edit" title="Edit this '
Pierre-Yves Chibon cf560a
                    'issue">' % cnt,
Pierre-Yves Chibon cf560a
                    output.data)
Pierre-Yves Chibon cf560a
                self.assertIn(
Pierre-Yves Chibon cf560a
                    u'\n                      '
Pierre-Yves Chibon a18547
                    u'Issue set to the milestone: %s\n' % mstone,
Pierre-Yves Chibon cf560a
                    output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # Mark ticket #1 as Fixed
Pierre-Yves Chibon c8f269
        for iid in [1, 4]:
Pierre-Yves Chibon c8f269
            ticket = pagure.lib.search_issues(
Pierre-Yves Chibon c8f269
                self.session,
Pierre-Yves Chibon c8f269
                repo,
Pierre-Yves Chibon c8f269
                issueid=iid
Pierre-Yves Chibon c8f269
            )
Pierre-Yves Chibon fad6c1
            ticket.status = 'Closed'
Pierre-Yves Chibon fad6c1
            ticket.close_status = 'Fixed'
Pierre-Yves Chibon c8f269
            self.session.add(ticket)
Pierre-Yves Chibon c8f269
            self.session.commit()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view
Pierre-Yves Chibon cf560a
        output = self.app.get('/test/roadmap')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'v2.0', output.data)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'unplanned', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon c8f269
            output.data.count(u'#'), 4)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view for all milestones
Pierre-Yves Chibon 041a00
        output = self.app.get('/test/roadmap?all_stones=True&status=All')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'v1.0', output.data)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'v2.0', output.data)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'unplanned', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon cf560a
            output.data.count(u'#'), 6)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view for a specific milestone
Pierre-Yves Chibon cf560a
        output = self.app.get('/test/roadmap?milestone=v2.0')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'v2.0', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon c8f269
            output.data.count(u'#'), 2)
Pierre-Yves Chibon cf560a
Mark Reynolds e73313
        # test the roadmap view for a specific milestone - open
Pierre-Yves Chibon cf560a
        output = self.app.get('/test/roadmap?milestone=v1.0')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Mark Reynolds e73313
        self.assertIn(u'No issues found', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon cf560a
            output.data.count(u'#'), 0)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view for a specific milestone - closed
Pierre-Yves Chibon 041a00
        output = self.app.get(
Pierre-Yves Chibon 041a00
            '/test/roadmap?milestone=v1.0&status=All&all_stones=True')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon db2e4b
        self.assertIn(u'v1.0', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon c8f269
            output.data.count(u'#'), 2)
Pierre-Yves Chibon cf560a
Mark Reynolds e73313
        # test the roadmap view for a specific tag
Mark Reynolds e73313
        output = self.app.get('/test/roadmap?milestone=v2.0&tag=unknown')
Mark Reynolds e73313
        self.assertEqual(output.status_code, 200)
Mark Reynolds e73313
        self.assertIn(u'No issues found', output.data)
Mark Reynolds e73313
        self.assertEqual(
Mark Reynolds e73313
            output.data.count(u'#'), 0)
Mark Reynolds e73313
Pierre-Yves Chibon cf560a
        # test the roadmap view for errors
Pierre-Yves Chibon cf560a
        output = self.app.get('/foo/roadmap')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
        settings = repo.settings
Pierre-Yves Chibon cf560a
        settings['issue_tracker'] = False
Pierre-Yves Chibon cf560a
        repo.settings = settings
Pierre-Yves Chibon cf560a
        self.session.add(repo)
Pierre-Yves Chibon cf560a
        self.session.commit()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        output = self.app.get('/test/roadmap', data=data)
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
if __name__ == '__main__':
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)