Blame tests/test_pagure_flask_ui_app.py

Pierre-Yves Chibon cfad13
# -*- coding: utf-8 -*-
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
"""
Pierre-Yves Chibon 75b0c3
 (c) 2015-2018 - Copyright Red Hat Inc
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
 Authors:
Pierre-Yves Chibon cfad13
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
"""
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard 626417
Pierre-Yves Chibon 170fc9
import datetime
Pierre-Yves Chibon cfad13
import unittest
Pierre-Yves Chibon cfad13
import shutil
Pierre-Yves Chibon cfad13
import sys
Pierre-Yves Chibon 8b2c5c
import tempfile
Pierre-Yves Chibon cfad13
import os
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon 5833b3
import six
Pierre-Yves Chibon cfad13
import json
Pierre-Yves Chibon f66c8c
import pygit2
Pierre-Yves Chibon ce6f30
from mock import patch, MagicMock
Pierre-Yves Chibon cfad13
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 cfad13
Pierre-Yves Chibon 930073
import pagure.lib.query
Pierre-Yves Chibon cfad13
import tests
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon cfad13
Pierre-Yves Chibon fe5017
class PagureFlaskApptests(tests.Modeltests):
Pierre-Yves Chibon fe5017
    """ Tests for flask app controller of pagure """
Pierre-Yves Chibon cfad13
Vivek Anand 272efb
    def test_watch_list(self):
Pierre-Yves Chibon 73d120
        """ Test for watch list of a user """
