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 5cdb69
    def setUp(self):
Pierre-Yves Chibon 5cdb69
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 5cdb69
        super(PagureFlaskAppIndextests, self).setUp()
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon 5cdb69
        pagure.SESSION = self.session
Pierre-Yves Chibon 5cdb69
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon 5cdb69
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon 5cdb69
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon 5cdb69
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 5cdb69
Pierre-Yves Chibon 5cdb69
    @patch.dict('pagure.APP.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(
Pierre-Yves Chibon 5cdb69
            '

All Projects '

Pierre-Yves Chibon 5cdb69
            '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(
Pierre-Yves Chibon 5cdb69
            '

All Projects '

Pierre-Yves Chibon 5cdb69
            '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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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(
Pierre-Yves Chibon 5cdb69
                'Projects 2',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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(
Pierre-Yves Chibon 5cdb69
                'Projects 2',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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 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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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(
Pierre-Yves Chibon 5cdb69
                'Projects 2',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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 5cdb69
        with tests.user_set(pagure.APP, 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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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(
Pierre-Yves Chibon 5cdb69
                'Projects 1',
Pierre-Yves Chibon 5cdb69
                output.data)
Pierre-Yves Chibon 5cdb69
            self.assertIn(
Pierre-Yves Chibon 5cdb69
                '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
Pierre-Yves Chibon 5cdb69
if __name__ == '__main__':
Pierre-Yves Chibon 5cdb69
    unittest.main(verbosity=2)