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
Aurélien Bompard 626417
from __future__ import unicode_literals
Aurélien Bompard 626417
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertTrue(
Ryan Lerch 7230c1
                '

New Issue

\n'
Aurélien Bompard 626417
                in output_text)
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertTrue(
Ryan Lerch 7230c1
                '

New Issue

\n'
Aurélien Bompard 626417
                in output_text)
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.split(
Aurélien Bompard 626417
                '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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Issue #1: Test issue - test - Pagure</title>',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Aurélien Bompard 626417
                output_text)
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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon 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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn('Milestones updated', output_text)
Pierre-Yves Chibon 4c5425
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones recorded
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Aurélien Bompard 626417
            self.assertEqual(repo.milestones, {'1': {'active': False, '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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn('Milestones updated', output_text)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones recorded
Aurélien Bompard 13bcde
            self.session.commit()
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
                {
Aurélien Bompard 626417
                    'v1.0': {'active': False, 'date': None},
Aurélien Bompard 626417
                    'v2.0': {'active': False, '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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Aurélien Bompard 626417
                    'v1.0': {'active': False, 'date': 'Tomorrow'},
Aurélien Bompard 626417
                    'v2.0': {'active': False, 'date': '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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch 90916a
                'Milestone v2.0 is present 2 times',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon b130e5
            repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Aurélien Bompard 626417
                    'v1.0': {'active': False, 'date': 'Tomorrow'},
Aurélien Bompard 626417
                    'v2.0': {'active': False, 'date': '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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            # Check the redirect
Pierre-Yves Chibon cf560a
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch 90916a
                'Milestones updated',
Aurélien Bompard 626417
                output_text)
Pierre-Yves Chibon 0619e5
            # Check the result of the action -- Milestones updated
Aurélien Bompard 13bcde
            self.session.commit()
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
                {
Aurélien Bompard 626417
                    'v1.0': {'active': False, 'date': 'Tomorrow'},
Aurélien Bompard 626417
                    'v2.0': {'active': False, 'date': 'Next week'},
Aurélien Bompard 626417
                    'v3.0': {'active': False, 'date': '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')
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Aurélien Bompard 626417
            csrf_token = output_text.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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Lubomír Sedlář 164359
            # Check the redirect
Lubomír Sedlář 164359
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn('Milestones updated', output_text)
Lubomír Sedlář 164359
            # Check the result of the action -- Milestones recorded
Aurélien Bompard 13bcde
            self.session.commit()
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
                {
Aurélien Bompard 626417
                    'v1.0': {'active': False, 'date': None},
Aurélien Bompard 626417
                    'v2.0': {'active': False, '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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
            self.assertTrue(
Ryan Lerch 7230c1
                '

New Issue

\n'
Aurélien Bompard 626417
                in output_text)
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.split(
Aurélien Bompard 626417
                'name="csrf_token" type="hidden" value="')[1].split('">')[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)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon c8f269
            # Check the redirect
Pierre-Yves Chibon c8f269
            self.assertIn(
Aurélien Bompard 626417
                '<title>Settings - test - Pagure</title>', output_text)
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 77bdcd
                'Project Settings\n', output_text)
Aurélien Bompard 626417
            self.assertIn('Milestones updated', output_text)
Pierre-Yves Chibon 4c5425
Pierre-Yves Chibon c8f269
            # Check the result of the action -- Milestones recorded
Aurélien Bompard 13bcde
            self.session.commit()
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
                {
Aurélien Bompard 626417
                    'unplanned': {'active': True, 'date': None},
Aurélien Bompard 626417
                    'v1.0': {'active': True, 'date': 'Tomorrow'},
Aurélien Bompard 626417
                    'v2.0': {'active': True, '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)
Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
                self.assertIn(
Aurélien Bompard 626417
                    '<title>Issue #{0}: Test issue {0} - test - '</title>
Pierre-Yves Chibon cf560a
                    'Pagure'.format(cnt),
Aurélien Bompard 626417
                    output_text)
Pierre-Yves Chibon cf560a
                self.assertIn(
Ryan Lerch e85d33
                    '
Ryan Lerch e85d33
                    'href="/test/issue/%s/edit" title="Edit this issue">' % cnt,
Aurélien Bompard 626417
                    output_text)
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)
Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cf560a
                self.assertIn(
Aurélien Bompard 626417
                    '<title>Issue #{0}: Test issue {0} - test - '</title>
Pierre-Yves Chibon cf560a
                    'Pagure'.format(cnt),
Aurélien Bompard 626417
                    output_text)
Pierre-Yves Chibon cf560a
                self.assertIn(
Ryan Lerch e85d33
                    '
Ryan Lerch e85d33
                    'href="/test/issue/%s/edit" title="Edit this issue">' % cnt,
Aurélien Bompard 626417
                    output_text)
Pierre-Yves Chibon cf560a
                self.assertIn(
Ryan Lerch 90916a
                    'Issue set to the milestone: %s' % mstone,
Aurélien Bompard 626417
                    output_text)
Pierre-Yves Chibon 4c5425
                self.assertIn(
Ryan Lerch e85d33
                    '
', output_text)
Pierre-Yves Chibon 4c5425
                self.assertIn(
Pierre-Yves Chibon 4c5425
                    '' % mstone, output_text)
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)
Aurélien Bompard 626417
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            '\n'
Ryan Lerch 1cdcf9
            '                            
Ryan Lerch 1cdcf9
            '-weight-bold">v1.0',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            '\n'
Ryan Lerch 1cdcf9
            '                            
Ryan Lerch 1cdcf9
            '-weight-bold">unplanned',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            'title="100% Completed | 2 Closed Issues | 0 Open Issues"\n',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view for a specific milestone
Ryan Lerch 1cdcf9
        output = self.app.get('/test/roadmap/v2.0/')
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            ' 2 Open\n',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            ' 0 Closed\n',
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon 4a2cf2
        self.assertIn(
Pierre-Yves Chibon 4a2cf2
            '', output_text)
Pierre-Yves Chibon 4a2cf2
        self.assertEquals(
Pierre-Yves Chibon 4a2cf2
            output_text.count(''),
Pierre-Yves Chibon 4a2cf2
            1)
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)