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 cf560a
 (c) 2016 - 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
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
    def setUp(self):
Pierre-Yves Chibon cf560a
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon cf560a
        super(PagureFlaskRoadmaptests, self).setUp()
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon cf560a
        pagure.SESSION = self.session
Pierre-Yves Chibon cf560a
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon cf560a
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon cf560a
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon cf560a
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon cf560a
        pagure.ui.issues.SESSION = self.session
Pierre-Yves Chibon cf560a
Jeremy Cline 20109f
        pagure.APP.config['GIT_FOLDER'] = self.path
Pierre-Yves Chibon cf560a
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'requests')
Pierre-Yves Chibon cf560a
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'tickets')
Pierre-Yves Chibon cf560a
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'docs')
Pierre-Yves Chibon cf560a
        self.app = pagure.APP.test_client()
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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        user = tests.FakeUser()
Pierre-Yves Chibon cf560a
        user.username = 'pingou'
Pierre-Yves Chibon cf560a
        with tests.user_set(pagure.APP, 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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # Set some milestone
Pierre-Yves Chibon cf560a
        repo = pagure.lib.get_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 cf560a
        with tests.user_set(pagure.APP, 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
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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # Set some milestones
Pierre-Yves Chibon cf560a
        repo = pagure.lib.get_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 cf560a
        with tests.user_set(pagure.APP, 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 cf560a
            repo = pagure.lib.get_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 cf560a
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(repo.milestones, {u'1': u'Tomorrow'})
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon cf560a
                'milestones': ['v1.0', 'v2.0'],
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 cf560a
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon cf560a
                repo.milestones, {u'v1.0': u'Tomorrow', u'v2.0': u''}
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 cf560a
                'milestone_dates': ['Tomorrow', 'Next week', '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
                '                      Milestones and dates are not of the '
Pierre-Yves Chibon cf560a
                'same length', output.data)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Pierre-Yves Chibon cf560a
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon cf560a
                repo.milestones, {u'v1.0': u'Tomorrow', u'v2.0': u''}
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 cf560a
                'milestone_dates': ['Tomorrow', 'Next week', '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 cf560a
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon cf560a
                repo.milestones, {u'v1.0': u'Tomorrow', u'v2.0': u''}
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 cf560a
                'milestone_dates': ['Tomorrow', 'Next week', '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 cf560a
                '                      Date Next week 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 cf560a
            repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon cf560a
                repo.milestones, {u'v1.0': u'Tomorrow', u'v2.0': u''}
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 cf560a
        with tests.user_set(pagure.APP, 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)
Jeremy Cline 20109f
        tests.create_projects_git(os.path.join(self.path), bare=True)
Lubomír Sedlář 164359
Lubomír Sedlář 164359
        user = tests.FakeUser()
Lubomír Sedlář 164359
        user.username = 'pingou'
Lubomír Sedlář 164359
        with tests.user_set(pagure.APP, 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
Lubomír Sedlář 164359
            repo = pagure.lib.get_project(self.session, 'test')
Lubomír Sedlář 164359
            self.assertEqual(repo.milestones, {u'v1.0': u'', u'v2.0': u''})
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 cf560a
        with tests.user_set(pagure.APP, 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 c8f269
                'milestone_dates': ['Tomorrow', '', ''],
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 c8f269
            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 c8f269
                    u'v1.0': u'Tomorrow', u'v2.0': u'', u'unplanned': u''
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 c8f269
                    u'Successfully edited issue #%s' % cnt,
Pierre-Yves Chibon cf560a
                    output.data)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        repo = pagure.lib.get_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 cf560a
        self.assertIn(u'2 Milestones', output.data)
Pierre-Yves Chibon cf560a
        self.assertIn(u'Milestone: v2.0', output.data)
Pierre-Yves Chibon b4817e
        self.assertIn(u'Milestone: 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 cf560a
        output = self.app.get('/test/roadmap?status=All')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
        self.assertIn(u'3 Milestones', output.data)
Pierre-Yves Chibon cf560a
        self.assertIn(u'Milestone: v1.0', output.data)
Pierre-Yves Chibon cf560a
        self.assertIn(u'Milestone: v2.0', output.data)
Pierre-Yves Chibon b4817e
        self.assertIn(u'Milestone: 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 cf560a
        self.assertIn(u'1 Milestones', output.data)
Pierre-Yves Chibon cf560a
        self.assertIn(u'Milestone: v2.0', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon c8f269
            output.data.count(u'#'), 2)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view for a specific milestone - closed
Pierre-Yves Chibon cf560a
        output = self.app.get('/test/roadmap?milestone=v1.0')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
        self.assertIn(u'1 Milestones', output.data)
Pierre-Yves Chibon cf560a
        self.assertIn(u'Milestone: v1.0', 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 cf560a
        output = self.app.get('/test/roadmap?milestone=v1.0&status=All')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cf560a
        self.assertIn(u'1 Milestones', output.data)
Pierre-Yves Chibon cf560a
        self.assertIn(u'Milestone: v1.0', output.data)
Pierre-Yves Chibon cf560a
        self.assertEqual(
Pierre-Yves Chibon c8f269
            output.data.count(u'#'), 2)
Pierre-Yves Chibon cf560a
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 cf560a
        repo = pagure.lib.get_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 cf560a
    SUITE = unittest.TestLoader().loadTestsFromTestCase(
Pierre-Yves Chibon cf560a
        PagureFlaskRoadmaptests)
Pierre-Yves Chibon cf560a
    unittest.TextTestRunner(verbosity=2).run(SUITE)