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 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard 626417
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 73d120
sys.path.insert(
Pierre-Yves Chibon 73d120
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon 930073
import pagure.lib.query
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 73d120
    @patch("pagure.lib.git.update_git")
Pierre-Yves Chibon 73d120
    @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)
Pierre-Yves Chibon 73d120
        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 73d120
        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 73d120
            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'
Pierre-Yves Chibon 73d120
                in output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon 73d120
                "title": "Test issue",
Pierre-Yves Chibon 73d120
                "issue_content": "We really should improve on this issue",
Pierre-Yves Chibon 73d120
                "status": "Open",
Pierre-Yves Chibon 73d120
                "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 73d120
                "/test/new_issue", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Issue #1: Test issue - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.git.update_git")
Pierre-Yves Chibon 73d120
    @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)
Pierre-Yves Chibon 73d120
        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 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon 73d120
        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 73d120
        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 73d120
            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'
Pierre-Yves Chibon 73d120
                in output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon 73d120
                "title": "Test issue",
Pierre-Yves Chibon 73d120
                "issue_content": "We really should improve on this issue",
Pierre-Yves Chibon 73d120
                "status": "Open",
Pierre-Yves Chibon 73d120
                "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 73d120
                "/test/new_issue", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Issue #1: Test issue - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Mark the ticket for the roadmap
Pierre-Yves Chibon 73d120
            data = {"tag": "roadmap", "csrf_token": csrf_token}
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/issue/1/update", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Issue #1: Test issue - test - Pagure</title>",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertIn(
Ryan Lerch e85d33
                '
Pierre-Yves Chibon cf560a
                'href="/test/issue/1/edit" title="Edit this issue">',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
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)
Pierre-Yves Chibon 73d120
        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 73d120
        repo = pagure.lib.query.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 73d120
        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 73d120
            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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon 73d120
                "milestones": 1,
Pierre-Yves Chibon 73d120
                "milestone_1_name": "1",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "Tomorrow",
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            # Check the result of the action -- None, no CSRF
Pierre-Yves Chibon 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertEqual(repo.milestones, {})
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon 73d120
                "milestones": 1,
Pierre-Yves Chibon 73d120
                "milestone_1_name": "1",
Pierre-Yves Chibon 73d120
                "milestone_date": "",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            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 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertEqual(
Pierre-Yves Chibon 73d120
                repo.milestones, {"1": {"active": False, "date": None}}
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            data = {
Pierre-Yves Chibon 73d120
                "milestones": [1, 2],
Pierre-Yves Chibon 73d120
                "milestone_1_name": "v1.0",
Pierre-Yves Chibon 73d120
                "milestone_2_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "Tomorrow",
Pierre-Yves Chibon 73d120
                "milestone_2_date": "",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            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 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 73d120
                    "v1.0": {"active": False, "date": "Tomorrow"},
Pierre-Yves Chibon 73d120
                    "v2.0": {"active": False, "date": None},
Pierre-Yves Chibon 73d120
                },
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 73d120
                "milestones": [1, 2],
Pierre-Yves Chibon 73d120
                "milestone_1_name": "v1.0",
Pierre-Yves Chibon 73d120
                "milestone_2_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "Tomorrow",
Pierre-Yves Chibon 73d120
                "milestone_2_date": "Next week",
Pierre-Yves Chibon 73d120
                "milestone_3_date": "Next Year",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 73d120
                    "v1.0": {"active": False, "date": "Tomorrow"},
Pierre-Yves Chibon 73d120
                    "v2.0": {"active": False, "date": "Next week"},
Pierre-Yves Chibon 73d120
                },
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 73d120
                "milestones": [1, 2, 3],
Pierre-Yves Chibon 73d120
                "milestone_1_name": "v1.0",
Pierre-Yves Chibon 73d120
                "milestone_2_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_3_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "Tomorrow",
Pierre-Yves Chibon 73d120
                "milestone_2_date": "Next week",
Pierre-Yves Chibon 73d120
                "milestone_3_date": "Next Year",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertIn(
Pierre-Yves Chibon 73d120
                "Milestone v2.0 is present multiple times",
Pierre-Yves Chibon 73d120
                "Milestone v2.0 is present multiple times",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            # Check the result of the action -- Milestones un-changed
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 73d120
                    "v1.0": {"active": False, "date": "Tomorrow"},
Pierre-Yves Chibon 73d120
                    "v2.0": {"active": False, "date": "Next week"},
Pierre-Yves Chibon 73d120
                },
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 73d120
                "milestones": [1, 2, 3],
Pierre-Yves Chibon 73d120
                "milestone_1_name": "v1.0",