Vivek Anand 272efb
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/", follow_redirects=True)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Vivek Anand 272efb
            self.assertIn(
Pierre-Yves Chibon 837e8c
                '
You have no Projects
',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Vivek Anand 272efb
Vivek Anand 272efb
            tests.create_projects(self.session)
Vivek Anand 272efb
Pierre-Yves Chibon 73d120
            output = self.app.get("/", follow_redirects=True)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Vivek Anand 272efb
            self.assertIn(
Ryan Lerch 336cd6
                '

My Projects

',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 0ebfa3
Pierre-Yves Chibon 78d005
    def test_view_users(self):
Pierre-Yves Chibon 7827f1
        """ Test the view_users endpoint. """
Pierre-Yves Chibon 78d005
Pierre-Yves Chibon 73d120
        output = self.app.get("/users/?page=abc")
Pierre-Yves Chibon 78d005
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 016b9a
        self.assertIn(
Ryan Lerch 6d2e06
            '

\n Users '

Pierre-Yves Chibon 73d120
            '2',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 016b9a
        self.assertIn(
Ryan Lerch 6d2e06
            '\n                  '
Ryan Lerch 6d2e06
            '
pingou',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 016b9a
        self.assertIn(
Ryan Lerch 6d2e06
            '\n                  '
Ryan Lerch 6d2e06
            '
foo',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 78d005
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"ITEM_PER_PAGE": 2})
Pierre-Yves Chibon ef2ad5
    def test_view_user_repo_cnt(self):
Pierre-Yves Chibon ef2ad5
        """ Test the repo counts on the view_user endpoint. """
Pierre-Yves Chibon ef2ad5
        tests.create_projects(self.session)
Pierre-Yves Chibon ef2ad5
        self.gitrepos = tests.create_projects_git(
Pierre-Yves Chibon 73d120
            pagure.config.config["GIT_FOLDER"]
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon ef2ad5
Pierre-Yves Chibon 73d120
        output = self.app.get("/user/pingou")
Pierre-Yves Chibon ef2ad5
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon ef2ad5
        self.assertIn(
Pierre-Yves Chibon 73d120
            """
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                Projects 
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                  3
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 73d120
              """,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon ef2ad5
        self.assertIn(
Pierre-Yves Chibon 73d120
            """
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                Forks 
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                  0
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 73d120
              """,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon ef2ad5
Pierre-Yves Chibon 045b56
    def test_view_user(self):
Pierre-Yves Chibon 7827f1
        """ Test the view_user endpoint. """
Pierre-Yves Chibon 045b56
Pierre-Yves Chibon 73d120
        output = self.app.get("/user/pingou?repopage=abc&forkpage=def")
Pierre-Yves Chibon 045b56
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 016b9a
        self.assertIn(
Pierre-Yves Chibon 73d120
            """
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                Projects 
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                  0
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 73d120
              """,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon a57a5c
        self.assertIn(
Pierre-Yves Chibon 73d120
            """
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                Forks 
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                  0
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 73d120
              """,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 045b56
Pierre-Yves Chibon 8bcb94
        tests.create_projects(self.session)
Pierre-Yves Chibon 293dcb
        self.gitrepos = tests.create_projects_git(
Pierre-Yves Chibon 73d120
            pagure.config.config["GIT_FOLDER"]
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 8bcb94
Pierre-Yves Chibon 73d120
        output = self.app.get("/user/pingou?repopage=abc&forkpage=def")
Pierre-Yves Chibon 8bcb94
        self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 016b9a
        self.assertIn(
Pierre-Yves Chibon 73d120
            """
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                Projects 
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                  3
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 73d120
              """,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 016b9a
        self.assertIn(
Pierre-Yves Chibon 73d120
            """
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                Forks 
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
              
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 75b0c3
                  0
Pierre-Yves Chibon 75b0c3
                
Pierre-Yves Chibon 73d120
              """,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon ef2ad5
        self.assertNotIn(
Pierre-Yves Chibon f0babf
            'page 1 of 2',
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 045b56
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"ENABLE_UI_NEW_PROJECTS": False})
Pierre-Yves Chibon cf3d3a
    def test_new_project_when_turned_off_in_the_ui(self):
Pierre-Yves Chibon cf3d3a
        """ Test the new_project endpoint when new project creation is
Pierre-Yves Chibon cf3d3a
        not allowed in the UI of this pagure instance. """
Pierre-Yves Chibon cf3d3a
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon cf3d3a
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon cf3d3a
Pierre-Yves Chibon 73d120
            data = {"description": "Project #1", "name": "project-1"}
Pierre-Yves Chibon cf3d3a
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon cf3d3a
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"ENABLE_UI_NEW_PROJECTS": False})
Pierre-Yves Chibon b59301
    def test_new_project_button_when_turned_off_in_the_ui_no_project(self):
Pierre-Yves Chibon b59301
        """ Test the index endpoint when new project creation is
Pierre-Yves Chibon b59301
        not allowed in the UI of this pagure instance. """
Pierre-Yves Chibon b59301
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/", follow_redirects=True)
Pierre-Yves Chibon b59301
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b59301
            self.assertIn(
Ryan Lerch 336cd6
                '

My Projects

',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon b59301
            # master template
Pierre-Yves Chibon b59301
            self.assertNotIn(
Aurélien Bompard 626417
                '
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon b59301
            # index_auth template
Pierre-Yves Chibon b59301
            self.assertNotIn(
Pierre-Yves Chibon 73d120
                'title="Create New Project" aria-hidden="true">', output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon b59301
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"ENABLE_UI_NEW_PROJECTS": False})
Pierre-Yves Chibon b59301
    def test_new_project_button_when_turned_off_in_the_ui_w_project(self):
Pierre-Yves Chibon b59301
        """ Test the index endpoint when new project creation is
Pierre-Yves Chibon b59301
        not allowed in the UI of this pagure instance. """
Pierre-Yves Chibon b59301
        tests.create_projects(self.session)
Pierre-Yves Chibon b59301
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/", follow_redirects=True)
Pierre-Yves Chibon b59301
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon b59301
            self.assertIn(
Ryan Lerch 336cd6
                '

My Projects

',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon b59301
            # master template
Pierre-Yves Chibon b59301
            self.assertNotIn(
Aurélien Bompard 626417
                '
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon b59301
            # index_auth template
Pierre-Yves Chibon b59301
            self.assertNotIn(
Pierre-Yves Chibon 73d120
                'title="Create New Project" aria-hidden="true">', output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon b59301
Pierre-Yves Chibon 5e14ea
    def test_new_project_with_dot(self):
Pierre-Yves Chibon 5e14ea
        """ Test the new_project endpoint when new project contains a dot.
Pierre-Yves Chibon 5e14ea
        """
Pierre-Yves Chibon 5e14ea
        # Before
Pierre-Yves Chibon 5e14ea
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 5e14ea
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 5e14ea
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon 5e14ea
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5e14ea
            csrf_token = self.get_csrf()
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 5e14ea
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1.",
Pierre-Yves Chibon 73d120
                "name": "project.1",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 5e14ea
            }
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 5e14ea
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5e14ea
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 5e14ea
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Overview - project.1 - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 5e14ea
            self.assertIn(
Pierre-Yves Chibon 5e14ea
                'project.1',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 5e14ea
            )
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 73d120
        # After
Pierre-Yves Chibon 5e14ea
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 5e14ea
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 5e14ea
    def test_new_project_with_plus(self):
Pierre-Yves Chibon 5e14ea
        """ Test the new_project endpoint when new project contains a plus sign.
Pierre-Yves Chibon 5e14ea
        """
Pierre-Yves Chibon 5e14ea
        # Before
Pierre-Yves Chibon 5e14ea
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 5e14ea
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 5e14ea
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon 5e14ea
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5e14ea
            csrf_token = self.get_csrf()
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 5e14ea
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1.",
Pierre-Yves Chibon 73d120
                "name": "project+1",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 5e14ea
            }
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 5e14ea
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5e14ea
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 5e14ea
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Overview - project+1 - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon c6cc5c
            self.assertTrue(
Pierre-Yves Chibon 73d120
                'project+1'
Pierre-Yves Chibon 73d120
                in output_text
Pierre-Yves Chibon 73d120
                or 'project+1'
Pierre-Yves Chibon 73d120
                in output_text
Pierre-Yves Chibon 5e14ea
            )
Pierre-Yves Chibon 5e14ea
Pierre-Yves Chibon 73d120
        # After
Pierre-Yves Chibon 5e14ea
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 5e14ea
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 5e14ea
Vivek Anand 3b0299
    def test_new_project_when_turned_off(self):
Vivek Anand 3b0299
        """ Test the new_project endpoint when new project creation is
Vivek Anand 3b0299
        not allowed in the pagure instance. """
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
        # turn the project creation off
Pierre-Yves Chibon 73d120
        pagure.config.config["ENABLE_NEW_PROJECTS"] = False
Vivek Anand 3b0299
Vivek Anand 3b0299
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Vivek Anand 3b0299
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "tickets", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "docs", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "requests", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Vivek Anand 3b0299
Vivek Anand 3b0299
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
            # just get the csrf token
Pierre-Yves Chibon 73d120
            pagure.config.config["ENABLE_NEW_PROJECTS"] = True
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon 73d120
            pagure.config.config["ENABLE_NEW_PROJECTS"] = False
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
            csrf_token = (
Pierre-Yves Chibon 73d120
                output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
                .split('name="csrf_token" type="hidden" value="')[1]
Pierre-Yves Chibon 73d120
                .split('">')[0]
Pierre-Yves Chibon 73d120
            )
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
            data = {"description": "Project #1", "name": "project-1"}
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
        # After
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Vivek Anand 3b0299
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "tickets", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "docs", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "requests", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Vivek Anand 3b0299
Pierre-Yves Chibon 73d120
        pagure.config.config["ENABLE_NEW_PROJECTS"] = True
Vivek Anand 3b0299
Pierre-Yves Chibon 227f4c
    def test_new_project_mirrored_invalid_url(self):
Pierre-Yves Chibon 227f4c
        """ Test the new_project with a mirrored repo but an invalid URL. """
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon 227f4c
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon 227f4c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "mirrored_from": "abcd",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 227f4c
            }
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 227f4c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 227f4c
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("<title>New project - Pagure</title>", output_text)
Pierre-Yves Chibon 73d120
            self.assertIn("Invalid input. ", output_text)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
    def test_new_project_mirrored_invalid_sshurl(self):
Pierre-Yves Chibon 227f4c
        """ Test the new_project with a mirrored repo but an invalid
Pierre-Yves Chibon 227f4c
        SSH-like url.
Pierre-Yves Chibon 227f4c
        """
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon 227f4c
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon 227f4c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "mirrored_from": "ssh://git@server.org/foo/bar.git",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 227f4c
            }
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 227f4c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 227f4c
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("<title>New project - Pagure</title>", output_text)
Pierre-Yves Chibon 73d120
            self.assertIn("Invalid input. ", output_text)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
    def test_new_project_mirrored_valid_url(self):
Pierre-Yves Chibon 227f4c
        """ Test the new_project with a mirrored repo with a valid url. """
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon 227f4c
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon 227f4c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cdb351
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cdb351
            self.assertIn(
Pierre-Yves Chibon cdb351
                '<label for="mirrored_from">Mirror from URL'</label>
Pierre-Yves Chibon 73d120
                "",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "mirrored_from": "https://example.com/foo/bar.git",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 227f4c
            }
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 227f4c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 227f4c
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 227f4c
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Overview - project-1 - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 227f4c
            self.assertIn(
Pierre-Yves Chibon 73d120
                "

This repo is brand new and meant to be mirrored from "

Pierre-Yves Chibon 73d120
                "https://example.com/foo/bar.git !

",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cdb351
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"DISABLE_MIRROR_IN": True})
Pierre-Yves Chibon cdb351
    def test_new_project_mirrored_mirror_disabled(self):
Pierre-Yves Chibon cdb351
        """ Test the new_project with a mirrored repo when that feature is
Pierre-Yves Chibon cdb351
        disabled.
Pierre-Yves Chibon cdb351
        """
Pierre-Yves Chibon cdb351
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon cdb351
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon cdb351
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cdb351
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon cdb351
            self.assertNotIn(
Pierre-Yves Chibon cdb351
                '<label for="mirrored_from">Mirror from URL'</label>
Pierre-Yves Chibon 73d120
                "",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon cdb351
Pierre-Yves Chibon cdb351
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon cdb351
Pierre-Yves Chibon cdb351
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "mirrored_from": "https://example.com/foo/bar.git",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon cdb351
            }
Pierre-Yves Chibon cdb351
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon cdb351
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon cdb351
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("<title>New project - Pagure</title>", output_text)
Pierre-Yves Chibon cdb351
            self.assertIn(
Pierre-Yves Chibon 73d120
                " Mirroring in projects has been disabled in "
Pierre-Yves Chibon 73d120
                "this instance",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon e5e107
    def test_new_project(self):
Pierre-Yves Chibon e5e107
        """ Test the new_project endpoint. """
Pierre-Yves Chibon e5e107
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon e5e107
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(os.path.join(self.path, "repos", "project#1.git"))
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "tickets", "project#1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "docs", "project#1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "requests", "project#1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon e5e107
Pierre-Yves Chibon e5e107
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon e5e107
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon e5e107
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 e5e107
Pierre-Yves Chibon 73d120
            data = {"description": "Project #1"}
Pierre-Yves Chibon e5e107
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data)
Pierre-Yves Chibon e5e107
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon 016b9a
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<small>\n            This field is required. \n"</small>
Pierre-Yves Chibon 73d120
                "          ",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon e5e107
Pierre-Yves Chibon 73d120
            data["name"] = "project-1"
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data)
Pierre-Yves Chibon e5e107
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon 016b9a
            self.assertNotIn(
Pierre-Yves Chibon 73d120
                "<small>\n            This field is required. \n"</small>
Pierre-Yves Chibon 73d120
                "          ",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon e5e107
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data)
Pierre-Yves Chibon e5e107
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon 73d120
            self.assertIn("No user " ""username" found", output_text)
Pierre-Yves Chibon e5e107
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon e5e107
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 98f2af
            self.assertIn(
Pierre-Yves Chibon 73d120
                '
\nProject #1', output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("

This repo is brand new!

", output_text)
Pierre-Yves Chibon 64f5f4
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Overview - project-1 - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon e5e107
Pierre-Yves Chibon e5e107
        # After
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon e5e107
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "tickets", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "docs", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "requests", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
Pierre-Yves Chibon 73d120
    @patch.dict(
Pierre-Yves Chibon 73d120
        "pagure.config.config",
Pierre-Yves Chibon 73d120
        {
Pierre-Yves Chibon 73d120
            "PAGURE_ADMIN_USERS": ["pingou"],
Pierre-Yves Chibon 73d120
            "ALLOW_ADMIN_IGNORE_EXISTING_REPOS": True,
Pierre-Yves Chibon 73d120
        },
Pierre-Yves Chibon 73d120
    )
Patrick Uiterwijk 335383
    def test_adopt_repos(self):
Patrick Uiterwijk 335383
        """ Test the new_project endpoint with existing git repo. """
Patrick Uiterwijk 335383
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Patrick Uiterwijk 335383
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
Pierre-Yves Chibon 73d120
        tests.add_content_git_repo(
Pierre-Yves Chibon 73d120
            os.path.join(self.path, "repos", "test.git")
Pierre-Yves Chibon 73d120
        )
Patrick Uiterwijk 335383
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Patrick Uiterwijk 335383
        with tests.user_set(self.app.application, user):
Patrick Uiterwijk 335383
            data = {
Pierre-Yves Chibon 73d120
                "csrf_token": self.get_csrf(),
Pierre-Yves Chibon 73d120
                "name": "test",
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Patrick Uiterwijk 335383
            }
Patrick Uiterwijk 335383
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Patrick Uiterwijk 335383
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 335383
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("The main repo test.git already exists", output_text)
Patrick Uiterwijk 335383
Pierre-Yves Chibon 73d120
            data["ignore_existing_repos"] = "y"
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Patrick Uiterwijk 335383
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 335383
            output_text = output.get_data(as_text=True)
Patrick Uiterwijk 335383
            self.assertIn("Alice Author", output_text)
Patrick Uiterwijk 335383
Pierre-Yves Chibon 73d120
    @patch.dict(
Pierre-Yves Chibon 73d120
        "pagure.config.config",
Pierre-Yves Chibon 73d120
        {"PAGURE_ADMIN_USERS": [], "USERS_IGNORE_EXISTING_REPOS": ["pingou"]},
Pierre-Yves Chibon 73d120
    )
Patrick Uiterwijk 9638fb
    def test_adopt_repos_non_admin(self):
Patrick Uiterwijk 9638fb
        """ Test the new_project endpoint with existing git repo for non-admins. """
Patrick Uiterwijk 9638fb
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Patrick Uiterwijk 9638fb
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
Pierre-Yves Chibon 73d120
        tests.add_content_git_repo(
Pierre-Yves Chibon 73d120
            os.path.join(self.path, "repos", "test.git")
Pierre-Yves Chibon 73d120
        )
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Patrick Uiterwijk 9638fb
        with tests.user_set(self.app.application, user):
Patrick Uiterwijk 9638fb
            data = {
Pierre-Yves Chibon 73d120
                "csrf_token": self.get_csrf(),
Pierre-Yves Chibon 73d120
                "name": "test",
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Patrick Uiterwijk 9638fb
            }
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Patrick Uiterwijk 9638fb
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9638fb
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("The main repo test.git already exists", output_text)
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
            data["ignore_existing_repos"] = "y"
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Patrick Uiterwijk 9638fb
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9638fb
            output_text = output.get_data(as_text=True)
Patrick Uiterwijk 9638fb
            self.assertIn("Alice Author", output_text)
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
    @patch.dict(
Pierre-Yves Chibon 73d120
        "pagure.config.config",
Pierre-Yves Chibon 73d120
        {"PAGURE_ADMIN_USERS": [], "USERS_IGNORE_EXISTING_REPOS": []},
Pierre-Yves Chibon 73d120
    )
Patrick Uiterwijk 9638fb
    def test_adopt_repos_not_allowed(self):
Patrick Uiterwijk 9638fb
        """ Test the new_project endpoint with existing git repo for no access. """
Patrick Uiterwijk 9638fb
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Patrick Uiterwijk 9638fb
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
Pierre-Yves Chibon 73d120
        tests.add_content_git_repo(
Pierre-Yves Chibon 73d120
            os.path.join(self.path, "repos", "test.git")
Pierre-Yves Chibon 73d120
        )
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Patrick Uiterwijk 9638fb
        with tests.user_set(self.app.application, user):
Patrick Uiterwijk 9638fb
            data = {
Pierre-Yves Chibon 73d120
                "csrf_token": self.get_csrf(),
Pierre-Yves Chibon 73d120
                "name": "test",
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Patrick Uiterwijk 9638fb
            }
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Patrick Uiterwijk 9638fb
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9638fb
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("The main repo test.git already exists", output_text)
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
            data["ignore_existing_repos"] = "y"
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Patrick Uiterwijk 9638fb
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9638fb
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("The main repo test.git already exists", output_text)
Patrick Uiterwijk 9638fb
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"PROJECT_NAME_REGEX": "^1[a-z]*$"})
Pierre-Yves Chibon dc53a9
    def test_new_project_diff_regex(self):
Pierre-Yves Chibon dc53a9
        """ Test the new_project endpoint with a different regex. """
Pierre-Yves Chibon dc53a9
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon dc53a9
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon dc53a9
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="foo")
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon dc53a9
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon dc53a9
Pierre-Yves Chibon dc53a9
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon dc53a9
Pierre-Yves Chibon dc53a9
            data = {
Pierre-Yves Chibon 73d120
                "description": "Project #1",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon dc53a9
            }
Pierre-Yves Chibon dc53a9
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon dc53a9
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("<title>New project - Pagure</title>", output_text)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon dc53a9
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<small>\n            Invalid input. \n"</small>
Pierre-Yves Chibon 73d120
                "          ",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon dc53a9
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"PRIVATE_PROJECTS": True})
Pierre-Yves Chibon f1cd93
    def test_new_project_private(self):
Pierre-Yves Chibon f1cd93
        """ Test the new_project endpoint for a private project. """
Pierre-Yves Chibon f1cd93
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon f1cd93
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "foo", "project#1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(
Pierre-Yves Chibon 73d120
                    self.path, "repos", "tickets", "foo", "project#1.git"
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(
Pierre-Yves Chibon 73d120
                    self.path, "repos", "docs", "foo", "project#1.git"
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(
Pierre-Yves Chibon 73d120
                    self.path, "repos", "requests", "foo", "project#1.git"
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon f1cd93
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon f1cd93
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon f1cd93
            self.assertIn(
Pierre-Yves Chibon 73d120
                "Create new Project",
Pierre-Yves Chibon 73d120
                output.get_data(as_text=True),
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon f1cd93
Aurélien Bompard 626417
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon 73d120
            data = {"description": "Project #1", "private": True}
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data)
Pierre-Yves Chibon f1cd93
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon f1cd93
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<small>\n            This field is required. \n"</small>
Pierre-Yves Chibon 73d120
                "          ",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon 73d120
            data["name"] = "project-1"
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data)
Pierre-Yves Chibon f1cd93
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon f1cd93
            self.assertNotIn(
Pierre-Yves Chibon 73d120
                "<small>\n            This field is required. \n"</small>
Pierre-Yves Chibon 73d120
                "          ",
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data)
Pierre-Yves Chibon f1cd93
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon 73d120
            self.assertIn("No user " ""username" found", output_text)
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon f1cd93
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon f1cd93
            self.assertIn(
Pierre-Yves Chibon 73d120
                '
\nProject #1', output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("

This repo is brand new!

", output_text)
Pierre-Yves Chibon f1cd93
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>Overview - foo/project-1 - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon f1cd93
        # After
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon f1cd93
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session, private=True)
Pierre-Yves Chibon f1cd93
        self.assertEqual(len(projects), 1)
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "foo", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(
Pierre-Yves Chibon 73d120
                    self.path, "repos", "tickets", "foo", "project-1.git"
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(
Pierre-Yves Chibon 73d120
                    self.path, "repos", "docs", "foo", "project-1.git"
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertTrue(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(
Pierre-Yves Chibon 73d120
                    self.path, "repos", "requests", "foo", "project-1.git"
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon f1cd93
Pierre-Yves Chibon 5833b3
    def test_non_ascii_new_project(self):
Pierre-Yves Chibon 5833b3
        """ Test the new_project endpoint with a non-ascii project. """
Pierre-Yves Chibon 5833b3
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 5833b3
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "tickets", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "docs", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "requests", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 5833b3
Pierre-Yves Chibon 5833b3
        user = tests.FakeUser()
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon 5833b3
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Create new Project", output_text)
Pierre-Yves Chibon 5833b3
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 5833b3
Pierre-Yves Chibon 5833b3
            data = {
Pierre-Yves Chibon 73d120
                "description": "Prõjéctö #1",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 73d120
                "create_readme": True,
Pierre-Yves Chibon 5833b3
            }
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon a219ad
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 5833b3
            self.assertIn(
Pierre-Yves Chibon 73d120
                '
\nPrõjéctö #1', output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 5833b3
            self.assertIn(
Pierre-Yves Chibon 73d120
                """<section class="readme"></section>
Shengjing Zhu 539c7f
              

project-1

Pierre-Yves Chibon a219ad

Prõjéctö #1

Pierre-Yves Chibon 73d120
            """,
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 5833b3
Pierre-Yves Chibon 645b66
            data = {
Pierre-Yves Chibon 73d120
                "description": "Мой первый суперский репозиторий",
Pierre-Yves Chibon 73d120
                "name": "project-2",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 73d120
                "create_readme": True,
Pierre-Yves Chibon 645b66
            }
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 645b66
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 645b66
            self.assertIn(
Ryan Lerch 6d2e06
                '
\nМой первый суперский репозиторий',
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 645b66
            self.assertIn(
Pierre-Yves Chibon 73d120
                """<section class="readme"></section>
Shengjing Zhu 539c7f
              

project-2

Pierre-Yves Chibon 645b66

Мой первый суперский репозиторий

Pierre-Yves Chibon 73d120
            """,
Pierre-Yves Chibon 73d120
                output_text,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 645b66
Pierre-Yves Chibon 5833b3
        # After
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 645b66
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon 73d120
        for project in ["project-1", "project-2"]:
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "%s.git" % project)
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(
Pierre-Yves Chibon 73d120
                        self.path, "repos", "tickets", "%s.git" % project
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(
Pierre-Yves Chibon 73d120
                        self.path, "repos", "docs", "%s.git" % project
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(
Pierre-Yves Chibon 73d120
                        self.path, "repos", "requests", "%s.git" % project
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
Pierre-Yves Chibon 73d120
    @patch("pygit2.init_repository", wraps=pygit2.init_repository)
Pierre-Yves Chibon 8a428c
    def test_new_project_with_template(self, pygit2init):
Pierre-Yves Chibon 8a428c
        """ Test the new_project endpoint for a new project with a template set.
Pierre-Yves Chibon 8a428c
        """
Pierre-Yves Chibon 8a428c
        # Before
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 8a428c
        self.assertEqual(len(projects), 0)
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "tickets", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "docs", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertFalse(
Pierre-Yves Chibon 73d120
            os.path.exists(
Pierre-Yves Chibon 73d120
                os.path.join(self.path, "repos", "requests", "project-1.git")
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 8a428c
        user = tests.FakeUser()
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon 8a428c
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Pierre-Yves Chibon 8a428c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 8a428c
            self.assertIn(
Pierre-Yves Chibon 73d120
                "Create new Project",
Pierre-Yves Chibon 73d120
                output.get_data(as_text=True),
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 8a428c
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 8a428c
            data = {
Pierre-Yves Chibon 73d120
                "description": "test",
Pierre-Yves Chibon 73d120
                "name": "project-1",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 73d120
                "create_readme": True,
Pierre-Yves Chibon 8a428c
            }
Pierre-Yves Chibon 73d120
            output = self.app.post("/new/", data=data, follow_redirects=True)
Pierre-Yves Chibon 8a428c
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 8a428c
            self.assertIn(
Ryan Lerch 6d2e06
                '
\ntest',
Pierre-Yves Chibon 73d120
                output.get_data(as_text=True),
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 8a428c
            self.assertEqual(pygit2init.call_count, 4)
Pierre-Yves Chibon 8a428c
            pygit2init.assert_any_call(
Pierre-Yves Chibon 73d120
                "%s/repos/project-1.git" % self.path,
Pierre-Yves Chibon 73d120
                bare=True,
Pierre-Yves Chibon 73d120
                template_path=None,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 73d120
            path = os.path.join(self.path, "repos", "project-1.git")
Pierre-Yves Chibon 8a428c
            with patch.dict(
Pierre-Yves Chibon 73d120
                "pagure.config.config", {"PROJECT_TEMPLATE_PATH": path}
Pierre-Yves Chibon 73d120
            ):
Pierre-Yves Chibon 8a428c
                data = {
Pierre-Yves Chibon 73d120
                    "description": "test2",
Pierre-Yves Chibon 73d120
                    "name": "project-2",
Pierre-Yves Chibon 73d120
                    "csrf_token": csrf_token,
Pierre-Yves Chibon 73d120
                    "create_readme": True,
Pierre-Yves Chibon 8a428c
                }
Pierre-Yves Chibon 73d120
                output = self.app.post(
Pierre-Yves Chibon 73d120
                    "/new/", data=data, follow_redirects=True
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 8a428c
                self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 8a428c
                self.assertIn(
Ryan Lerch 6d2e06
                    '
\ntest2',
Pierre-Yves Chibon 73d120
                    output.get_data(as_text=True),
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 8a428c
            self.assertEqual(pygit2init.call_count, 8)
Pierre-Yves Chibon 8a428c
            pygit2init.assert_any_call(
Pierre-Yves Chibon 73d120
                "%s/repos/project-2.git" % self.path,
Pierre-Yves Chibon 8a428c
                bare=True,
Pierre-Yves Chibon 73d120
                template_path="%s/repos/project-1.git" % self.path,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 8a428c
Pierre-Yves Chibon 8a428c
        # After
Pierre-Yves Chibon 930073
        projects = pagure.lib.query.search_projects(self.session)
Pierre-Yves Chibon 8a428c
        self.assertEqual(len(projects), 2)
Pierre-Yves Chibon 73d120
        for project in ["project-1", "project-2"]:
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "%s.git" % project)
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(
Pierre-Yves Chibon 73d120
                        self.path, "repos", "tickets", "%s.git" % project
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(
Pierre-Yves Chibon 73d120
                        self.path, "repos", "docs", "%s.git" % project
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertTrue(
Pierre-Yves Chibon 73d120
                os.path.exists(
Pierre-Yves Chibon 73d120
                    os.path.join(
Pierre-Yves Chibon 73d120
                        self.path, "repos", "requests", "%s.git" % project
Pierre-Yves Chibon 73d120
                    )
Pierre-Yves Chibon 73d120
                )
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
Pierre-Yves Chibon 73d120
    @patch.dict("pagure.config.config", {"CASE_SENSITIVE": True})
Slavek Kabrda 1e87ae
    def test_new_project_case_sensitive(self):
Slavek Kabrda 1e87ae
        tests.create_projects(self.session)
Pierre-Yves Chibon 73d120
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
Slavek Kabrda 1e87ae
Pierre-Yves Chibon 73d120
        output = self.app.get("/test")
Slavek Kabrda 1e87ae
        self.assertEqual(output.status_code, 200)
Slavek Kabrda 1e87ae
Pierre-Yves Chibon 73d120
        output = self.app.get("/TEST")
Slavek Kabrda 1e87ae
        self.assertEqual(output.status_code, 404)
Slavek Kabrda 1e87ae
Slavek Kabrda 1e87ae
        user = tests.FakeUser()
Pierre-Yves Chibon 73d120
        user.username = "foo"
Slavek Kabrda 1e87ae
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/new/")
Slavek Kabrda 1e87ae
            self.assertEqual(output.status_code, 200)
Slavek Kabrda 1e87ae
Slavek Kabrda 1e87ae
            csrf_token = self.get_csrf(output=output)
Slavek Kabrda 1e87ae
            data = {
Pierre-Yves Chibon 73d120
                "description": "TEST",
Pierre-Yves Chibon 73d120
                "name": "TEST",
Pierre-Yves Chibon 73d120
                "csrf_token": csrf_token,
Pierre-Yves Chibon 73d120
                "create_readme": True,
Slavek Kabrda 1e87ae
            }
Pierre-Yves Chibon 73d120
            self.app.post("/new/", data=data, follow_redirects=True)
Slavek Kabrda 1e87ae
Pierre-Yves Chibon 73d120
            output = self.app.get("/TEST")
Slavek Kabrda 1e87ae
            self.assertEqual(output.status_code, 200)
Slavek Kabrda 1e87ae
Pierre-Yves Chibon 73d120
    @patch("pagure.ui.app.admin_session_timedout")
Pierre-Yves Chibon 893463
    def test_user_settings(self, ast):
Pierre-Yves Chibon 7958b1
        """ Test the user_settings endpoint. """
Pierre-Yves Chibon 893463
        ast.return_value = False
Pierre-Yves Chibon 7958b1
        self.test_new_project()
Pierre-Yves Chibon 7958b1
Pierre-Yves Chibon 7958b1
        user = tests.FakeUser()
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/settings/")
Pierre-Yves Chibon 7958b1
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 73d120
            self.assertIn(
Pierre-Yves Chibon 73d120
                "

Page not found (404)

", output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7958b1
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/settings/")
Pierre-Yves Chibon 7958b1
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 64f5f4
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>foo's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 7958b1
Patrick Uiterwijk 9b237b
            ast.return_value = True
Pierre-Yves Chibon 73d120
            output = self.app.get("/settings/")
Patrick Uiterwijk 9b237b
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 7958b1
Pierre-Yves Chibon 73d120
    @patch("pagure.decorators.admin_session_timedout")
Pierre-Yves Chibon f1a842
    def test_add_user_sshkey(self, ast):
Pierre-Yves Chibon f1a842
        """ Test the add_user_sshkey endpoint. """
Patrick Uiterwijk 9b237b
        ast.return_value = False
Pierre-Yves Chibon 7958b1
Patrick Uiterwijk 9b237b
        # User not logged in
Pierre-Yves Chibon 73d120
        output = self.app.get("/settings/")
Patrick Uiterwijk 9b237b
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 7958b1
Patrick Uiterwijk 9b237b
        ast.return_value = False
Pierre-Yves Chibon 7958b1
Pierre-Yves Chibon 73d120
        user = tests.FakeUser(username="pingou")
Patrick Uiterwijk 9b237b
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/settings", follow_redirects=True)
Pierre-Yves Chibon 7958b1
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Add SSH key", output_text)
Patrick Uiterwijk f888fd
Pierre-Yves Chibon 3f434c
            csrf_token = self.get_csrf(output=output)
Patrick Uiterwijk f888fd
Pierre-Yves Chibon 73d120
            data = {"ssh_key": "asdf"}
Patrick Uiterwijk f888fd
Patrick Uiterwijk 9b237b
            # No CSRF token
Pierre-Yves Chibon 3f434c
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/addkey",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Patrick Uiterwijk f888fd
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Add SSH key", output_text)
Pierre-Yves Chibon 7958b1
Pierre-Yves Chibon 73d120
            data["csrf_token"] = csrf_token
Pierre-Yves Chibon 893463
Patrick Uiterwijk 9b237b
            # First, invalid SSH key
Pierre-Yves Chibon 3f434c
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/addkey",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Patrick Uiterwijk 9b237b
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9b237b
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Add SSH key", output_text)
Pierre-Yves Chibon 73d120
            self.assertIn("SSH key invalid", output_text)
Pierre-Yves Chibon 91c9c0
Patrick Uiterwijk 9b237b
            # Next up, multiple SSH keys
Pierre-Yves Chibon 73d120
            data[
Pierre-Yves Chibon 73d120
                "ssh_key"
Pierre-Yves Chibon 73d120
            ] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q=="
Patrick Uiterwijk 9b237b
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/addkey",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Patrick Uiterwijk 9b237b
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9b237b
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("Please add single SSH keys.", output_text)
Patrick Uiterwijk 9b237b
Patrick Uiterwijk 9b237b
            # Now, a valid SSH key
Pierre-Yves Chibon 73d120
            data[
Pierre-Yves Chibon 73d120
                "ssh_key"
Pierre-Yves Chibon 73d120
            ] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q=="
Patrick Uiterwijk 9b237b
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/addkey",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 91c9c0
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 91c9c0
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>pingou's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("SSH key added", output_text)
Pierre-Yves Chibon 73d120
            self.assertNotIn("Push Access", output_text)
Pierre-Yves Chibon 91c9c0
Patrick Uiterwijk 9b237b
            # And now, adding the same key
Patrick Uiterwijk 9b237b
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/addkey",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Patrick Uiterwijk 9b237b
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9b237b
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
            self.assertIn("SSH key already exists", output_text)
Pierre-Yves Chibon 91c9c0
Patrick Uiterwijk 9b237b
            # And next, a key with push access
Pierre-Yves Chibon 73d120
            data[
Pierre-Yves Chibon 73d120
                "ssh_key"
Pierre-Yves Chibon 73d120
            ] = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9Xwc2RDzPBhlEDARfHldGjudIVoa04tqT1JVKGQmyllTFz7Rb8CngQL3e7zyNzotnhwYKHdoiLlPkVEiDee4dWMUe48ilqId+FJZQGhyv8fu4BoFdE1AJUVylzmltbLg14VqG5gjTpXgtlrEva9arKwBMHJjRYc8ScaSn3OgyQw=="
Patrick Uiterwijk 9b237b
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/addkey",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 91c9c0
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 91c9c0
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>pingou's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("SSH key added", output_text)
Pierre-Yves Chibon 91c9c0
Pierre-Yves Chibon 73d120
    @patch("pagure.decorators.admin_session_timedout")
Pierre-Yves Chibon f1a842
    def test_remove_user_sshkey(self, ast):
Patrick Uiterwijk 9b237b
        """ Test the remove_sshkey endpoint. """
Patrick Uiterwijk 9b237b
        ast.return_value = False
Pierre-Yves Chibon 91c9c0
Patrick Uiterwijk 9b237b
        user = tests.FakeUser()
Patrick Uiterwijk 9b237b
        # User not logged in
Pierre-Yves Chibon 73d120
        output = self.app.post("/settings/usersettings/removekey/1")
Patrick Uiterwijk 9b237b
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 91c9c0
Pierre-Yves Chibon 73d120
        user.username = "pingou"
Patrick Uiterwijk 9b237b
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            data = {"csrf_token": self.get_csrf()}
Pierre-Yves Chibon 91c9c0
Pierre-Yves Chibon 91c9c0
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/removekey/1",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 91c9c0
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 91c9c0
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>pingou's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("SSH key does not exist", output_text)
Patrick Uiterwijk 9b237b
Patrick Uiterwijk 9b237b
        # Add a deploy key to a project
Pierre-Yves Chibon 73d120
        pingou = pagure.lib.query.get_user(self.session, "pingou")
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_sshkey_to_project_or_user(
Patrick Uiterwijk 9b237b
            session=self.session,
Pierre-Yves Chibon 73d120
            ssh_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDAzBMSIlvPRaEiLOTVInErkRIw9CzQQcnslDekAn1jFnGf+SNa1acvbTiATbCX71AA03giKrPxPH79dxcC7aDXerc6zRcKjJs6MAL9PrCjnbyxCKXRNNZU5U9X/DLaaL1b3caB+WD6OoorhS3LTEtKPX8xyjOzhf3OQSzNjhJp5Q==",
Patrick Uiterwijk 9b237b
            user=pingou,
Patrick Uiterwijk 9b237b
            pushaccess=True,
Pierre-Yves Chibon f1a842
            creator=pingou,
Patrick Uiterwijk 9b237b
        )
Patrick Uiterwijk 9b237b
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, "SSH key added")
Patrick Uiterwijk 9b237b
Patrick Uiterwijk 9b237b
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/removekey/1", follow_redirects=True
Pierre-Yves Chibon 73d120
            )
Patrick Uiterwijk 9b237b
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9b237b
            output_text = output.get_data(as_text=True)
Patrick Uiterwijk 9b237b
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>pingou's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertNotIn("SSH key removed", output_text)
Pierre-Yves Chibon 91c9c0
Pierre-Yves Chibon 73d120
            data = {"csrf_token": self.get_csrf()}
Patrick Uiterwijk 9b237b
            output = self.app.post(
Pierre-Yves Chibon 73d120
                "/settings/usersettings/removekey/1",
Pierre-Yves Chibon 73d120
                data=data,
Pierre-Yves Chibon 73d120
                follow_redirects=True,
Pierre-Yves Chibon 73d120
            )
Patrick Uiterwijk 9b237b
            self.assertEqual(output.status_code, 200)
Patrick Uiterwijk 9b237b
            output_text = output.get_data(as_text=True)
Patrick Uiterwijk 9b237b
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>pingou's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon 73d120
            self.assertIn("SSH key removed", output_text)
Pierre-Yves Chibon 91c9c0
Pierre-Yves Chibon 80e0f2
    def patched_commit_exists(user, namespace, repo, githash):
Pierre-Yves Chibon 73d120
        """ Patched version of pagure.pfmarkdown._commit_exists to enforce
Pierre-Yves Chibon 80e0f2
        returning true on some given hash without having us actually check
Pierre-Yves Chibon 80e0f2
        the git repos.
Pierre-Yves Chibon 73d120
        """
Pierre-Yves Chibon 73d120
        if githash in [
Pierre-Yves Chibon 73d120
            "9364354",
Pierre-Yves Chibon 73d120
            "9364354a",
Pierre-Yves Chibon 73d120
            "9364354a4555ba17aa60f0dc844d70b74eb1aecd",
Pierre-Yves Chibon 73d120
        ]:
Pierre-Yves Chibon 80e0f2
            return True
Pierre-Yves Chibon 80e0f2
        else:
Pierre-Yves Chibon 80e0f2
            return False
Pierre-Yves Chibon 80e0f2
Pierre-Yves Chibon 80e0f2
    @patch(
Pierre-Yves Chibon 73d120
        "pagure.pfmarkdown._commit_exists",
Pierre-Yves Chibon 73d120
        MagicMock(side_effect=patched_commit_exists),
Pierre-Yves Chibon 73d120
    )
Pierre-Yves Chibon f66c8c
    def test_patched_markdown_preview(self):
Pierre-Yves Chibon 1ea2d8
        """ Test the markdown_preview endpoint. """
Pierre-Yves Chibon 1ea2d8
Pierre-Yves Chibon 73d120
        data = {"content": "test\n----\n\n * 1\n * item 2"}
Pierre-Yves Chibon 1ea2d8
Pierre-Yves Chibon f629ce
        # CSRF missing
Pierre-Yves Chibon 73d120
        output = self.app.post("/markdown/", data=data)
Pierre-Yves Chibon f629ce
        self.assertEqual(output.status_code, 400)
Pierre-Yves Chibon 1ea2d8
Pierre-Yves Chibon 1ea2d8
        user = tests.FakeUser()
Pierre-Yves Chibon 73d120
        user.username = "foo"
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 73d120
            output = self.app.get("/settings/")
Pierre-Yves Chibon 1ea2d8
            self.assertEqual(output.status_code, 200)
Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
Pierre-Yves Chibon 64f5f4
            self.assertIn(
Pierre-Yves Chibon 73d120
                "<title>foo's settings - Pagure</title>", output_text
Pierre-Yves Chibon 73d120
            )
Pierre-Yves Chibon f629ce
Pierre-Yves Chibon 88d13c
            csrf_token = self.get_csrf(output=output)
Pierre-Yves Chibon f629ce
Pierre-Yves Chibon f629ce
        # With CSRF
Pierre-Yves Chibon 73d120
        data["csrf_token"] = csrf_token
Pierre-Yves Chibon 73d120
        output = self.app.post("/markdown/", data=data)
Pierre-Yves Chibon f629ce
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon f629ce
        exp = """

test

Pierre-Yves Chibon 1ea2d8
    Pierre-Yves Chibon 1ea2d8
  • 1
  • Pierre-Yves Chibon 1ea2d8
  • item 2
  • Pierre-Yves Chibon 1ea2d8
    """
    Aurélien Bompard 626417
            self.assertEqual(output.get_data(as_text=True), exp)
    Pierre-Yves Chibon 1ea2d8
    Pierre-Yves Chibon 82e2f3
            tests.create_projects(self.session)
    Pierre-Yves Chibon 82e2f3
            texts = [
    Pierre-Yves Chibon 73d120
                "pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd",
    Pierre-Yves Chibon 73d120
                "Cf commit 936435",  # 6 chars - not long enough
    Pierre-Yves Chibon 73d120
                "Cf commit 9364354",  # 7 chars - long enough
    Pierre-Yves Chibon 73d120
                "Cf commit 9364354a",  # 8 chars - still long enough
    Pierre-Yves Chibon 73d120
                "Cf commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd",  # 40 chars
    Pierre-Yves Chibon 82e2f3
            ]
    Pierre-Yves Chibon 82e2f3
            expected = [
    Pierre-Yves Chibon 82e2f3
                # 'pingou committed on test#9364354a4555ba17aa60f0dc844d70b74eb1aecd',
    Pierre-Yves Chibon 82e2f3
                '

    pingou committed on

    Pierre-Yves Chibon 82e2f3
                'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'
    Pierre-Yves Chibon 73d120
                ">test#9364354a4555ba17aa60f0dc844d70b74eb1aecd

    ",
    Pierre-Yves Chibon 82e2f3
                # 'Cf commit 936435',
    Pierre-Yves Chibon 73d120
                "

    Cf commit 936435

    ",
    Pierre-Yves Chibon 82e2f3
                # 'Cf commit 9364354',
    Pierre-Yves Chibon 82e2f3
                #'

    Cf commit 9364354

    ',
    Clement Verna 90bb3b
                '

    Cf commit

    Clement Verna 90bb3b
                'title="Commit 9364354">9364354

    ',
    Pierre-Yves Chibon 82e2f3
                # 'Cf commit 9364354a',
    Clement Verna 90bb3b
                '

    Cf commit

    Clement Verna 90bb3b
                'title="Commit 9364354a">9364354

    ',
    Pierre-Yves Chibon 82e2f3
                # 'Cf commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd',
    Clement Verna 90bb3b
                '

    Cf commit

    Pierre-Yves Chibon 82e2f3
                'title="Commit 9364354a4555ba17aa60f0dc844d70b74eb1aecd"'
    Pierre-Yves Chibon 73d120
                ">9364354

    ",
    Pierre-Yves Chibon 82e2f3
            ]
    Pierre-Yves Chibon 82e2f3
    Pierre-Yves Chibon b130e5
            with self.app.application.app_context():
    Pierre-Yves Chibon 82e2f3
                for idx, text in enumerate(texts):
    Pierre-Yves Chibon 73d120
                    data = {"content": text, "csrf_token": csrf_token}
    Pierre-Yves Chibon 73d120
                    output = self.app.post("/markdown/?repo=test", data=data)
    Pierre-Yves Chibon 82e2f3
                    self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                    self.assertEqual(expected[idx], output.get_data(as_text=True))
    Pierre-Yves Chibon 82e2f3
    Pierre-Yves Chibon 80e0f2
        def test_markdown_preview(self):
    Pierre-Yves Chibon f66c8c
            """ Test the markdown_preview endpoint with a non-existing commit.
    Pierre-Yves Chibon f66c8c
            """
    Pierre-Yves Chibon 80e0f2
    Pierre-Yves Chibon 80e0f2
            user = tests.FakeUser()
    Pierre-Yves Chibon 73d120
            user.username = "foo"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/")
    Pierre-Yves Chibon 80e0f2
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 80e0f2
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 80e0f2
    Pierre-Yves Chibon 88d13c
                csrf_token = self.get_csrf(output=output)
    Pierre-Yves Chibon 80e0f2
    Pierre-Yves Chibon 80e0f2
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
    Pierre-Yves Chibon 73d120
            text = "Cf commit 9364354a4555ba17aa60f0d"
    Pierre-Yves Chibon 73d120
            exp = "

    Cf commit 9364354a4555ba17aa60f0d

    "
    Pierre-Yves Chibon 80e0f2
    Pierre-Yves Chibon b130e5
            with self.app.application.app_context():
    Pierre-Yves Chibon 73d120
                data = {"content": text, "csrf_token": csrf_token}
    Pierre-Yves Chibon 73d120
                output = self.app.post("/markdown/?repo=test", data=data)
    Pierre-Yves Chibon 80e0f2
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                self.assertEqual(exp, output.get_data(as_text=True))
    Pierre-Yves Chibon 80e0f2
    Pierre-Yves Chibon f66c8c
        def test_markdown_preview_valid_commit(self):
    Pierre-Yves Chibon f66c8c
            """ Test the markdown_preview endpoint with an existing commit. """
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon f66c8c
            user = tests.FakeUser()
    Pierre-Yves Chibon 73d120
            user.username = "foo"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/")
    Pierre-Yves Chibon f66c8c
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon f66c8c
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon 88d13c
                csrf_token = self.get_csrf(output=output)
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon f66c8c
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
    Pierre-Yves Chibon 73d120
            repopath = os.path.join(self.path, "repos", "test.git")
    Pierre-Yves Chibon f66c8c
            tests.add_content_git_repo(repopath)
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon f66c8c
            repo = pygit2.Repository(repopath)
    Pierre-Yves Chibon 73d120
            first_commit = repo.revparse_single("HEAD")
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon 73d120
            text = "Cf commit %s" % first_commit.oid.hex
    Pierre-Yves Chibon 73d120
            exp = (
    Pierre-Yves Chibon 73d120
                '

    Cf commit {1}'

    Pierre-Yves Chibon 73d120
                "

    ".format(first_commit.oid.hex, first_commit.oid.hex[:7])
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon b130e5
            with self.app.application.app_context():
    Pierre-Yves Chibon 73d120
                data = {"content": text, "csrf_token": csrf_token}
    Pierre-Yves Chibon 73d120
                output = self.app.post("/markdown/?repo=test", data=data)
    Pierre-Yves Chibon f66c8c
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                self.assertEqual(exp, output.get_data(as_text=True))
    Pierre-Yves Chibon f66c8c
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon c87f24
        def test_remove_user_email(self, ast):
    Pierre-Yves Chibon c87f24
            """ Test the remove_user_email endpoint. """
    Pierre-Yves Chibon c87f24
            ast.return_value = False
    Pierre-Yves Chibon c87f24
            self.test_new_project()
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
            user = tests.FakeUser()
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/drop")
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    ", output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
            user.username = "foo"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/")
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 88d13c
                csrf_token = self.get_csrf(output=output)
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
                data = {"email": "foo@pingou.com"}
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/drop", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon c87f24
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "You must always have at " "least one email", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
            user.username = "pingou"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/")
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 88d13c
                csrf_token = self.get_csrf(output=output)
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
                data = {"email": "foo@pingou.com"}
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/drop", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foobar@pingou.com"}
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/drop", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon c87f24
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "You do not have the "
    Pierre-Yves Chibon 73d120
                    "email: foobar@pingou.com, nothing to remove",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foo@pingou.com"}
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/drop", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 0)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("bar@pingou.com"), 3)
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/drop", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 0)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("bar@pingou.com"), 3)
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon c87f24
                ast.return_value = True
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/drop", data=data)
    Pierre-Yves Chibon c87f24
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon c87f24
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email")
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon 2c7572
        def test_add_api_user_email(self, ast, send_email):
    Pierre-Yves Chibon 2c7572
            """ Test the add_api_user_email endpoint. """
    Pierre-Yves Chibon ca16bb
            send_email.return_value = True
    Pierre-Yves Chibon ca16bb
            ast.return_value = False
    Pierre-Yves Chibon ca16bb
            self.test_new_project()
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
            user = tests.FakeUser()
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/add")
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    ", output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon 73d120
            user.username = "foo"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/add")
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Aurélien Bompard 626417
                self.assertIn("Add new email", output_text)
    Pierre-Yves Chibon 3e9b1d
                if self.get_wtforms_version() >= (2, 2):
    Pierre-Yves Chibon 3e9b1d
                    self.assertIn(
    Pierre-Yves Chibon 3e9b1d
                        '
    Pierre-Yves Chibon 73d120
                        'name="email" required type="text" value="">',
    Pierre-Yves Chibon 73d120
                        output_text,
    Pierre-Yves Chibon 73d120
                    )
    Pierre-Yves Chibon 3e9b1d
                else:
    Pierre-Yves Chibon 3e9b1d
                    self.assertIn(
    Pierre-Yves Chibon 3e9b1d
                        '
    Pierre-Yves Chibon 73d120
                        'name="email" type="text" value="">',
    Pierre-Yves Chibon 73d120
                        output_text,
    Pierre-Yves Chibon 73d120
                    )
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon 73d120
            user.username = "pingou"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/add")
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Aurélien Bompard 626417
                self.assertIn("Add new email", output_text)
    Pierre-Yves Chibon 3e9b1d
                if self.get_wtforms_version() >= (2, 2):
    Pierre-Yves Chibon 3e9b1d
                    self.assertIn(
    Pierre-Yves Chibon 3e9b1d
                        '
    Pierre-Yves Chibon 73d120
                        'name="email" required type="text" value="">',
    Pierre-Yves Chibon 73d120
                        output_text,
    Pierre-Yves Chibon 73d120
                    )
    Pierre-Yves Chibon 3e9b1d
                else:
    Pierre-Yves Chibon 3e9b1d
                    self.assertIn(
    Pierre-Yves Chibon 3e9b1d
                        '
    Pierre-Yves Chibon 73d120
                        'name="email" type="text" value="">',
    Pierre-Yves Chibon 73d120
                        output_text,
    Pierre-Yves Chibon 73d120
                    )
    Pierre-Yves Chibon ca16bb
    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 ca16bb
    Pierre-Yves Chibon 73d120
                data = {"email": "foo2@pingou.com"}
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/add", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Aurélien Bompard 626417
                self.assertIn("Add new email", output_text)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo2@pingou.com"), 1)
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                # New email
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foðbar@pingou.com"}
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/add", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon ca16bb
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertIn("Email pending validation", output_text)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("bar@pingou.com"), 5)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foðbar@pingou.com"), 2)
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon 15ef6d
                # Email already pending
    Pierre-Yves Chibon 15ef6d
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/add", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 15ef6d
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 15ef6d
                self.assertIn(
    Pierre-Yves Chibon 15ef6d
                    '
    \n '
    Pierre-Yves Chibon 73d120
                    "Add new email",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 15ef6d
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "This email is already " "pending confirmation", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 15ef6d
    Pierre-Yves Chibon ca16bb
                # User already has this email
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foo@pingou.com"}
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/add", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Aurélien Bompard 626417
                self.assertTrue("Add new email" in output_text)
    Pierre-Yves Chibon 8558c8
                self.assertTrue(
    Pierre-Yves Chibon 73d120
                    "Invalid value, can't be any of: bar@pingou.com, "
    Pierre-Yves Chibon 73d120
                    "foo@pingou.com. " in output_text
    Pierre-Yves Chibon 73d120
                    or "Invalid value, can't be any of: foo@pingou.com, "
    Pierre-Yves Chibon 73d120
                    "bar@pingou.com. " in output_text
    Pierre-Yves Chibon 8558c8
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 6)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("bar@pingou.com"), 5)
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foðbar@pingou.com"), 0)
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                # Email registered by someone else
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foo@bar.com"}
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/add", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Aurélien Bompard 626417
                self.assertTrue("Add new email" in output_text)
    Pierre-Yves Chibon ca16bb
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "Invalid value, can't be any of: foo@bar.com. ",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon ca16bb
                ast.return_value = True
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/add", data=data)
    Pierre-Yves Chibon ca16bb
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon ca16bb
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email")
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon 5cae35
        def test_set_default_email(self, ast, send_email):
    Pierre-Yves Chibon 5cae35
            """ Test the set_default_email endpoint. """
    Pierre-Yves Chibon 5cae35
            send_email.return_value = True
    Pierre-Yves Chibon 5cae35
            ast.return_value = False
    Pierre-Yves Chibon 5cae35
            self.test_new_project()
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
            user = tests.FakeUser()
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/default")
    Pierre-Yves Chibon 5cae35
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertTrue(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    "
    Pierre-Yves Chibon 73d120
                    in output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 73d120
            user.username = "pingou"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/")
    Pierre-Yves Chibon 5cae35
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 88d13c
                csrf_token = self.get_csrf(output=output)
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 73d120
                data = {"email": "foo@pingou.com"}
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/default", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
                # Set invalid default email
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foobar@pingou.com"}
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/default", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 5cae35
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "You do not have the "
    Pierre-Yves Chibon 73d120
                    "email: foobar@pingou.com, nothing to set",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
                # Set default email
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foo@pingou.com"}
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/default", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 64f5f4
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 5cae35
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "Default email set to: " "foo@pingou.com", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 5cae35
                ast.return_value = True
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/default", data=data)
    Pierre-Yves Chibon 5cae35
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 5cae35
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email")
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon 496605
        def test_reconfirm_email(self, ast, send_email):
    Pierre-Yves Chibon 496605
            """ Test the reconfirm_email endpoint. """
    Pierre-Yves Chibon 496605
            send_email.return_value = True
    Pierre-Yves Chibon 496605
            ast.return_value = False
    Pierre-Yves Chibon 496605
            self.test_new_project()
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
            # Add a pending email to pingou
    Pierre-Yves Chibon 73d120
            userobj = pagure.lib.query.search_user(self.session, username="pingou")
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
            self.assertEqual(len(userobj.emails), 2)
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
            email_pend = pagure.lib.model.UserEmailPending(
    Pierre-Yves Chibon 73d120
                user_id=userobj.id, email="foo@fp.o", token="abcdef"
    Pierre-Yves Chibon 496605
            )
    Pierre-Yves Chibon 496605
            self.session.add(email_pend)
    Pierre-Yves Chibon 496605
            self.session.commit()
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
            user = tests.FakeUser()
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/resend")
    Pierre-Yves Chibon 496605
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertTrue(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    "
    Pierre-Yves Chibon 73d120
                    in output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 73d120
            user.username = "pingou"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/")
    Pierre-Yves Chibon 496605
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 496605
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 88d13c
                csrf_token = self.get_csrf(output=output)
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 73d120
                data = {"email": "foo@pingou.com"}
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/resend", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 496605
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 496605
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
                # Set invalid default email
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foobar@pingou.com"}
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/resend", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 496605
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 496605
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 496605
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "This email address has " "already been confirmed", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
                # Validate a non-validated email
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token, "email": "foo@fp.o"}
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/email/resend", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 496605
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 496605
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertEqual(output_text.count("foo@pingou.com"), 4)
    Pierre-Yves Chibon 73d120
                self.assertIn("Confirmation email re-sent", output_text)
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 496605
                ast.return_value = True
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/email/resend", data=data)
    Pierre-Yves Chibon 496605
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 496605
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon 2497e3
        def test_confirm_email(self, ast):
    Pierre-Yves Chibon 2497e3
            """ Test the confirm_email endpoint. """
    Pierre-Yves Chibon 73d120
            output = self.app.get("/settings/email/confirm/foobar")
    Pierre-Yves Chibon 2497e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
            ast.return_value = False
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
            # Add a pending email to pingou
    Pierre-Yves Chibon 73d120
            userobj = pagure.lib.query.search_user(self.session, username="pingou")
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
            self.assertEqual(len(userobj.emails), 2)
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
            email_pend = pagure.lib.model.UserEmailPending(
    Pierre-Yves Chibon 73d120
                user_id=userobj.id, email="foo@fp.o", token="abcdef"
    Pierre-Yves Chibon 2497e3
            )
    Pierre-Yves Chibon 2497e3
            self.session.add(email_pend)
    Pierre-Yves Chibon 2497e3
            self.session.commit()
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
            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 2497e3
                # Wrong token
    Pierre-Yves Chibon 2497e3
                output = self.app.get(
    Pierre-Yves Chibon 73d120
                    "/settings/email/confirm/foobar", follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 2497e3
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 2497e3
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertIn("No email associated with this token.", output_text)
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
                # Confirm email
    Pierre-Yves Chibon 2497e3
                output = self.app.get(
    Pierre-Yves Chibon 73d120
                    "/settings/email/confirm/abcdef", follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 2497e3
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 2497e3
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>pingou's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertIn("Email validated", output_text)
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 73d120
            userobj = pagure.lib.query.search_user(self.session, username="pingou")
    Pierre-Yves Chibon 2497e3
            self.assertEqual(len(userobj.emails), 3)
    Pierre-Yves Chibon 2497e3
    Pierre-Yves Chibon 2497e3
            ast.return_value = True
    Pierre-Yves Chibon 73d120
            output = self.app.get("/settings/email/confirm/foobar")
    Pierre-Yves Chibon 2497e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 2497e3
    Jeremy Cline babe37
        def test_view_my_requests_no_user(self):
    Pierre-Yves Chibon ce6f30
            """Test the view_user_requests endpoint."""
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/somenonexistentuser/requests")
    Jeremy Cline babe37
            self.assertEqual(output.status_code, 404)
    Jeremy Cline babe37
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
    Jeremy Cline babe37
        def test_view_my_requests(self):
    Pierre-Yves Chibon ce6f30
            """Test the view_user_requests endpoint. """
    Pierre-Yves Chibon ce6f30
            # Create the PR
    Pierre-Yves Chibon ce6f30
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Pierre-Yves Chibon 930073
            req = pagure.lib.query.new_pull_request(
    Pierre-Yves Chibon ce6f30
                session=self.session,
    Pierre-Yves Chibon ce6f30
                repo_from=repo,
    Pierre-Yves Chibon 73d120
                branch_from="dev",
    Pierre-Yves Chibon ce6f30
                repo_to=repo,
    Pierre-Yves Chibon 73d120
                branch_to="master",
    Pierre-Yves Chibon 73d120
                title="test pull-request #1",
    Pierre-Yves Chibon 73d120
                user="pingou",
    Pierre-Yves Chibon ce6f30
            )
    Pierre-Yves Chibon ce6f30
            self.session.commit()
    Pierre-Yves Chibon ce6f30
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon 73d120
            self.assertEqual(req.title, "test pull-request #1")
    Pierre-Yves Chibon ce6f30
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/requests")
    Jeremy Cline 6492c1
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("test pull-request #1", output_text)
    Pierre-Yves Chibon 73d120
            self.assertEqual(output_text.count('pr-status pr-status-open"'), 1)
    Jeremy Cline babe37
    Pierre-Yves Chibon ce6f30
            # Add a PR in a fork
    Pierre-Yves Chibon ce6f30
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon ce6f30
                user_id=1,  # pingou
    Pierre-Yves Chibon 73d120
                name="test_fork",
    Pierre-Yves Chibon 73d120
                description="test project #1",
    Pierre-Yves Chibon ce6f30
                is_fork=True,
    Pierre-Yves Chibon ce6f30
                parent_id=1,
    Pierre-Yves Chibon 73d120
                hook_token="aaabbbttt",
    Pierre-Yves Chibon ce6f30
            )
    Pierre-Yves Chibon ce6f30
            self.session.add(item)
    Pierre-Yves Chibon 930073
            repo = pagure.lib.query._get_project(
    Pierre-Yves Chibon 73d120
                self.session, "test_fork", user="pingou"
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon ce6f30
    Pierre-Yves Chibon 930073
            req = pagure.lib.query.new_pull_request(
    Pierre-Yves Chibon ce6f30
                session=self.session,
    Pierre-Yves Chibon ce6f30
                repo_from=repo,
    Pierre-Yves Chibon 73d120
                branch_from="dev",
    Pierre-Yves Chibon ce6f30
                repo_to=repo,
    Pierre-Yves Chibon 73d120
                branch_to="master",
    Pierre-Yves Chibon 73d120
                title="tést pull-request #2",
    Pierre-Yves Chibon 73d120
                user="pingou",
    Pierre-Yves Chibon ce6f30
            )
    Pierre-Yves Chibon ce6f30
            self.session.commit()
    Pierre-Yves Chibon ce6f30
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon 73d120
            self.assertEqual(req.title, "tést pull-request #2")
    Jeremy Cline babe37
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/requests")
    Pierre-Yves Chibon ce6f30
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("test pull-request #1", output_text)
    Pierre-Yves Chibon 73d120
            self.assertIn("tést pull-request #2", output_text)
    Pierre-Yves Chibon 73d120
            self.assertEqual(output_text.count('pr-status pr-status-open"'), 2)
    Jeremy Cline babe37
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
    Pierre-Yves Chibon a26413
        def test_view_my_requests_pr_in_another_project(self):
    Pierre-Yves Chibon a26413
            """Test the view_user_requests endpoint when the user opened a PR
    Pierre-Yves Chibon a26413
            in another project. """
    Pierre-Yves Chibon a26413
            # Pingou creates the PR on test
    Pierre-Yves Chibon a26413
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Pierre-Yves Chibon 930073
            req = pagure.lib.query.new_pull_request(
    Pierre-Yves Chibon a26413
                session=self.session,
    Pierre-Yves Chibon a26413
                repo_from=repo,
    Pierre-Yves Chibon 73d120
                branch_from="dev",
    Pierre-Yves Chibon a26413
                repo_to=repo,
    Pierre-Yves Chibon 73d120
                branch_to="master",
    Pierre-Yves Chibon 73d120
                title="test pull-request #1",
    Pierre-Yves Chibon 73d120
                user="pingou",
    Pierre-Yves Chibon a26413
            )
    Pierre-Yves Chibon a26413
            self.session.commit()
    Pierre-Yves Chibon a26413
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon 73d120
            self.assertEqual(req.title, "test pull-request #1")
    Pierre-Yves Chibon a26413
    Pierre-Yves Chibon a26413
            # foo creates the PR on test
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Pierre-Yves Chibon 930073
            req = pagure.lib.query.new_pull_request(
    Pierre-Yves Chibon a26413
                session=self.session,
    Pierre-Yves Chibon a26413
                repo_from=repo,
    Pierre-Yves Chibon 73d120
                branch_from="dev",
    Pierre-Yves Chibon a26413
                repo_to=repo,
    Pierre-Yves Chibon 73d120
                branch_to="master",
    Pierre-Yves Chibon 73d120
                title="test pull-request #2",
    Pierre-Yves Chibon 73d120
                user="foo",
    Pierre-Yves Chibon a26413
            )
    Pierre-Yves Chibon a26413
            self.session.commit()
    Pierre-Yves Chibon a26413
            self.assertEqual(req.id, 2)
    Pierre-Yves Chibon 73d120
            self.assertEqual(req.title, "test pull-request #2")
    Pierre-Yves Chibon a26413
    Pierre-Yves Chibon a26413
            # Check pingou's PR list
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/requests")
    Pierre-Yves Chibon a26413
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("test pull-request #1", output_text)
    Pierre-Yves Chibon 73d120
            self.assertIn("test pull-request #2", output_text)
    Pierre-Yves Chibon 73d120
            self.assertEqual(output_text.count('pr-status pr-status-open"'), 2)
    Pierre-Yves Chibon a26413
    Pierre-Yves Chibon a26413
            # Check foo's PR list
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/foo/requests")
    Pierre-Yves Chibon a26413
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertNotIn("test pull-request #1", output_text)
    Pierre-Yves Chibon 73d120
            self.assertIn("test pull-request #2", output_text)
    Pierre-Yves Chibon 73d120
            self.assertEqual(output_text.count('pr-status pr-status-open"'), 1)
    Pierre-Yves Chibon a26413
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
    Pierre-Yves Chibon 16db83
        def test_view_my_requests_against_another_project(self):
    Pierre-Yves Chibon 16db83
            """Test the view_user_requests endpoint when there is a PR opened
    Pierre-Yves Chibon 16db83
            by me against a project I do not have rights on. """
    Pierre-Yves Chibon 16db83
            # Create the PR
    Pierre-Yves Chibon 16db83
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Pierre-Yves Chibon 930073
            req = pagure.lib.query.new_pull_request(
    Pierre-Yves Chibon 16db83
                session=self.session,
    Pierre-Yves Chibon 16db83
                repo_from=repo,
    Pierre-Yves Chibon 73d120
                branch_from="dev",
    Pierre-Yves Chibon 16db83
                repo_to=repo,
    Pierre-Yves Chibon 73d120
                branch_to="master",
    Pierre-Yves Chibon 73d120
                title="test pull-request #1",
    Pierre-Yves Chibon 73d120
                user="foo",
    Pierre-Yves Chibon 16db83
            )
    Pierre-Yves Chibon 16db83
            self.session.commit()
    Pierre-Yves Chibon 16db83
            self.assertEqual(req.id, 1)
    Pierre-Yves Chibon 73d120
            self.assertEqual(req.title, "test pull-request #1")
    Pierre-Yves Chibon 16db83
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/foo/requests")
    Pierre-Yves Chibon 16db83
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("test pull-request #1", output_text)
    Pierre-Yves Chibon 73d120
            self.assertEqual(output_text.count('pr-status pr-status-open"'), 1)
    Pierre-Yves Chibon 16db83
    Jeremy Cline babe37
        def test_view_my_issues_no_user(self):
    Pierre-Yves Chibon ce6f30
            """Test the view_user_issues endpoint with a missing user."""
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/somenonexistentuser/issues")
    Jeremy Cline babe37
            self.assertEqual(output.status_code, 404)
    Jeremy Cline babe37
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
    Jeremy Cline babe37
        def test_view_my_issues(self):
    Pierre-Yves Chibon ce6f30
            """Test the view_user_issues endpoint when the user exists."""
    Pierre-Yves Chibon ce6f30
            # Create the issue
    Pierre-Yves Chibon ce6f30
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Pierre-Yves Chibon 930073
            msg = pagure.lib.query.new_issue(
    Pierre-Yves Chibon ce6f30
                session=self.session,
    Pierre-Yves Chibon ce6f30
                repo=repo,
    Pierre-Yves Chibon 73d120
                title="Test issue #1",
    Pierre-Yves Chibon 73d120
                content="We should work on this for the second time",
    Pierre-Yves Chibon 73d120
                user="pingou",
    Pierre-Yves Chibon 73d120
                status="Open",
    Pierre-Yves Chibon ce6f30
            )
    Pierre-Yves Chibon ce6f30
            self.session.commit()
    Pierre-Yves Chibon 73d120
            self.assertEqual(msg.title, "Test issue #1")
    Pierre-Yves Chibon ce6f30
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/issues")
    Pierre-Yves Chibon ce6f30
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("Test issue #1", output_text)
    Pierre-Yves Chibon ce6f30
            self.assertEqual(
    Pierre-Yves Chibon 73d120
                output_text.count("issue-status issue-status-open"), 1
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon ce6f30
    Pierre-Yves Chibon ce6f30
            # Add an issue in a fork
    Pierre-Yves Chibon ce6f30
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon ce6f30
                user_id=2,  # foo
    Pierre-Yves Chibon 73d120
                name="test_fork",
    Pierre-Yves Chibon 73d120
                description="test project #1",
    Pierre-Yves Chibon ce6f30
                is_fork=True,
    Pierre-Yves Chibon ce6f30
                parent_id=1,
    Pierre-Yves Chibon 73d120
                hook_token="aaabbbttt",
    Pierre-Yves Chibon ce6f30
            )
    Pierre-Yves Chibon ce6f30
            self.session.add(item)
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(
    Pierre-Yves Chibon 73d120
                self.session, "test_fork", user="foo"
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon ce6f30
    Pierre-Yves Chibon 930073
            msg = pagure.lib.query.new_issue(
    Pierre-Yves Chibon ce6f30
                session=self.session,
    Pierre-Yves Chibon ce6f30
                repo=repo,
    Pierre-Yves Chibon 73d120
                title="Test issue #2",
    Pierre-Yves Chibon 73d120
                content="We should work on this for the second time",
    Pierre-Yves Chibon 73d120
                user="pingou",
    Pierre-Yves Chibon 73d120
                status="Open",
    Pierre-Yves Chibon ce6f30
            )
    Pierre-Yves Chibon ce6f30
            self.session.commit()
    Pierre-Yves Chibon 73d120
            self.assertEqual(msg.title, "Test issue #2")
    Pierre-Yves Chibon ce6f30
    Mark Reynolds 300f0f
            # Test the assigned issue table.  Create issue then set the assignee
    Pierre-Yves Chibon 930073
            msg = pagure.lib.query.new_issue(
    Mark Reynolds 300f0f
                session=self.session,
    Mark Reynolds 300f0f
                repo=repo,
    Pierre-Yves Chibon 73d120
                title="Test issue #3",
    Pierre-Yves Chibon 73d120
                content="This issue created by foo, but assigned to pingou",
    Pierre-Yves Chibon 73d120
                user="foo",
    Pierre-Yves Chibon 73d120
                status="Open",
    Mark Reynolds 300f0f
            )
    Mark Reynolds 300f0f
            self.session.commit()
    Pierre-Yves Chibon 73d120
            self.assertEqual(msg.title, "Test issue #3")
    Mark Reynolds 300f0f
    Pierre-Yves Chibon 930073
            msg = pagure.lib.query.add_issue_assignee(
    Pierre-Yves Chibon 73d120
                session=self.session, issue=msg, assignee="pingou", user="foo"
    Patrick Uiterwijk 3f97f6
            )
    Mark Reynolds 300f0f
            self.session.commit()
    Pierre-Yves Chibon 73d120
            self.assertEqual(msg, "Issue assigned to pingou")
    Pierre-Yves Chibon ce6f30
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/issues")
    Jeremy Cline 6492c1
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("Test issue #1", output_text)
    Pierre-Yves Chibon 73d120
            self.assertIn("Test issue #2", output_text)
    Pierre-Yves Chibon 73d120
            self.assertIn("Test issue #3", output_text)
    Pierre-Yves Chibon ce6f30
            self.assertEqual(
    Pierre-Yves Chibon 73d120
                output_text.count("issue-status issue-status-open"), 3
    Pierre-Yves Chibon 73d120
            )
    Jeremy Cline babe37
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.git.update_git", MagicMock(return_value=True))
    Pierre-Yves Chibon 73d120
        @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
    Vivek Anand 09369e
        def test_view_my_issues_disabled(self):
    Vivek Anand 09369e
            """Test the view_user_issues endpoint when the project disabled issue
    Vivek Anand 09369e
            tracking."""
    Vivek Anand 09369e
            # Create the issue
    Vivek Anand 09369e
            tests.create_projects(self.session)
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Pierre-Yves Chibon 930073
            msg = pagure.lib.query.new_issue(
    Vivek Anand 09369e
                session=self.session,
    Vivek Anand 09369e
                repo=repo,
    Pierre-Yves Chibon 73d120
                title="Test issue #1",
    Pierre-Yves Chibon 73d120
                content="We should work on this for the second time",
    Pierre-Yves Chibon 73d120
                user="pingou",
    Pierre-Yves Chibon 73d120
                status="Open",
    Vivek Anand 09369e
            )
    Vivek Anand 09369e
            self.session.commit()
    Pierre-Yves Chibon 73d120
            self.assertEqual(msg.title, "Test issue #1")
    Vivek Anand 09369e
    Vivek Anand 09369e
            # Before
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/issues")
    Vivek Anand 09369e
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("Test issue #1", output_text)
    Vivek Anand 09369e
            self.assertEqual(
    Pierre-Yves Chibon 73d120
                output_text.count("issue-status issue-status-open"), 1
    Pierre-Yves Chibon 73d120
            )
    Vivek Anand 09369e
    Vivek Anand 09369e
            # Disable issue tracking
    Pierre-Yves Chibon 73d120
            repo = pagure.lib.query._get_project(self.session, "test")
    Vivek Anand 09369e
            settings = repo.settings
    Pierre-Yves Chibon 73d120
            settings["issue_tracker"] = False
    Vivek Anand 09369e
            repo.settings = settings
    Vivek Anand 09369e
            self.session.add(repo)
    Vivek Anand 09369e
            self.session.commit()
    Vivek Anand 09369e
    Vivek Anand 09369e
            # After
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/issues")
    Vivek Anand 09369e
            self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertNotIn("Test issue #1", output_text)
    Vivek Anand 09369e
            self.assertEqual(
    Pierre-Yves Chibon 73d120
                output_text.count("issue-status issue-status-open"), 0
    Pierre-Yves Chibon 73d120
            )
    Vivek Anand 09369e
    Vivek Anand 611221
        def test_view_my_issues_tickets_turned_off(self):
    Vivek Anand 611221
            """Test the view_user_issues endpoint when the user exists and
    Vivek Anand 611221
            and ENABLE_TICKETS is False """
    Vivek Anand 611221
    Vivek Anand 611221
            # Turn off the tickets instance wide
    Pierre-Yves Chibon 73d120
            pagure.config.config["ENABLE_TICKETS"] = False
    Vivek Anand 611221
    Pierre-Yves Chibon 73d120
            output = self.app.get("/user/pingou/issues")
    Vivek Anand 611221
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
            pagure.config.config["ENABLE_TICKETS"] = True
    Vivek Anand 611221
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon 170fc9
        def test_add_user_token(self, ast):
    Pierre-Yves Chibon 170fc9
            """ Test the add_user_token endpoint. """
    Pierre-Yves Chibon 170fc9
            ast.return_value = False
    Pierre-Yves Chibon 170fc9
            self.test_new_project()
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
            user = tests.FakeUser()
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/token/new/")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    ", output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 73d120
            user.username = "foo"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/token/new")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 170fc9
                    '
    \n '
    Pierre-Yves Chibon 73d120
                    "Create a new token\n",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 170fc9
                    '<input name="acls" type="checkbox" value="create_project">',
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    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 170fc9
    Pierre-Yves Chibon 73d120
                data = {"acls": ["create_project", "fork_project"]}
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # missing CSRF
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/token/new", data=data)
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                self.assertIn("<title>Create token - Pagure</title>", output_text)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 170fc9
                    '
    \n '
    Pierre-Yves Chibon 73d120
                    "Create a new token\n",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 170fc9
                    '<input name="acls" type="checkbox" value="create_project">',
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 73d120
                data = {"acls": ["new_project"], "csrf_token": csrf_token}
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # Invalid ACLs
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/token/new", data=data)
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                self.assertIn("<title>Create token - Pagure</title>", output_text)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 170fc9
                    '
    \n '
    Pierre-Yves Chibon 73d120
                    "Create a new token\n",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 170fc9
                    '<input name="acls" type="checkbox" value="create_project">',
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                data = {
    Pierre-Yves Chibon 73d120
                    "acls": ["create_project", "fork_project"],
    Pierre-Yves Chibon 73d120
                    "csrf_token": csrf_token,
    Pierre-Yves Chibon 170fc9
                }
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # All good
    Pierre-Yves Chibon 170fc9
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/token/new", data=data, follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertIn("Token created", output_text)
    Pierre-Yves Chibon 170fc9
                self.assertEqual(
    Aurélien Bompard 626417
                    output_text.count(
    Pierre-Yves Chibon 73d120
                        '<small class="font-weight-bold text-success input-group-text">Active until'</small>
    Pierre-Yves Chibon 73d120
                    ),
    Pierre-Yves Chibon 73d120
                    1,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                ast.return_value = True
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/token/new")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 73d120
        @patch("pagure.ui.app.admin_session_timedout")
    Pierre-Yves Chibon 170fc9
        def test_revoke_api_user_token(self, ast):
    Pierre-Yves Chibon 170fc9
            """ Test the revoke_api_user_token endpoint. """
    Pierre-Yves Chibon 170fc9
            ast.return_value = False
    Pierre-Yves Chibon 170fc9
            self.test_new_project()
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
            user = tests.FakeUser()
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 170fc9
                # Token doesn't exist
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/token/revoke/foobar")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertTrue(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    "
    Pierre-Yves Chibon 73d120
                    in output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # Create the foobar API token but associated w/ the user 'foo'
    Pierre-Yves Chibon 170fc9
                item = pagure.lib.model.Token(
    Pierre-Yves Chibon 73d120
                    id="foobar",
    Pierre-Yves Chibon 170fc9
                    user_id=2,  # foo
    Pierre-Yves Chibon 73d120
                    expiration=datetime.datetime.utcnow()
    Pierre-Yves Chibon 73d120
                    + datetime.timedelta(days=30),
    Pierre-Yves Chibon 170fc9
                )
    Pierre-Yves Chibon 170fc9
                self.session.add(item)
    Pierre-Yves Chibon 170fc9
                self.session.commit()
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # Token not associated w/ this user
    Pierre-Yves Chibon 73d120
                output = self.app.post("/settings/token/revoke/foobar")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 73d120
                self.assertTrue(
    Pierre-Yves Chibon 73d120
                    "

    Page not found (404)

    "
    Pierre-Yves Chibon 73d120
                    in output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 73d120
            user.username = "foo"
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 170fc9
                # Missing CSRF token
    Pierre-Yves Chibon 170fc9
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/token/revoke/foobar", follow_redirects=True
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(
    Aurélien Bompard 626417
                    output_text.count(
    Pierre-Yves Chibon 73d120
                        '<small class="font-weight-bold text-success input-group-text">Active until'</small>
    Pierre-Yves Chibon 73d120
                    ),
    Pierre-Yves Chibon 73d120
                    1,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    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 170fc9
    Pierre-Yves Chibon 73d120
                data = {"csrf_token": csrf_token}
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # All good - token is deleted
    Pierre-Yves Chibon 170fc9
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/token/revoke/foobar",
    Pierre-Yves Chibon 73d120
                    data=data,
    Pierre-Yves Chibon 73d120
                    follow_redirects=True,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(
    Aurélien Bompard 626417
                    output_text.count(
    Pierre-Yves Chibon 73d120
                        '<small class="font-weight-bold text-success input-group-text">Active until'</small>
    Pierre-Yves Chibon 73d120
                    ),
    Pierre-Yves Chibon 73d120
                    0,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 73d120
                user = pagure.lib.query.get_user(self.session, key="foo")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(len(user.tokens), 1)
    Pierre-Yves Chibon 170fc9
                expiration_dt = user.tokens[0].expiration
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # Token was already deleted - no changes
    Pierre-Yves Chibon 170fc9
                output = self.app.post(
    Pierre-Yves Chibon 73d120
                    "/settings/token/revoke/foobar",
    Pierre-Yves Chibon 73d120
                    data=data,
    Pierre-Yves Chibon 73d120
                    follow_redirects=True,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 170fc9
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>foo's settings - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
                self.assertEqual(
    Aurélien Bompard 626417
                    output_text.count(
    Pierre-Yves Chibon 73d120
                        '<small class="font-weight-bold text-success input-group-text">Active until'</small>
    Pierre-Yves Chibon 73d120
                    ),
    Pierre-Yves Chibon 73d120
                    0,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                # Ensure the expiration date did not change
    Pierre-Yves Chibon 73d120
                user = pagure.lib.query.get_user(self.session, key="foo")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(len(user.tokens), 1)
    Pierre-Yves Chibon 73d120
                self.assertEqual(expiration_dt, user.tokens[0].expiration)
    Pierre-Yves Chibon 170fc9
    Pierre-Yves Chibon 170fc9
                ast.return_value = True
    Pierre-Yves Chibon 73d120
                output = self.app.get("/settings/token/new")
    Pierre-Yves Chibon 170fc9
                self.assertEqual(output.status_code, 302)
    Jeremy Cline babe37
    Pierre-Yves Chibon 73d120
        @patch.dict("pagure.config.config", {"PAGURE_AUTH": "fas"})
    Pierre-Yves Chibon 73d120
        @patch.dict("pagure.utils.pagure_config", {"PAGURE_AUTH": "fas"})
    Pierre-Yves Chibon 08da0d
        def test_create_project_auth_FAS_no_FPCA(self):
    Pierre-Yves Chibon 08da0d
            """ Test creating a project when auth is FAS and the user did not
    Pierre-Yves Chibon 08da0d
            sign the FPCA. """
    Pierre-Yves Chibon 08da0d
    Pierre-Yves Chibon 73d120
            user = tests.FakeUser(username="foo", cla_done=False)
    Pierre-Yves Chibon 08da0d
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 73d120
                output = self.app.get("/new/", follow_redirects=True)
    Pierre-Yves Chibon 08da0d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 08da0d
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
                self.assertIn("<title>Home - Pagure</title>", output_text)
    Pierre-Yves Chibon 08da0d
                self.assertIn(
    Pierre-Yves Chibon 08da0d
                    ' You must 
    Pierre-Yves Chibon 08da0d
                    '">sign the FPCA (Fedora Project Contributor Agreement) '
    Pierre-Yves Chibon 73d120
                    "to use pagure",
    Pierre-Yves Chibon 73d120
                    output_text,
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 08da0d
    Pierre-Yves Chibon 5cdb69
    Pierre-Yves Chibon 7c6237
    class PagureFlaskAppAboutPagetests(tests.Modeltests):
    Pierre-Yves Chibon 7c6237
        """ Unit-tests for the about page. """
    Pierre-Yves Chibon 7c6237
    Pierre-Yves Chibon 7c6237
        def test_about_page(self):
    Pierre-Yves Chibon 7c6237
            """ Test the about page when an admin_email is set. """
    Pierre-Yves Chibon 73d120
            output = self.app.get("/about/")
    Pierre-Yves Chibon 7c6237
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 7c6237
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("<title>About - Pagure</title>", output_text)
    Pierre-Yves Chibon 7c6237
            self.assertIn(
    Pierre-Yves Chibon 73d120
                "by emailing:\n      "
    Pierre-Yves Chibon 73d120
                '',
    Pierre-Yves Chibon 73d120
                output_text,
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 7c6237
            self.assertIn(
    Pierre-Yves Chibon 7c6237
                'href="https://pagure.io/pagure/issues">open a ticket',
    Pierre-Yves Chibon 73d120
                output_text,
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 7c6237
    Pierre-Yves Chibon 73d120
        @patch.dict("pagure.config.config", {"ADMIN_EMAIL": "admin@fp.o"})
    Pierre-Yves Chibon 7c6237
        def test_about_page_admin_email(self):
    Pierre-Yves Chibon 7c6237
            """ Test the about page when an admin_email is set. """
    Pierre-Yves Chibon 73d120
            output = self.app.get("/about/")
    Pierre-Yves Chibon 7c6237
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 7c6237
            output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 73d120
            self.assertIn("<title>About - Pagure</title>", output_text)
    Pierre-Yves Chibon 7c6237
            self.assertIn(
    Pierre-Yves Chibon 73d120
                'by emailing:\n      ', output_text
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 7c6237
            self.assertIn(
    Pierre-Yves Chibon 7c6237
                'href="https://pagure.io/pagure/issues">open a ticket',
    Pierre-Yves Chibon 73d120
                output_text,
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 7c6237
    Pierre-Yves Chibon 7c6237
    Pierre-Yves Chibon 8b2c5c
    class PagureFlaskAppNoDocstests(tests.Modeltests):
    Pierre-Yves Chibon 8b2c5c
        """ Tests for flask app controller of pagure """
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 73d120
        config_values = {"enable_docs": False, "docs_folder": None}
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
        def test_new_project_no_docs_folder(self):
    Pierre-Yves Chibon 8b2c5c
            """ Test the new_project endpoint with DOCS_FOLDER is None. """
    Pierre-Yves Chibon 95e961
            # Before
    Pierre-Yves Chibon 930073
            projects = pagure.lib.query.search_projects(self.session)
    Pierre-Yves Chibon 8b2c5c
            self.assertEqual(len(projects), 0)
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(os.path.join(self.path, "repos", "project#1.git"))
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "tickets", "project#1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "docs", "project#1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "requests", "project#1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
    Pierre-Yves Chibon 73d120
            user = tests.FakeUser(username="foo")
    Pierre-Yves Chibon 8b2c5c
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
                csrf_token = self.get_csrf()
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
                data = {
    Pierre-Yves Chibon 73d120
                    "description": "Project #1",
    Pierre-Yves Chibon 73d120
                    "name": "project-1",
    Pierre-Yves Chibon 73d120
                    "csrf_token": csrf_token,
    Pierre-Yves Chibon 8b2c5c
                }
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 73d120
                output = self.app.post("/new/", data=data, follow_redirects=True)
    Pierre-Yves Chibon 8b2c5c
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 8b2c5c
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    '
    \nProject #1', output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertIn("

    This repo is brand new!

    ", output_text)
    Pierre-Yves Chibon 8b2c5c
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>Overview - project-1 - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
            # After
    Pierre-Yves Chibon 930073
            projects = pagure.lib.query.search_projects(self.session)
    Pierre-Yves Chibon 8b2c5c
            self.assertEqual(len(projects), 1)
    Pierre-Yves Chibon 73d120
            self.assertTrue(
    Pierre-Yves Chibon 73d120
                os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertTrue(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "tickets", "project-1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "docs", "project-1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertTrue(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "requests", "project-1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
    class PagureFlaskAppNoTicketstests(tests.Modeltests):
    Pierre-Yves Chibon 8b2c5c
        """ Tests for flask app controller of pagure """
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 73d120
        config_values = {"enable_tickets": False, "tickets_folder": None}
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
        def test_new_project_no_tickets_folder(self):
    Pierre-Yves Chibon e6f2ec
            """ Test the new_project endpoint with TICKETS_FOLDER is None. """
    Pierre-Yves Chibon 8b2c5c
            # Before
    Pierre-Yves Chibon 930073
            projects = pagure.lib.query.search_projects(self.session)
    Pierre-Yves Chibon 8b2c5c
            self.assertEqual(len(projects), 0)
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(os.path.join(self.path, "repos", "project#1.git"))
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "tickets", "project#1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "docs", "project#1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "requests", "project#1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
    Pierre-Yves Chibon 73d120
            user = tests.FakeUser(username="foo")
    Pierre-Yves Chibon 8b2c5c
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
                csrf_token = self.get_csrf()
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
                data = {
    Pierre-Yves Chibon 73d120
                    "description": "Project #1",
    Pierre-Yves Chibon 73d120
                    "name": "project-1",
    Pierre-Yves Chibon 73d120
                    "csrf_token": csrf_token,
    Pierre-Yves Chibon 8b2c5c
                }
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 73d120
                output = self.app.post("/new/", data=data, follow_redirects=True)
    Pierre-Yves Chibon 8b2c5c
                self.assertEqual(output.status_code, 200)
    Aurélien Bompard 626417
                output_text = output.get_data(as_text=True)
    Pierre-Yves Chibon 8b2c5c
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    '
    \nProject #1', output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
                self.assertIn("

    This repo is brand new!

    ", output_text)
    Pierre-Yves Chibon 8b2c5c
                self.assertIn(
    Pierre-Yves Chibon 73d120
                    "<title>Overview - project-1 - Pagure</title>", output_text
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
            # After
    Pierre-Yves Chibon 930073
            projects = pagure.lib.query.search_projects(self.session)
    Pierre-Yves Chibon 8b2c5c
            self.assertEqual(len(projects), 1)
    Pierre-Yves Chibon 73d120
            self.assertTrue(
    Pierre-Yves Chibon 73d120
                os.path.exists(os.path.join(self.path, "repos", "project-1.git"))
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertFalse(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "tickets", "project-1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertTrue(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "docs", "project-1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 73d120
            self.assertTrue(
    Pierre-Yves Chibon 73d120
                os.path.exists(
    Pierre-Yves Chibon 73d120
                    os.path.join(self.path, "repos", "requests", "project-1.git")
    Pierre-Yves Chibon 73d120
                )
    Pierre-Yves Chibon 73d120
            )
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 8b2c5c
    Pierre-Yves Chibon 73d120
    if __name__ == "__main__":
    Pierre-Yves Chibon 170fc9
        unittest.main(verbosity=2)