Blame tests/test_pagure_flask_ui_app_index.py

Pierre-Yves Chibon 5cdb69
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
"""
Pierre-Yves Chibon 5cdb69
 (c) 2017 - Copyright Red Hat Inc
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
 Authors:
Pierre-Yves Chibon 5cdb69
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
"""
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 5cdb69
import pkg_resources
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
import datetime
Pierre-Yves Chibon 5cdb69
import unittest
Pierre-Yves Chibon 5cdb69
import shutil
Pierre-Yves Chibon 5cdb69
import sys
Pierre-Yves Chibon 5cdb69
import os
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
import six
Pierre-Yves Chibon 5cdb69
import json
Pierre-Yves Chibon 5cdb69
import pygit2
Pierre-Yves Chibon 5cdb69
from mock import patch, MagicMock
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 5cdb69
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
import pagure.lib
Pierre-Yves Chibon 5cdb69
import tests
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
class PagureFlaskAppIndextests(tests.Modeltests):
Pierre-Yves Chibon 5cdb69
    """ Tests for the index page of flask app controller of pagure """
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon b130e5
    @patch.dict('pagure.config.config', {'HTML_TITLE': 'Pagure HTML title set'})
Pierre-Yves Chibon 5cdb69
    def test_index_html_title(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint with a set html title. """
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        output = self.app.get('/')
Pierre-Yves Chibon 5cdb69
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
        self.assertIn(
Pierre-Yves Chibon 5cdb69
            '<title>Home - Pagure HTML title set</title>',
Pierre-Yves Chibon 5cdb69
            output.data)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_logged_out(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint when logged out. """
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        output = self.app.get('/')
Pierre-Yves Chibon 5cdb69
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
        self.assertIn('<title>Home - Pagure</title>', output.data)
Pierre-Yves Chibon 5cdb69
        self.assertIn(
Ryan Lerch eef090
            '

All Projects '

Ryan Lerch eef090
            '0', output.data)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        output = self.app.get('/?page=abc')
Pierre-Yves Chibon 5cdb69
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
        self.assertIn(
Ryan Lerch eef090
            '

All Projects '

Ryan Lerch eef090
            '3', output.data)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_logged_in(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint when logged in. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project with a long description
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?repopage=abc&forkpage=def')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_commit_access_while_admin(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint filter for commit access only when user
Pierre-Yves Chibon 5cdb69
        is an admin. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project just for foo
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            # Before
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=commit')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # Add foo to test with admin level
Pierre-Yves Chibon 5cdb69
            project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 5cdb69
            msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5cdb69
                self.session,
Pierre-Yves Chibon 5cdb69
                project=project,
Pierre-Yves Chibon 5cdb69
                new_user='foo',
Pierre-Yves Chibon 5cdb69
                user='pingou',
Pierre-Yves Chibon 5cdb69
                access='admin')
Pierre-Yves Chibon 5cdb69
            self.session.commit()
Pierre-Yves Chibon 5cdb69
            self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # After
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=commit')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 2',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_commit_access_while_commit(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint filter for commit access only when user
Pierre-Yves Chibon 5cdb69
        is an committer. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project just for foo
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            # Before
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=commit')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # Add foo to test with commit level
Pierre-Yves Chibon 5cdb69
            project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 5cdb69
            msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5cdb69
                self.session,
Pierre-Yves Chibon 5cdb69
                project=project,
Pierre-Yves Chibon 5cdb69
                new_user='foo',
Pierre-Yves Chibon 5cdb69
                user='pingou',
Pierre-Yves Chibon 5cdb69
                access='commit')
Pierre-Yves Chibon 5cdb69
            self.session.commit()
Pierre-Yves Chibon 5cdb69
            self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # After
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=commit')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 2',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_commit_access_while_ticket(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint filter for commit access only when user
Pierre-Yves Chibon 5cdb69
        is has ticket access. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project just for foo
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            # Before
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=ticket')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # Add foo to test with ticket level
Pierre-Yves Chibon 5cdb69
            project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 5cdb69
            msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5cdb69
                self.session,
Pierre-Yves Chibon 5cdb69
                project=project,
Pierre-Yves Chibon 5cdb69
                new_user='foo',
Pierre-Yves Chibon 5cdb69
                user='pingou',
Pierre-Yves Chibon 5cdb69
                access='ticket')
Pierre-Yves Chibon 5cdb69
            self.session.commit()
Pierre-Yves Chibon 5cdb69
            self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # After  -  projects with ticket access aren't shown
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=ticket')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Lubomír Sedlář a25e58
    def test_index_admin_access_while_admin(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint filter for admin access only when user
Pierre-Yves Chibon 5cdb69
        is an admin. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project just for foo
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            # Before
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=admin')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # Add foo to test with commit level
Pierre-Yves Chibon 5cdb69
            project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 5cdb69
            msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5cdb69
                self.session,
Pierre-Yves Chibon 5cdb69
                project=project,
Pierre-Yves Chibon 5cdb69
                new_user='foo',
Pierre-Yves Chibon 5cdb69
                user='pingou',
Pierre-Yves Chibon 5cdb69
                access='admin')
Pierre-Yves Chibon 5cdb69
            self.session.commit()
Pierre-Yves Chibon 5cdb69
            self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # After
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=admin')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 2',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_admin_access_while_commit(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint filter for admin access only when user
Pierre-Yves Chibon 5cdb69
        is an committer. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project just for foo
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            # Before
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=admin')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # Add foo to test with commit level
Pierre-Yves Chibon 5cdb69
            project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 5cdb69
            msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5cdb69
                self.session,
Pierre-Yves Chibon 5cdb69
                project=project,
Pierre-Yves Chibon 5cdb69
                new_user='foo',
Pierre-Yves Chibon 5cdb69
                user='pingou',
Pierre-Yves Chibon 5cdb69
                access='commit')
Pierre-Yves Chibon 5cdb69
            self.session.commit()
Pierre-Yves Chibon 5cdb69
            self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # After
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=admin')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    def test_index_main_admin_access_while_commit(self):
Pierre-Yves Chibon 5cdb69
        """ Test the index endpoint filter for main admin access only when
Pierre-Yves Chibon 5cdb69
        user is an committer. """
Pierre-Yves Chibon 5cdb69
        tests.create_projects(self.session)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        # Add a 3rd project just for foo
Pierre-Yves Chibon 5cdb69
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 5cdb69
            user_id=2,  # foo
Pierre-Yves Chibon 5cdb69
            name='test3',
Pierre-Yves Chibon 5cdb69
            description='test project #3 with a very long description',
Pierre-Yves Chibon 5cdb69
            hook_token='aaabbbeeefff',
Pierre-Yves Chibon 5cdb69
        )