Pierre-Yves Chibon 73d120
                "milestone_2_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_3_name": "v3.0",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "Tomorrow",
Pierre-Yves Chibon 73d120
                "milestone_2_date": "Next week",
Pierre-Yves Chibon 73d120
                "milestone_3_date": "Next week",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon cf560a
            }
Pierre-Yves Chibon cf560a
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("Milestones updated", output_text)
Pierre-Yves Chibon 0619e5
            # Check the result of the action -- Milestones updated
Aurélien Bompard 13bcde
            self.session.commit()
Pierre-Yves Chibon 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 73d120
                    "v1.0": {"active": False, "date": "Tomorrow"},
Pierre-Yves Chibon 73d120
                    "v2.0": {"active": False, "date": "Next week"},
Pierre-Yves Chibon 73d120
                    "v3.0": {"active": False, "date": "Next week"},
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon cf560a
            )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
            # Check for an invalid project
Pierre-Yves Chibon 73d120
            output = self.app.post("/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 73d120
            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 73d120
            output = self.app.post("/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 73d120
        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 73d120
        user.username = "ralph"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.post("/test/update/milestones", data=data)
Pierre-Yves Chibon cf560a
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.git.update_git")
Pierre-Yves Chibon 73d120
    @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)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
Lubomír Sedlář 164359
Lubomír Sedlář 164359
        user = tests.FakeUser()
Pierre-Yves Chibon 73d120
        user.username = "pingou"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Lubomír Sedlář 164359
            # Get the CSRF token
Pierre-Yves Chibon 73d120
            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(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Lubomír Sedlář 164359
Lubomír Sedlář 164359
            data = {
Pierre-Yves Chibon 73d120
                "milestones": [1, 2],
Pierre-Yves Chibon 73d120
                "milestone_1_name": "v1.0",
Pierre-Yves Chibon 73d120
                "milestone_2_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "",
Pierre-Yves Chibon 73d120
                "milestone_2_date": "",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Lubomír Sedlář 164359
            }
Lubomír Sedlář 164359
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            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 73d120
            repo = pagure.lib.query.get_authorized_project(
Pierre-Yves Chibon 73d120
                self.session, "test"
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 0619e5
            self.assertEqual(
Pierre-Yves Chibon 0619e5
                repo.milestones,
Pierre-Yves Chibon 0619e5
                {
Pierre-Yves Chibon 73d120
                    "v1.0": {"active": False, "date": None},
Pierre-Yves Chibon 73d120
                    "v2.0": {"active": False, "date": None},
Pierre-Yves Chibon 73d120
                },
Pierre-Yves Chibon 0619e5
            )
Lubomír Sedlář 164359
Pierre-Yves Chibon 73d120
    @patch("pagure.lib.git.update_git")
Pierre-Yves Chibon 73d120
    @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 73d120
        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 73d120
            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'
Pierre-Yves Chibon 73d120
                in output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cf560a
Aurélien Bompard 626417
            csrf_token = output_text.split(
Pierre-Yves Chibon 73d120
                'name="csrf_token" type="hidden" value="'
Pierre-Yves Chibon 73d120
            )[1].split('">')[0]
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon c8f269
            # Create an unplanned milestone
Pierre-Yves Chibon c8f269
            data = {
Pierre-Yves Chibon 73d120
                "milestones": [1, 2, 3],
Pierre-Yves Chibon 73d120
                "milestone_1_name": "v1.0",
Pierre-Yves Chibon 73d120
                "milestone_2_name": "v2.0",
Pierre-Yves Chibon 73d120
                "milestone_3_name": "unplanned",
Pierre-Yves Chibon 73d120
                "milestone_1_date": "Tomorrow",
Pierre-Yves Chibon 73d120
                "milestone_2_date": "",
Pierre-Yves Chibon 73d120
                "milestone_3_date": "",
Pierre-Yves Chibon 73d120
                "milestone_1_active": True,
Pierre-Yves Chibon 73d120
                "milestone_2_active": True,
Pierre-Yves Chibon 73d120
                "milestone_3_active": True,
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon c8f269
            }
Pierre-Yves Chibon c8f269
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/test/update/milestones", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
            )
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(
Pierre-Yves Chibon 73d120
                "<title>Settings - test - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 77bdcd
            self.assertIn(
Pierre-Yves Chibon 77bdcd
                '
'
Pierre-Yves Chibon 73d120
                "Project Settings\n",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            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()
Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
Pierre-Yves Chibon c8f269
            self.assertEqual(
Pierre-Yves Chibon c8f269
                repo.milestones,
Pierre-Yves Chibon c8f269
                {
Pierre-Yves Chibon 73d120
                    "unplanned": {"active": True, "date": None},
Pierre-Yves Chibon 73d120
                    "v1.0": {"active": True, "date": "Tomorrow"},
Pierre-Yves Chibon 73d120
                    "v2.0": {"active": True, "date": None},
Pierre-Yves Chibon 73d120
                },
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 73d120
                    "title": "Test issue %s" % cnt,
Pierre-Yves Chibon 73d120
                    "issue_content": "We really should improve on this "
Pierre-Yves Chibon 73d120
                    "issue %s" % cnt,
Pierre-Yves Chibon 73d120
                    "csrf_token": csrf_token,
Pierre-Yves Chibon cf560a
                }
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
                output = self.app.post(
Pierre-Yves Chibon 73d120
                    "/test/new_issue", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
                )
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(
Pierre-Yves Chibon 73d120
                    "<title>Issue #{0}: Test issue {0} - test - "</title>
Pierre-Yves Chibon 73d120
                    "Pagure".format(cnt),
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon cf560a
                self.assertIn(
Ryan Lerch e85d33
                    '
Pierre-Yves Chibon 73d120
                    'href="/test/issue/%s/edit" title="Edit this issue">'
Pierre-Yves Chibon 73d120
                    % cnt,
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
                # Mark the ticket for the roadmap
Pierre-Yves Chibon 73d120
                mstone = "v%s.0" % cnt
Pierre-Yves Chibon c8f269
                if cnt >= 3:
Pierre-Yves Chibon c8f269
                    if (cnt % 3) == 0:
Pierre-Yves Chibon 73d120
                        mstone = "unplanned"
Pierre-Yves Chibon c8f269
                    else:
Pierre-Yves Chibon 73d120
                        mstone = "v%s.0" % (cnt % 3)
Pierre-Yves Chibon 73d120
                data = {"milestone": mstone, "csrf_token": csrf_token}
Pierre-Yves Chibon cf560a
                output = self.app.post(
Pierre-Yves Chibon 73d120
                    "/test/issue/%s/update" % cnt,
Pierre-Yves Chibon 73d120
                    data=data,
Pierre-Yves Chibon 73d120
                    follow_redirects=True,
Pierre-Yves Chibon 73d120
                )
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(
Pierre-Yves Chibon 73d120
                    "<title>Issue #{0}: Test issue {0} - test - "</title>
Pierre-Yves Chibon 73d120
                    "Pagure".format(cnt),
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon cf560a
                self.assertIn(
Ryan Lerch e85d33
                    '
Pierre-Yves Chibon 73d120
                    'href="/test/issue/%s/edit" title="Edit this issue">'
Pierre-Yves Chibon 73d120
                    % cnt,
Pierre-Yves Chibon 73d120
                    output_text,
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon cf560a
                self.assertIn(
Pierre-Yves Chibon 73d120
                    "Issue set to the milestone: %s" % mstone, output_text
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 4c5425
                self.assertIn(
Pierre-Yves Chibon 73d120
                    '
', output_text
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 4c5425
                self.assertIn(
Pierre-Yves Chibon 73d120
                    '' % mstone, output_text
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.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 930073
            ticket = pagure.lib.query.search_issues(
Pierre-Yves Chibon 73d120
                self.session, repo, issueid=iid
Pierre-Yves Chibon c8f269
            )
Pierre-Yves Chibon 73d120
            ticket.status = "Closed"
Pierre-Yves Chibon 73d120
            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 73d120
        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 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            '\n'
Ryan Lerch 1cdcf9
            '                            
Ryan Lerch 1cdcf9
            '-weight-bold">unplanned',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            'title="100% Completed | 2 Closed Issues | 0 Open Issues"\n',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            'title="0% Completed | 0 Closed Issues | 2 Open Issues"\n',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon cf560a
        # test the roadmap view for a specific milestone
Pierre-Yves Chibon 73d120
        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 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 77bdcd
        self.assertIn(
Ryan Lerch 1cdcf9
            ' 0 Closed\n',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn('', output_text)
Pierre-Yves Chibon 4a2cf2
        self.assertEquals(
Pierre-Yves Chibon 73d120
            output_text.count(''), 1
Pierre-Yves Chibon 73d120
        )
Mark Reynolds e73313
Pierre-Yves Chibon cf560a
        # test the roadmap view for errors
Pierre-Yves Chibon 73d120
        output = self.app.get("/foo/roadmap")
Pierre-Yves Chibon cf560a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon cf560a
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon cf560a
        settings = repo.settings
Pierre-Yves Chibon 73d120
        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 73d120
        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 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 393f31
    unittest.main(verbosity=2)