Pierre-Yves Chibon 5cdb69
        self.session.add(item)
Pierre-Yves Chibon 5cdb69
        self.session.commit()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        user = tests.FakeUser(username='foo')
Pierre-Yves Chibon b130e5
        with tests.user_set(self.app.application, user):
Pierre-Yves Chibon 5cdb69
            # Before
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=main admin')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # Add foo to test with commit level
Pierre-Yves Chibon 5cdb69
            project = pagure.lib._get_project(self.session, 'test')
Pierre-Yves Chibon 5cdb69
            msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5cdb69
                self.session,
Pierre-Yves Chibon 5cdb69
                project=project,
Pierre-Yves Chibon 5cdb69
                new_user='foo',
Pierre-Yves Chibon 5cdb69
                user='pingou',
Pierre-Yves Chibon 5cdb69
                access='commit')
Pierre-Yves Chibon 5cdb69
            self.session.commit()
Pierre-Yves Chibon 5cdb69
            self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
            # After
Pierre-Yves Chibon 5cdb69
            output = self.app.get('/?acl=main admin')
Pierre-Yves Chibon 5cdb69
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Ryan Lerch eef090
                'Forks 0',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('

No group found

'), 1)
Pierre-Yves Chibon 5cdb69
            self.assertEqual(
Pierre-Yves Chibon 5cdb69
                output.data.count('
'), 6)
Pierre-Yves Chibon 5cdb69
Lubomír Sedlář 696885
    def test_index_fork_without_parent(self):
Lubomír Sedlář 696885
        """ Test the index view: forks should display either their parent
Lubomír Sedlář 696885
        project or mention that it was deleted. """
Lubomír Sedlář 696885
        tests.create_projects(self.session)
Lubomír Sedlář 696885
Lubomír Sedlář 696885
        # Add a 3rd project just for foo
Lubomír Sedlář 696885
        item = pagure.lib.model.Project(
Lubomír Sedlář 696885
            user_id=2,  # foo
Lubomír Sedlář 696885
            name='test3',
Lubomír Sedlář 696885
            description='test project #3',
Lubomír Sedlář 696885
            hook_token='aaabbbeeefff',
Lubomír Sedlář 696885
            is_fork=True,
Lubomír Sedlář 696885
            parent_id=1,
Lubomír Sedlář 696885
        )
Lubomír Sedlář 696885
        self.session.add(item)
Lubomír Sedlář 696885
        self.session.commit()
Lubomír Sedlář 696885
Lubomír Sedlář 696885
        user = tests.FakeUser(username='foo')
Lubomír Sedlář 696885
        with tests.user_set(self.app.application, user):
Lubomír Sedlář 696885
            # Before
Lubomír Sedlář 696885
            output = self.app.get('/')
Lubomír Sedlář 696885
            self.assertEqual(output.status_code, 200)
Lubomír Sedlář 696885
Lubomír Sedlář 696885
            self.assertIn(
Ryan Lerch eef090
                'My Forks 1',
Lubomír Sedlář 696885
                output.data)
Lubomír Sedlář 696885
            segment = output.data.split('My Forks')[1].split('My Groups')[0]
Lubomír Sedlář 696885
            self.assertRegexpMatches(
Lubomír Sedlář 696885
                segment,
Lubomír Sedlář 696885
                r'foo/test3(\s*<[^>]+?>\s*)*?forked from(\s*<[^>]+?>\s*)*?test'
Lubomír Sedlář 696885
            )
Lubomír Sedlář 696885
Lubomír Sedlář 696885
            # Delete the parent (or fake it)
Lubomír Sedlář 696885
            proj = pagure.lib._get_project(self.session, 'test3', user='foo')
Lubomír Sedlář 696885
            proj.parent_id = None
Lubomír Sedlář 696885
            self.session.add(proj)
Lubomír Sedlář 696885
            self.session.commit()
Lubomír Sedlář 696885
Lubomír Sedlář 696885
            # Check page again
Lubomír Sedlář 696885
            output = self.app.get('/')
Lubomír Sedlář 696885
            self.assertEqual(output.status_code, 200)
Lubomír Sedlář 696885
Lubomír Sedlář 696885
            self.assertIn(
Ryan Lerch eef090
                'My Forks 1',
Lubomír Sedlář 696885
                output.data)
Lubomír Sedlář 696885
            segment = output.data.split('My Forks')[1].split('My Groups')[0]
Lubomír Sedlář 696885
            self.assertRegexpMatches(
Lubomír Sedlář 696885
                segment,
Lubomír Sedlář 696885
                r'foo/test3(\s*<[^>]+?>\s*)*?forked from a deleted repository'
Lubomír Sedlář 696885
            )
Lubomír Sedlář 696885
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
if __name__ == '__main__':
Pierre-Yves Chibon 5cdb69
    unittest.main(verbosity=2)