Blame tests/test_pagure_flask_ui_repo.py

Pierre-Yves Chibon 78ce15
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
"""
Pierre-Yves Chibon 1d1633
 (c) 2015-2016 - Copyright Red Hat Inc
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
 Authors:
Pierre-Yves Chibon 78ce15
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
"""
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 78ce15
import pkg_resources
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 66632f
import datetime
Pierre-Yves Chibon c56993
import json
Pierre-Yves Chibon 78ce15
import unittest
Pierre-Yves Chibon 78ce15
import shutil
Pierre-Yves Chibon 78ce15
import sys
Pierre-Yves Chibon 184a05
import tempfile
Pierre-Yves Chibon 78ce15
import os
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon c56993
import pygit2
Pierre-Yves Chibon 78ce15
from mock import patch
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 78ce15
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon fe5017
import pagure.lib
Pierre-Yves Chibon 78ce15
import tests
Pierre-Yves Chibon 27a73d
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon fe5017
class PagureFlaskRepotests(tests.Modeltests):
Pierre-Yves Chibon fe5017
    """ Tests for flask app controller of pagure """
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
    def setUp(self):
Pierre-Yves Chibon 78ce15
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon fe5017
        super(PagureFlaskRepotests, self).setUp()
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon fe5017
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon fe5017
        pagure.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon 06909f
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon fe5017
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 624be1
        pagure.APP.config['VIRUS_SCAN_ATTACHMENTS'] = False
Pierre-Yves Chibon fe5017
        pagure.APP.config['GIT_FOLDER'] = tests.HERE
Pierre-Yves Chibon fe5017
        pagure.APP.config['FORK_FOLDER'] = os.path.join(
Pierre-Yves Chibon 78ce15
            tests.HERE, 'forks')
Pierre-Yves Chibon 8a488f
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 8a488f
            tests.HERE, 'requests')
Pierre-Yves Chibon fe5017
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 78ce15
            tests.HERE, 'tickets')
Pierre-Yves Chibon fe5017
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 78ce15
            tests.HERE, 'docs')
Pierre-Yves Chibon ff69ce
        pagure.APP.config['UPLOAD_FOLDER_PATH'] = os.path.join(
Pierre-Yves Chibon ff69ce
            tests.HERE, 'releases')
Pierre-Yves Chibon fe5017
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon e213e7
    @patch('pagure.ui.repo.admin_session_timedout')
Vivek Anand 3b0299
    def test_add_user_when_user_mngt_off(self, ast):
Vivek Anand 3b0299
        """ Test the add_user endpoint when user management is turned off
Vivek Anand 3b0299
        in the pagure instance """
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = False
Vivek Anand 3b0299
        ast.return_value = False
Vivek Anand 3b0299
Pierre-Yves Chibon 3f60e3
        # No Git repo
Vivek Anand 3b0299
        output = self.app.get('/foo/adduser')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        tests.create_projects(self.session)
Pierre-Yves Chibon 3f60e3
        tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.get('/test/adduser')
Vivek Anand 3b0299
        self.assertEqual(output.status_code, 302)
Vivek Anand 3b0299
Vivek Anand 3b0299
        user = tests.FakeUser(username='pingou')
Vivek Anand 3b0299
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 72ed6b
Vivek Anand 3b0299
            output = self.app.get('/test/adduser')
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            #just get the csrf token
Vivek Anand 3b0299
            pagure.APP.config['ENABLE_USER_MNGT'] = True
Vivek Anand 3b0299
            output = self.app.get('/test/adduser')
Vivek Anand 3b0299
            csrf_token = output.data.split(
Vivek Anand 3b0299
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 3b0299
Vivek Anand 3b0299
            pagure.APP.config['ENABLE_USER_MNGT'] = False
Vivek Anand 3b0299
Vivek Anand 3b0299
            data = {
Vivek Anand 3b0299
                'user': 'ralph',
Vivek Anand 3b0299
            }
Vivek Anand 3b0299
Vivek Anand 3b0299
            output = self.app.post('/test/adduser', data=data)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            data['csrf_token'] = csrf_token
Vivek Anand 3b0299
            output = self.app.post('/test/adduser', data=data)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            data['user'] = 'foo'
Vivek Anand 3b0299
            tests.create_projects_git(tests.HERE)
Vivek Anand 3b0299
            output = self.app.post(
Vivek Anand 3b0299
                '/test/adduser', data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = True
Vivek Anand 3b0299
Vivek Anand 3b0299
Vivek Anand 3b0299
    @patch('pagure.ui.repo.admin_session_timedout')
Pierre-Yves Chibon e213e7
    def test_add_user(self, ast):
Pierre-Yves Chibon 78ce15
        """ Test the add_user endpoint. """
Pierre-Yves Chibon e213e7
        ast.return_value = False
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 3f60e3
        # No git repo
Pierre-Yves Chibon 78ce15
        output = self.app.get('/foo/adduser')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        tests.create_projects(self.session)
Pierre-Yves Chibon 3f60e3
        tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.get('/test/adduser')
Pierre-Yves Chibon 78ce15
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 78ce15
            output = self.app.get('/test/adduser')
Pierre-Yves Chibon 78ce15
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon e213e7
            ast.return_value = True
Pierre-Yves Chibon e213e7
            output = self.app.get('/test/adduser')
Pierre-Yves Chibon e213e7
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 728eb1
Pierre-Yves Chibon 728eb1
            # Redirect also happens for POST request
Pierre-Yves Chibon 728eb1
            output = self.app.post('/test/adduser')
Pierre-Yves Chibon 728eb1
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 728eb1
Pierre-Yves Chibon fb5b9d
        # Need to do this un-authentified since our fake user isn't in the DB
Pierre-Yves Chibon fb5b9d
        # Check the message flashed during the redirect
Pierre-Yves Chibon fb5b9d
        output = self.app.get('/')
Pierre-Yves Chibon fb5b9d
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon fb5b9d
        self.assertIn(
Pierre-Yves Chibon fb5b9d
            '\n                      Action canceled, try it '
Pierre-Yves Chibon fb5b9d
            'again',output.data)
Pierre-Yves Chibon fb5b9d
Pierre-Yves Chibon fb5b9d
        ast.return_value = False
Pierre-Yves Chibon e213e7
Pierre-Yves Chibon 78ce15
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 78ce15
            output = self.app.get('/test/adduser')
Pierre-Yves Chibon 78ce15
            self.assertEqual(output.status_code, 200)
Ryan Lerch b27f8f
            self.assertIn('Add user to the', output.data)
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
            csrf_token = output.data.split(
Pierre-Yves Chibon 78ce15
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
            data = {
Pierre-Yves Chibon 78ce15
                'user': 'ralph',
Pierre-Yves Chibon 78ce15
            }
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
            output = self.app.post('/test/adduser', data=data)
Pierre-Yves Chibon 78ce15
            self.assertEqual(output.status_code, 200)
Ryan Lerch b27f8f
            self.assertTrue('Add user to the' in output.data)
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 78ce15
            output = self.app.post('/test/adduser', data=data)
Pierre-Yves Chibon 78ce15
            self.assertEqual(output.status_code, 200)
Ryan Lerch b27f8f
            self.assertIn('Add user to the', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      No user "ralph" '
Pierre-Yves Chibon efb2ec
                'found', output.data)
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
            data['user'] = 'foo'
Pierre-Yves Chibon 78ce15
            output = self.app.post(
Pierre-Yves Chibon 78ce15
                '/test/adduser', data=data, follow_redirects=True)
Pierre-Yves Chibon 78ce15
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      User added', output.data)
Pierre-Yves Chibon 78ce15
Vivek Anand 3b0299
Vivek Anand 3b0299
    @patch('pagure.ui.repo.admin_session_timedout')
Vivek Anand 3b0299
    def test_add_group_project_when_user_mngt_off(self, ast):
Vivek Anand 3b0299
        """ Test the add_group_project endpoint  when user management is
Vivek Anand 3b0299
        turned off in the pagure instance"""
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = False
Vivek Anand 3b0299
        ast.return_value = False
Vivek Anand 3b0299
Pierre-Yves Chibon 3f60e3
        # No Git repo
Vivek Anand 3b0299
        output = self.app.get('/foo/addgroup')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        tests.create_projects(self.session)
Pierre-Yves Chibon 3f60e3
        tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.get('/test/addgroup')
Vivek Anand 3b0299
        self.assertEqual(output.status_code, 302)
Vivek Anand 3b0299
Vivek Anand 3b0299
        msg = pagure.lib.add_group(
Vivek Anand 3b0299
            self.session,
Vivek Anand 3b0299
            group_name='foo',
Vivek Anand 3b0299
            group_type='bar',
Pierre-Yves Chibon ce6666
            display_name='foo group',
Pierre-Yves Chibon ce6666
            description=None,
Vivek Anand 3b0299
            user='pingou',
Vivek Anand 3b0299
            is_admin=False,
Vivek Anand 3b0299
            blacklist=pagure.APP.config['BLACKLISTED_GROUPS'],
Vivek Anand 3b0299
        )
Vivek Anand 3b0299
        self.session.commit()
Vivek Anand 3b0299
        self.assertEqual(msg, 'User `pingou` added to the group `foo`.')
Vivek Anand 3b0299
Vivek Anand 3b0299
        user = tests.FakeUser(username='pingou')
Vivek Anand 3b0299
        with tests.user_set(pagure.APP, user):
Vivek Anand 3b0299
            #just get the csrf token
Vivek Anand 3b0299
            pagure.APP.config['ENABLE_USER_MNGT'] = True
Pierre-Yves Chibon 72ed6b
Vivek Anand 3b0299
            output = self.app.get('/test/addgroup')
Vivek Anand 3b0299
            csrf_token = output.data.split(
Vivek Anand 3b0299
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 3b0299
            pagure.APP.config['ENABLE_USER_MNGT'] = False
Vivek Anand 3b0299
Vivek Anand 3b0299
            data = {
Vivek Anand 3b0299
                'group': 'ralph',
Vivek Anand 3b0299
            }
Vivek Anand 3b0299
Vivek Anand 3b0299
            output = self.app.post('/test/addgroup', data=data)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            data['csrf_token'] = csrf_token
Vivek Anand 3b0299
            output = self.app.post('/test/addgroup', data=data)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            data['group'] = 'foo'
Vivek Anand 3b0299
            output = self.app.post(
Vivek Anand 3b0299
                '/test/addgroup', data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = True
Vivek Anand 3b0299
Vivek Anand 3b0299
Pierre-Yves Chibon 5f82db
    @patch('pagure.ui.repo.admin_session_timedout')
Pierre-Yves Chibon 8b9ecb
    def test_add_group_project(self, ast):
Pierre-Yves Chibon 8b9ecb
        """ Test the add_group_project endpoint. """
Pierre-Yves Chibon 8b9ecb
        ast.return_value = False
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 3f60e3
        # No Git repo
Pierre-Yves Chibon 8b9ecb
        output = self.app.get('/foo/addgroup')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        tests.create_projects(self.session)
Pierre-Yves Chibon 3f60e3
        tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.get('/test/addgroup')
Pierre-Yves Chibon 8b9ecb
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
        user = tests.FakeUser()
Pierre-Yves Chibon 8b9ecb
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 8b9ecb
            output = self.app.get('/test/addgroup')
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            ast.return_value = True
Pierre-Yves Chibon 8b9ecb
            output = self.app.get('/test/addgroup')
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 7de9f5
Pierre-Yves Chibon 7de9f5
            # Redirect also happens for POST request
Pierre-Yves Chibon 7de9f5
            output = self.app.post('/test/addgroup')
Pierre-Yves Chibon 7de9f5
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 7de9f5
Pierre-Yves Chibon fb5b9d
        # Need to do this un-authentified since our fake user isn't in the DB
Pierre-Yves Chibon fb5b9d
        # Check the message flashed during the redirect
Pierre-Yves Chibon fb5b9d
        output = self.app.get('/')
Pierre-Yves Chibon fb5b9d
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon fb5b9d
        self.assertIn(
Pierre-Yves Chibon fb5b9d
            '\n                      Action canceled, try it '
Pierre-Yves Chibon fb5b9d
            'again', output.data)
Pierre-Yves Chibon fb5b9d
Pierre-Yves Chibon fb5b9d
        ast.return_value = False
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
        msg = pagure.lib.add_group(
Pierre-Yves Chibon 8b9ecb
            self.session,
Pierre-Yves Chibon 8b9ecb
            group_name='foo',
Pierre-Yves Chibon ce6666
            display_name='foo group',
Pierre-Yves Chibon ce6666
            description=None,
Pierre-Yves Chibon 8b9ecb
            group_type='bar',
Pierre-Yves Chibon 8b9ecb
            user='pingou',
Pierre-Yves Chibon 8b9ecb
            is_admin=False,
Pierre-Yves Chibon d4d101
            blacklist=pagure.APP.config['BLACKLISTED_GROUPS'],
Pierre-Yves Chibon 8b9ecb
        )
Pierre-Yves Chibon 8b9ecb
        self.session.commit()
Pierre-Yves Chibon 8b9ecb
        self.assertEqual(msg, 'User `pingou` added to the group `foo`.')
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
        user.username = 'pingou'
Pierre-Yves Chibon 8b9ecb
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 8b9ecb
            output = self.app.get('/test/addgroup')
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 200)
Ryan Lerch b27f8f
            self.assertTrue('Add group to the' in output.data)
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            csrf_token = output.data.split(
Pierre-Yves Chibon 8b9ecb
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            data = {
Pierre-Yves Chibon 8b9ecb
                'group': 'ralph',
Pierre-Yves Chibon 8b9ecb
            }
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            output = self.app.post('/test/addgroup', data=data)
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 200)
Ryan Lerch b27f8f
            self.assertTrue('Add group to the' in output.data)
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            data['csrf_token'] = csrf_token
Pierre-Yves Chibon 8b9ecb
            output = self.app.post('/test/addgroup', data=data)
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 200)
Ryan Lerch b27f8f
            self.assertTrue('Add group to the' in output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      No group ralph found.',
Pierre-Yves Chibon efb2ec
                output.data)
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            data['group'] = 'foo'
Pierre-Yves Chibon 8b9ecb
            output = self.app.post(
Pierre-Yves Chibon 8b9ecb
                '/test/addgroup', data=data, follow_redirects=True)
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Group added', output.data)
Pierre-Yves Chibon 8b9ecb
Vivek Anand 3b0299
    @patch('pagure.ui.repo.admin_session_timedout')
Vivek Anand 3b0299
    def test_remove_user_when_user_mngt_off(self, ast):
Vivek Anand 3b0299
        """ Test the remove_user endpoint when user management is turned
Vivek Anand 3b0299
        off in the pagure instance"""
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = False
Vivek Anand 3b0299
        ast.return_value = False
Vivek Anand 3b0299
Pierre-Yves Chibon 3f60e3
        # Git repo not found
Vivek Anand 3b0299
        output = self.app.post('/foo/dropuser/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
        user = tests.FakeUser(username='pingou')
Vivek Anand 3b0299
        with tests.user_set(pagure.APP, user):
Vivek Anand 3b0299
            tests.create_projects(self.session)
Vivek Anand 3b0299
            tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 72ed6b
Vivek Anand 3b0299
            output = self.app.post('/test/settings')
Vivek Anand 3b0299
Vivek Anand 3b0299
            csrf_token = output.data.split(
Vivek Anand 3b0299
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 3b0299
Vivek Anand 3b0299
            data = {'csrf_token': csrf_token}
Vivek Anand 3b0299
Vivek Anand 3b0299
            output = self.app.post(
Vivek Anand 3b0299
                '/test/dropuser/2', data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.post('/test/dropuser/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 3f60e3
Vivek Anand 3b0299
        # Add an user to a project
Vivek Anand 3b0299
        repo = pagure.lib.get_project(self.session, 'test')
Vivek Anand 3b0299
        msg = pagure.lib.add_user_to_project(
Vivek Anand 3b0299
            session=self.session,
Vivek Anand 3b0299
            project=repo,
Vivek Anand 3b0299
            new_user='foo',
Vivek Anand 3b0299
            user='pingou',
Vivek Anand 3b0299
        )
Vivek Anand 3b0299
        self.session.commit()
Vivek Anand 3b0299
        self.assertEqual(msg, 'User added')
Vivek Anand 3b0299
Vivek Anand 3b0299
        with tests.user_set(pagure.APP, user):
Vivek Anand 3b0299
            output = self.app.post('/test/dropuser/2', follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            data = {'csrf_token': csrf_token}
Vivek Anand 3b0299
            output = self.app.post(
Vivek Anand 3b0299
                '/test/dropuser/2', data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = True
Vivek Anand 3b0299
Vivek Anand 3b0299
Pierre-Yves Chibon 8b9ecb
    @patch('pagure.ui.repo.admin_session_timedout')
Pierre-Yves Chibon 5f82db
    def test_remove_user(self, ast):
Pierre-Yves Chibon 5980f6
        """ Test the remove_user endpoint. """
Pierre-Yves Chibon 5f82db
        ast.return_value = False
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon 3f60e3
        # Git repo not found
Pierre-Yves Chibon 5980f6
        output = self.app.post('/foo/dropuser/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon 5980f6
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5980f6
            output = self.app.post('/foo/dropuser/1')
Pierre-Yves Chibon 5980f6
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon 5980f6
            tests.create_projects(self.session)
Pierre-Yves Chibon 72ed6b
            tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon 5980f6
            output = self.app.post('/test/dropuser/1')
Pierre-Yves Chibon 5980f6
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon 5f82db
            ast.return_value = True
Pierre-Yves Chibon 5f82db
            output = self.app.post('/test/dropuser/1')
Pierre-Yves Chibon 5f82db
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 5f82db
            ast.return_value = False
Pierre-Yves Chibon 5f82db
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.post('/test/dropuser/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 5980f6
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 2c15da
            output = self.app.post('/test/settings')
Pierre-Yves Chibon 2c15da
Pierre-Yves Chibon 2c15da
            csrf_token = output.data.split(
Pierre-Yves Chibon 2c15da
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 2c15da
Pierre-Yves Chibon 2c15da
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 2c15da
Pierre-Yves Chibon 2c15da
            output = self.app.post(
Pierre-Yves Chibon 2c15da
                '/test/dropuser/2', data=data, follow_redirects=True)
Pierre-Yves Chibon 5980f6
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      User does not have commit or cannot '
Pierre-Yves Chibon efb2ec
                'loose it right', output.data)
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon 5980f6
        # Add an user to a project
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon fe5017
        msg = pagure.lib.add_user_to_project(
Pierre-Yves Chibon 5980f6
            session=self.session,
Pierre-Yves Chibon 5980f6
            project=repo,
Pierre-Yves Chibon a5a9ad
            new_user='foo',
Pierre-Yves Chibon a5a9ad
            user='pingou',
Pierre-Yves Chibon 5980f6
        )
Pierre-Yves Chibon 5980f6
        self.session.commit()
Pierre-Yves Chibon 5980f6
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon 5980f6
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 5980f6
            output = self.app.post('/test/dropuser/2', follow_redirects=True)
Pierre-Yves Chibon 5980f6
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertNotIn(
Pierre-Yves Chibon efb2ec
                '\n                      User removed', output.data)
Pierre-Yves Chibon 2c15da
Pierre-Yves Chibon 2c15da
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 2c15da
            output = self.app.post(
Pierre-Yves Chibon 2c15da
                '/test/dropuser/2', data=data, follow_redirects=True)
Pierre-Yves Chibon 2c15da
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      User removed', output.data)
Pierre-Yves Chibon 5980f6
Vivek Anand 3b0299
Vivek Anand 3b0299
    @patch('pagure.ui.repo.admin_session_timedout')
Vivek Anand 3b0299
    def test_remove_group_project_when_user_mngt_off(self, ast):
Vivek Anand 3b0299
        """ Test the remove_group_project endpoint when user management is
Vivek Anand 3b0299
        turned off in the pagure instance"""
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = False
Vivek Anand 3b0299
        ast.return_value = False
Vivek Anand 3b0299
Pierre-Yves Chibon 3f60e3
        # No Git repo
Vivek Anand 3b0299
        output = self.app.post('/foo/dropgroup/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        tests.create_projects(self.session)
Pierre-Yves Chibon 3f60e3
        tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.post('/test/dropgroup/1')
Vivek Anand 3b0299
        self.assertEqual(output.status_code, 302)
Vivek Anand 3b0299
Vivek Anand 3b0299
        user = tests.FakeUser()
Vivek Anand 3b0299
        user.username = 'pingou'
Vivek Anand 3b0299
        with tests.user_set(pagure.APP, user):
Vivek Anand 3b0299
            output = self.app.post('/test/settings')
Vivek Anand 3b0299
Vivek Anand 3b0299
            csrf_token = output.data.split(
Vivek Anand 3b0299
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Vivek Anand 3b0299
Vivek Anand 3b0299
            data = {'csrf_token': csrf_token}
Vivek Anand 3b0299
Vivek Anand 3b0299
            output = self.app.post(
Vivek Anand 3b0299
                '/test/dropgroup/2', data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
        # Create the new group
Vivek Anand 3b0299
        msg = pagure.lib.add_group(
Vivek Anand 3b0299
            session=self.session,
Vivek Anand 3b0299
            group_name='testgrp',
Vivek Anand 3b0299
            group_type='user',
Pierre-Yves Chibon ce6666
            display_name='testgrp group',
Pierre-Yves Chibon ce6666
            description=None,
Vivek Anand 3b0299
            user='pingou',
Vivek Anand 3b0299
            is_admin=False,
Vivek Anand 3b0299
            blacklist=[],
Vivek Anand 3b0299
        )
Vivek Anand 3b0299
        self.assertEqual(msg, 'User `pingou` added to the group `testgrp`.')
Vivek Anand 3b0299
        self.session.commit()
Vivek Anand 3b0299
Vivek Anand 3b0299
        repo = pagure.lib.get_project(self.session, 'test')
Vivek Anand 3b0299
        # Add the group to a project
Vivek Anand 3b0299
        msg = pagure.lib.add_group_to_project(
Vivek Anand 3b0299
            session=self.session,
Vivek Anand 3b0299
            project=repo,
Vivek Anand 3b0299
            new_group='testgrp',
Vivek Anand 3b0299
            user='pingou',
Vivek Anand 3b0299
        )
Vivek Anand 3b0299
        self.session.commit()
Vivek Anand 3b0299
        self.assertEqual(msg, 'Group added')
Vivek Anand 3b0299
Vivek Anand 3b0299
        with tests.user_set(pagure.APP, user):
Vivek Anand 3b0299
            output = self.app.post('/test/dropgroup/1', follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
            data = {'csrf_token': csrf_token}
Vivek Anand 3b0299
            output = self.app.post(
Vivek Anand 3b0299
                '/test/dropgroup/1', data=data, follow_redirects=True)
Vivek Anand 3b0299
            self.assertEqual(output.status_code, 404)
Vivek Anand 3b0299
Vivek Anand 3b0299
        pagure.APP.config['ENABLE_USER_MNGT'] = True
Vivek Anand 3b0299
Vivek Anand 3b0299
Pierre-Yves Chibon e2fa89
    @patch('pagure.ui.repo.admin_session_timedout')
Pierre-Yves Chibon 114c3d
    def test_remove_group_project(self, ast):
Pierre-Yves Chibon 114c3d
        """ Test the remove_group_project endpoint. """
Pierre-Yves Chibon 114c3d
        ast.return_value = False
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 3f60e3
        # No Git repo
Pierre-Yves Chibon 114c3d
        output = self.app.post('/foo/dropgroup/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
        user = tests.FakeUser()
Pierre-Yves Chibon 114c3d
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 114c3d
            output = self.app.post('/foo/dropgroup/1')
Pierre-Yves Chibon 114c3d
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            tests.create_projects(self.session)
Pierre-Yves Chibon 72ed6b
            tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            output = self.app.post('/test/dropgroup/1')
Pierre-Yves Chibon 114c3d
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            ast.return_value = True
Pierre-Yves Chibon 114c3d
            output = self.app.post('/test/dropgroup/1')
Pierre-Yves Chibon 114c3d
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 114c3d
            ast.return_value = False
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.post('/test/dropgroup/1')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 114c3d
        user.username = 'pingou'
Pierre-Yves Chibon 114c3d
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 114c3d
            output = self.app.post('/test/settings')
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            csrf_token = output.data.split(
Pierre-Yves Chibon 114c3d
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            output = self.app.post(
Pierre-Yves Chibon 114c3d
                '/test/dropgroup/2', data=data, follow_redirects=True)
Pierre-Yves Chibon 114c3d
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 114c3d
            self.assertIn(
Pierre-Yves Chibon 114c3d
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 114c3d
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 114c3d
            self.assertIn(
Pierre-Yves Chibon 114c3d
                '\n                      '
Pierre-Yves Chibon 114c3d
                'Group does not seem to be part of this project',
Pierre-Yves Chibon 114c3d
                output.data)
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
        # Create the new group
Pierre-Yves Chibon 114c3d
        msg = pagure.lib.add_group(
Pierre-Yves Chibon 114c3d
            session=self.session,
Pierre-Yves Chibon 114c3d
            group_name='testgrp',
Pierre-Yves Chibon 114c3d
            group_type='user',
Pierre-Yves Chibon ce6666
            display_name='testgrp group',
Pierre-Yves Chibon ce6666
            description=None,
Pierre-Yves Chibon 114c3d
            user='pingou',
Pierre-Yves Chibon 114c3d
            is_admin=False,
Pierre-Yves Chibon 114c3d
            blacklist=[],
Pierre-Yves Chibon 114c3d
        )
Pierre-Yves Chibon 114c3d
        self.assertEqual(msg, 'User `pingou` added to the group `testgrp`.')
Pierre-Yves Chibon 114c3d
        self.session.commit()
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 114c3d
        # Add the group to a project
Pierre-Yves Chibon 114c3d
        msg = pagure.lib.add_group_to_project(
Pierre-Yves Chibon 114c3d
            session=self.session,
Pierre-Yves Chibon 114c3d
            project=repo,
Pierre-Yves Chibon 114c3d
            new_group='testgrp',
Pierre-Yves Chibon 114c3d
            user='pingou',
Pierre-Yves Chibon 114c3d
        )
Pierre-Yves Chibon 114c3d
        self.session.commit()
Pierre-Yves Chibon 114c3d
        self.assertEqual(msg, 'Group added')
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 114c3d
            output = self.app.post('/test/dropgroup/1', follow_redirects=True)
Pierre-Yves Chibon 114c3d
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 114c3d
            self.assertIn(
Pierre-Yves Chibon 114c3d
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 114c3d
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 114c3d
            self.assertNotIn(
Pierre-Yves Chibon 114c3d
                '\n                      Group removed',
Pierre-Yves Chibon 114c3d
                output.data)
Pierre-Yves Chibon 114c3d
Pierre-Yves Chibon 114c3d
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 114c3d
            output = self.app.post(
Pierre-Yves Chibon 114c3d
                '/test/dropgroup/1', data=data, follow_redirects=True)
Pierre-Yves Chibon 114c3d
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 114c3d
            self.assertIn(
Pierre-Yves Chibon 114c3d
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon 114c3d
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 114c3d
            self.assertIn(
Pierre-Yves Chibon 114c3d
                '\n                      Group removed',
Pierre-Yves Chibon 114c3d
                output.data)
Pierre-Yves Chibon 114c3d
Vivek Anand 3b0299
Pierre-Yves Chibon 114c3d
    @patch('pagure.ui.repo.admin_session_timedout')
Pierre-Yves Chibon e2fa89
    def test_update_project(self, ast):
Pierre-Yves Chibon 21b196
        """ Test the update_project endpoint. """
Pierre-Yves Chibon e2fa89
        ast.return_value = True
Pierre-Yves Chibon e2fa89
Pierre-Yves Chibon 3f60e3
        # Git repo not found
Pierre-Yves Chibon 21b196
        output = self.app.post('/foo/update')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon 8cae39
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 3f60e3
            # Project does not exist
Pierre-Yves Chibon e2fa89
            output = self.app.post('/foo/update')
Pierre-Yves Chibon 8cae39
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon 8cae39
            tests.create_projects(self.session)
Pierre-Yves Chibon 3f60e3
            tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
            # Session timed-out
Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/update')
Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon 3f60e3
            ast.return_value = False
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 3f60e3
            # Not allowed
Pierre-Yves Chibon 21b196
            output = self.app.post('/test/update')
Pierre-Yves Chibon 8cae39
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.post('/test/update')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 8cae39
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 21b196
            output = self.app.post('/test/update', follow_redirects=True)
Pierre-Yves Chibon 8cae39
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon 8cae39
            csrf_token = output.data.split(
Pierre-Yves Chibon 8cae39
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon 8cae39
            data = {
Pierre-Yves Chibon 8cae39
                'description': 'new description for test project #1',
Pierre-Yves Chibon 8cae39
                'csrf_token': csrf_token,
Pierre-Yves Chibon 8cae39
            }
Pierre-Yves Chibon 8cae39
            output = self.app.post(
Pierre-Yves Chibon 21b196
                '/test/update', data=data, follow_redirects=True)
Pierre-Yves Chibon 8cae39
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon a3121e
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<input class="form-control" name="avatar_email" value="">', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Project updated',
Pierre-Yves Chibon efb2ec
                output.data)
Pierre-Yves Chibon a3121e
Pierre-Yves Chibon a3121e
            # Edit the avatar_email
Pierre-Yves Chibon a3121e
            data = {
Pierre-Yves Chibon a3121e
                'description': 'new description for test project #1',
Pierre-Yves Chibon a3121e
                'avatar_email': 'pingou@fp.o',
Pierre-Yves Chibon a3121e
                'csrf_token': csrf_token,
Pierre-Yves Chibon a3121e
            }
Pierre-Yves Chibon a3121e
            output = self.app.post(
Pierre-Yves Chibon 21b196
                '/test/update', data=data, follow_redirects=True)
Pierre-Yves Chibon a3121e
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon a3121e
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<input class="form-control" name="avatar_email" value="pingou@fp.o">',
Pierre-Yves Chibon efb2ec
                output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Project updated',
Pierre-Yves Chibon a3121e
                output.data)
Pierre-Yves Chibon a3121e
Pierre-Yves Chibon a3121e
            # Reset the avatar_email
Pierre-Yves Chibon a3121e
            data = {
Pierre-Yves Chibon a3121e
                'description': 'new description for test project #1',
Pierre-Yves Chibon a3121e
                'avatar_email': '',
Pierre-Yves Chibon a3121e
                'csrf_token': csrf_token,
Pierre-Yves Chibon a3121e
            }
Pierre-Yves Chibon a3121e
            output = self.app.post(
Pierre-Yves Chibon 21b196
                '/test/update', data=data, follow_redirects=True)
Pierre-Yves Chibon a3121e
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon a3121e
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<input class="form-control" name="avatar_email" value="">', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Project updated',
Pierre-Yves Chibon a3121e
                output.data)
Pierre-Yves Chibon 8cae39
Pierre-Yves Chibon d9cdbe
    @patch('pagure.ui.repo.admin_session_timedout')
Pierre-Yves Chibon d9cdbe
    def test_view_settings(self, ast):
Pierre-Yves Chibon 490ff9
        """ Test the view_settings endpoint. """
Pierre-Yves Chibon d9cdbe
        ast.return_value = False
Pierre-Yves Chibon d9cdbe
Pierre-Yves Chibon 3f60e3
        # No Git repo
Pierre-Yves Chibon 490ff9
        output = self.app.get('/foo/settings')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
        user = tests.FakeUser()
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon 490ff9
            output = self.app.get('/foo/settings')
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            tests.create_projects(self.session)
Pierre-Yves Chibon 490ff9
            tests.create_projects_git(tests.HERE)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 403)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 3f60e3
        # User not logged in
Pierre-Yves Chibon 3f60e3
        output = self.app.get('/test/settings')
Pierre-Yves Chibon 3f60e3
        self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon 3f60e3
Pierre-Yves Chibon 490ff9
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Pierre-Yves Chibon d9cdbe
            ast.return_value = True
Pierre-Yves Chibon d9cdbe
            output = self.app.get('/test/settings')
Pierre-Yves Chibon d9cdbe
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon d9cdbe
Pierre-Yves Chibon d9cdbe
            ast.return_value = False
Pierre-Yves Chibon d9cdbe
            output = self.app.get('/test/settings')
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
Pierre-Yves Chibon 490ff9
            # Both checkbox checked before
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 540c4b
                '
Pierre-Yves Chibon efb2ec
                'name="pull_requests" checked=""/>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 719bdd
                '
Pierre-Yves Chibon efb2ec
                'name="issue_tracker" checked=""/>', output.data)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            csrf_token = output.data.split(
Pierre-Yves Chibon 490ff9
                'name="csrf_token" type="hidden" value="')[1].split('">')[0]
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            data = {}
Pierre-Yves Chibon 490ff9
            output = self.app.post(
Pierre-Yves Chibon 490ff9
                '/test/settings', data=data, follow_redirects=True)
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            # Both checkbox are still checked
Pierre-Yves Chibon 490ff9
            output = self.app.get('/test/settings', follow_redirects=True)
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 540c4b
                '
Pierre-Yves Chibon efb2ec
                'name="pull_requests" checked=""/>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 719bdd
                '
Pierre-Yves Chibon efb2ec
                'name="issue_tracker" checked=""/>', output.data)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            data = {'csrf_token': csrf_token}
Pierre-Yves Chibon 490ff9
            output = self.app.post(
Pierre-Yves Chibon 490ff9
                '/test/settings', data=data, follow_redirects=True)
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Overview - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Edited successfully '
Pierre-Yves Chibon efb2ec
                'settings of repo: test', output.data)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon 490ff9
            # Both checkbox are now un-checked
Pierre-Yves Chibon 490ff9
            output = self.app.get('/test/settings', follow_redirects=True)
Pierre-Yves Chibon 490ff9
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 540c4b
                '
Pierre-Yves Chibon efb2ec
                'name="pull_requests" />', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 719bdd
                '
Pierre-Yves Chibon efb2ec
                'name="issue_tracker" />', output.data)
Pierre-Yves Chibon 490ff9
Pierre-Yves Chibon c104d3
            data = {
Pierre-Yves Chibon c104d3
                'csrf_token': csrf_token,
Pierre-Yves Chibon 540c4b
                'pull_requests': 'y',
Pierre-Yves Chibon c104d3
                'issue_tracker': 'y',
Pierre-Yves Chibon c104d3
            }
Pierre-Yves Chibon c104d3
            output = self.app.post(
Pierre-Yves Chibon c104d3
                '/test/settings', data=data, follow_redirects=True)
Pierre-Yves Chibon c104d3
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Overview - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 98f2af
                '
\n'
Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Edited successfully '
Pierre-Yves Chibon efb2ec
                'settings of repo: test', output.data)
Pierre-Yves Chibon c104d3
Pierre-Yves Chibon c104d3
            # Both checkbox are again checked
Pierre-Yves Chibon c104d3
            output = self.app.get('/test/settings', follow_redirects=True)
Pierre-Yves Chibon c104d3
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '<title>Settings - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Settings for test

', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon 540c4b
                '
Pierre-Yves Chibon efb2ec
                'name="pull_requests" checked=""/>', output.data)
Pierre-Yves Chibon efb2ec
            self.assertIn(
Pierre-Yves Chibon c104d3
                '
Pierre-Yves Chibon efb2ec
                'name="issue_tracker" checked=""/>', output.data)
Pierre-Yves Chibon c104d3
Pierre-Yves Chibon aca486
    def test_view_forks(self):
Pierre-Yves Chibon aca486
        """ Test the view_forks endpoint. """
Pierre-Yves Chibon aca486
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/foo/forks', follow_redirects=True)
Pierre-Yves Chibon aca486
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aca486
Pierre-Yves Chibon aca486
        tests.create_projects(self.session)
Ryan Lerch 7bc3d6
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon aca486
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/forks', follow_redirects=True)
Pierre-Yves Chibon aca486
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon aca486
        self.assertTrue('This project has not been forked.' in output.data)
Pierre-Yves Chibon aca486
Pierre-Yves Chibon 0447df
    def test_view_repo(self):
Pierre-Yves Chibon 0447df
        """ Test the view_repo endpoint. """
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        output = self.app.get('/foo')
Pierre-Yves Chibon 0447df
        # No project registered in the DB
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        tests.create_projects(self.session)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        output = self.app.get('/test')
Pierre-Yves Chibon 0447df
        # No git repo associated
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        output = self.app.get('/test')
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0447df
        self.assertTrue('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 21c4c3
        output = self.app.get('/test/')
Pierre-Yves Chibon 21c4c3
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 21c4c3
        self.assertTrue('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 21c4c3
        self.assertIn(
Pierre-Yves Chibon 21c4c3
            '
\n'
Pierre-Yves Chibon 21c4c3
            'test project #1        ', output.data)
Pierre-Yves Chibon 21c4c3
Pierre-Yves Chibon 0447df
        # Add some content to the git repo
Pierre-Yves Chibon 0447df
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 0447df
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        output = self.app.get('/test')
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0447df
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 0447df
        self.assertFalse('Forked from' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        # Turn that repo into a fork
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 0447df
        repo.parent_id = 2
farhaanbukhsh 907098
        repo.is_fork = True
Pierre-Yves Chibon 0447df
        self.session.add(repo)
Pierre-Yves Chibon 0447df
        self.session.commit()
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        # View the repo in the UI
Pierre-Yves Chibon 0447df
        output = self.app.get('/test')
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        # Add some content to the git repo
Pierre-Yves Chibon 0447df
        tests.add_content_git_repo(
Pierre-Yves Chibon 0447df
            os.path.join(tests.HERE, 'forks', 'pingou', 'test.git'))
Pierre-Yves Chibon 0447df
        tests.add_readme_git_repo(
Pierre-Yves Chibon 0447df
            os.path.join(tests.HERE, 'forks', 'pingou', 'test.git'))
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        output = self.app.get('/fork/pingou/test')
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0447df
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon 0447df
        self.assertTrue('Forked from' in output.data)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 0447df
            user_id=1,  # pingou
Pierre-Yves Chibon 0447df
            name='test3',
Pierre-Yves Chibon 0447df
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon 0447df
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbbmmm',
Pierre-Yves Chibon 0447df
        )
Pierre-Yves Chibon 0447df
        self.session.add(item)
Pierre-Yves Chibon 0447df
        self.session.commit()
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        tests.add_content_git_repo(
Pierre-Yves Chibon 0447df
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon 0447df
        tests.add_readme_git_repo(
Pierre-Yves Chibon 0447df
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon 0447df
        tests.add_commit_git_repo(
Pierre-Yves Chibon 0447df
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'),
Pierre-Yves Chibon 0447df
            ncommits=10)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 0447df
        output = self.app.get('/fork/pingou/test3')
Pierre-Yves Chibon 0447df
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0447df
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #3        ', output.data)
Pierre-Yves Chibon 0447df
        self.assertTrue('Forked from' in output.data)
Pierre-Yves Chibon 0447df
Pierre-Yves Chibon 184a05
    def test_view_repo_empty(self):
Pierre-Yves Chibon 184a05
        """ Test the view_repo endpoint on a repo w/o master branch. """
Pierre-Yves Chibon 184a05
Pierre-Yves Chibon 184a05
        tests.create_projects(self.session)
Pierre-Yves Chibon 184a05
        # Create a git repo to play with
Pierre-Yves Chibon 184a05
        gitrepo = os.path.join(tests.HERE, 'test.git')
Pierre-Yves Chibon 184a05
        pygit2.init_repository(gitrepo, bare=True)
Pierre-Yves Chibon 184a05
Pierre-Yves Chibon 184a05
        # Create a fork of this repo
Pierre-Yves Chibon 184a05
        newpath = tempfile.mkdtemp(prefix='pagure-viewrepo-test')
Pierre-Yves Chibon 184a05
        new_repo = pygit2.clone_repository(gitrepo, newpath)
Pierre-Yves Chibon 184a05
Pierre-Yves Chibon 184a05
        # Edit the sources file again
Pierre-Yves Chibon 184a05
        with open(os.path.join(newpath, 'sources'), 'w') as stream:
Pierre-Yves Chibon 184a05
            stream.write('foo\n bar\nbaz\n boose')
Pierre-Yves Chibon 184a05
        new_repo.index.add('sources')
Pierre-Yves Chibon 184a05
        new_repo.index.write()
Pierre-Yves Chibon 184a05
Pierre-Yves Chibon 184a05
        # Commits the files added
Pierre-Yves Chibon 184a05
        tree = new_repo.index.write_tree()
Pierre-Yves Chibon 184a05
        author = pygit2.Signature(
Pierre-Yves Chibon 184a05
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 184a05
        committer = pygit2.Signature(
Pierre-Yves Chibon 184a05
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 184a05
        new_repo.create_commit(
Pierre-Yves Chibon 184a05
            'refs/heads/feature',
Pierre-Yves Chibon 184a05
            author,
Pierre-Yves Chibon 184a05
            committer,
Pierre-Yves Chibon 184a05
            'A commit on branch feature',
Pierre-Yves Chibon 184a05
            tree,
Pierre-Yves Chibon 184a05
            []
Pierre-Yves Chibon 184a05
        )
Pierre-Yves Chibon 184a05
        refname = 'refs/heads/feature'
Pierre-Yves Chibon 184a05
        ori_remote = new_repo.remotes[0]
Pierre-Yves Chibon 27a73d
        PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 184a05
Pierre-Yves Chibon 184a05
        output = self.app.get('/test')
Pierre-Yves Chibon 184a05
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 184a05
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 184a05
        self.assertFalse('Forked from' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon 184a05
        self.assertEqual(
Pierre-Yves Chibon 184a05
            output.data.count(''), 0)
Pierre-Yves Chibon 184a05
Pierre-Yves Chibon 62ffe0
        shutil.rmtree(newpath)
Pierre-Yves Chibon 62ffe0
Pierre-Yves Chibon faa629
    def test_view_repo_branch(self):
Pierre-Yves Chibon faa629
        """ Test the view_repo_branch endpoint. """
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        output = self.app.get('/foo/branch/master')
Pierre-Yves Chibon faa629
        # No project registered in the DB
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        tests.create_projects(self.session)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        output = self.app.get('/test/branch/master')
Pierre-Yves Chibon faa629
        # No git repo associated
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        output = self.app.get('/test/branch/master')
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        # Add some content to the git repo
Pierre-Yves Chibon faa629
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon faa629
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        output = self.app.get('/test/branch/master')
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon faa629
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon faa629
        self.assertFalse('Forked from' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        # Turn that repo into a fork
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon faa629
        repo.parent_id = 2
farhaanbukhsh 907098
        repo.is_fork = True
Pierre-Yves Chibon faa629
        self.session.add(repo)
Pierre-Yves Chibon faa629
        self.session.commit()
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        # View the repo in the UI
Pierre-Yves Chibon faa629
        output = self.app.get('/test/branch/master')
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        # Add some content to the git repo
Pierre-Yves Chibon faa629
        tests.add_content_git_repo(
Pierre-Yves Chibon faa629
            os.path.join(tests.HERE, 'forks', 'pingou', 'test.git'))
Pierre-Yves Chibon faa629
        tests.add_readme_git_repo(
Pierre-Yves Chibon faa629
            os.path.join(tests.HERE, 'forks', 'pingou', 'test.git'))
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        output = self.app.get('/fork/pingou/test/branch/master')
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon faa629
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon faa629
        self.assertTrue('Forked from' in output.data)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon faa629
            user_id=1,  # pingou
Pierre-Yves Chibon faa629
            name='test3',
Pierre-Yves Chibon faa629
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon faa629
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbbnnn',
Pierre-Yves Chibon faa629
        )
Pierre-Yves Chibon faa629
        self.session.add(item)
Pierre-Yves Chibon faa629
        self.session.commit()
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        tests.add_content_git_repo(
Pierre-Yves Chibon faa629
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon faa629
        tests.add_readme_git_repo(
Pierre-Yves Chibon faa629
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon faa629
        tests.add_commit_git_repo(
Pierre-Yves Chibon faa629
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'),
Pierre-Yves Chibon faa629
            ncommits=10)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon faa629
        output = self.app.get('/fork/pingou/test3/branch/master')
Pierre-Yves Chibon faa629
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon faa629
        self.assertFalse('

This repo is brand new!

' in output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #3        ', output.data)
Pierre-Yves Chibon faa629
        self.assertTrue('Forked from' in output.data)
Pierre-Yves Chibon faa629
Pierre-Yves Chibon 225cb8
    def test_view_commits(self):
Pierre-Yves Chibon 225cb8
        """ Test the view_commits endpoint. """
Pierre-Yves Chibon 1279e0
        output = self.app.get('/foo/commits')
Pierre-Yves Chibon 85d878
        # No project registered in the DB
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 85d878
        tests.create_projects(self.session)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 1279e0
        output = self.app.get('/test/commits')
Pierre-Yves Chibon 85d878
        # No git repo associated
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 1279e0
        output = self.app.get('/test/commits')
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertIn('

This repo is brand new!

', output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 85d878
        # Add some content to the git repo
Pierre-Yves Chibon 85d878
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 85d878
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 1279e0
        output = self.app.get('/test/commits')
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertNotIn('

This repo is brand new!

', output.data)
Pierre-Yves Chibon efb2ec
        self.assertNotIn('Forked from', output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Ryan Lerch c3b81e
        self.assertIn('<title>Commits - test - Pagure</title>', output.data)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon a923d1
        output = self.app.get('/test/commits/master')
Pierre-Yves Chibon a923d1
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertNotIn('

This repo is brand new!

', output.data)
Pierre-Yves Chibon efb2ec
        self.assertNotIn('Forked from', output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon a923d1
Pierre-Yves Chibon 85d878
        # Turn that repo into a fork
Pierre-Yves Chibon fe5017
        repo = pagure.lib.get_project(self.session, 'test')
Pierre-Yves Chibon 85d878
        repo.parent_id = 2
farhaanbukhsh 907098
        repo.is_fork = True
Pierre-Yves Chibon 85d878
        self.session.add(repo)
Pierre-Yves Chibon 85d878
        self.session.commit()
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 85d878
        # View the repo in the UI
Pierre-Yves Chibon 1279e0
        output = self.app.get('/test/commits')
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 85d878
        # Add some content to the git repo
Pierre-Yves Chibon 85d878
        tests.add_content_git_repo(
Pierre-Yves Chibon 85d878
            os.path.join(tests.HERE, 'forks', 'pingou', 'test.git'))
Pierre-Yves Chibon 85d878
        tests.add_readme_git_repo(
Pierre-Yves Chibon 85d878
            os.path.join(tests.HERE, 'forks', 'pingou', 'test.git'))
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 1279e0
        output = self.app.get('/fork/pingou/test/commits?page=abc')
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertNotIn('

This repo is brand new!

', output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #1        ', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('Forked from', output.data)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 85d878
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 85d878
            user_id=1,  # pingou
Pierre-Yves Chibon 85d878
            name='test3',
Pierre-Yves Chibon 85d878
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon 85d878
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbbooo',
Pierre-Yves Chibon 85d878
        )
Pierre-Yves Chibon 85d878
        self.session.add(item)
Pierre-Yves Chibon 85d878
        self.session.commit()
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 85d878
        tests.add_content_git_repo(
Pierre-Yves Chibon 85d878
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon 85d878
        tests.add_readme_git_repo(
Pierre-Yves Chibon 85d878
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon 85d878
        tests.add_commit_git_repo(
Pierre-Yves Chibon 85d878
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'),
Pierre-Yves Chibon 85d878
            ncommits=10)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 1279e0
        output = self.app.get('/fork/pingou/test3/commits/fobranch')
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 85d878
Pierre-Yves Chibon 1279e0
        output = self.app.get('/fork/pingou/test3/commits')
Pierre-Yves Chibon 85d878
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertNotIn('

This repo is brand new!

', output.data)
Pierre-Yves Chibon 98f2af
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n'
Pierre-Yves Chibon 98f2af
            'test project #3        ', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('Forked from', output.data)
Pierre-Yves Chibon 85d878
Oliver Gutierrez 38f510
    def test_compare_commits(self):
Oliver Gutierrez 38f510
        """ Test the compare_commits endpoint. """
Oliver Gutierrez 9e99d9
Oliver Gutierrez 9e99d9
        # First two commits comparison
Oliver Gutierrez 9e99d9
        def compare_first_two(c1, c2):
Oliver Gutierrez 9e99d9
            # View commits comparison
Oliver Gutierrez 9e99d9
            output = self.app.get('/test/c/%s..%s' % (c2.oid.hex, c1.oid.hex))
Oliver Gutierrez 9e99d9
            self.assertEqual(output.status_code, 200)
Oliver Gutierrez 9e99d9
            self.assertIn(
Pierre-Yves Chibon 8544f4
                '<title>Diff from %s to %s - test\n - Pagure</title>'
Oliver Gutierrez 9e99d9
                % (c2.oid.hex, c1.oid.hex),
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '
%s .. %s
'
Oliver Gutierrez 9e99d9
                % (c2.oid.hex, c1.oid.hex),
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                'Commits \n      ' +
Oliver Gutierrez 9e99d9
                '
Oliver Gutierrez 9e99d9
                'class="label label-default label-pill hidden-sm-down">' +
Oliver Gutierrez 9e99d9
                '\n        2\n      ',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '' +
Oliver Gutierrez 9e99d9
                '@@ -1,2 +1,1 @@',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '- Row 0', output.data)
Oliver Gutierrez 9e99d9
            # View inverse commits comparison
Oliver Gutierrez 9e99d9
            output = self.app.get('/test/c/%s..%s' % (c1.oid.hex, c2.oid.hex))
Oliver Gutierrez 9e99d9
            self.assertEqual(output.status_code, 200)
Oliver Gutierrez 9e99d9
            self.assertIn(
Pierre-Yves Chibon 8544f4
                '<title>Diff from %s to %s - test\n - Pagure</title>' %
Oliver Gutierrez 9e99d9
                (c1.oid.hex, c2.oid.hex),
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                'Commits \n      ' +
Oliver Gutierrez 9e99d9
                '
Oliver Gutierrez 9e99d9
                'class="label label-default label-pill hidden-sm-down">' +
Oliver Gutierrez 9e99d9
                '\n        2\n      ',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '
%s .. %s
' %
Oliver Gutierrez 9e99d9
                (c1.oid.hex, c2.oid.hex),
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '' +
Oliver Gutierrez 9e99d9
                '@@ -1,1 +1,2 @@',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '+ Row 0',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
Oliver Gutierrez 9e99d9
        def compare_all(c1, c3):
Oliver Gutierrez 9e99d9
            # View commits comparison
Oliver Gutierrez 9e99d9
            output = self.app.get('/test/c/%s..%s' % (c1.oid.hex, c3.oid.hex))
Oliver Gutierrez 9e99d9
            self.assertEqual(output.status_code, 200)
Oliver Gutierrez 9e99d9
            self.assertIn(
Pierre-Yves Chibon 8544f4
                '<title>Diff from %s to %s - test\n - Pagure</title>' %
Oliver Gutierrez 9e99d9
                (c1.oid.hex, c3.oid.hex), output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '
%s .. %s
' %
Oliver Gutierrez 9e99d9
                (c1.oid.hex, c3.oid.hex),
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '' +
Pierre-Yves Chibon 3c6ab6
                '@@ -1,1 +1,2 @@',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '+ Row 0', output.data)
Oliver Gutierrez 9e99d9
            self.assertEqual(
Oliver Gutierrez 9e99d9
                output.data.count(
Oliver Gutierrez 9e99d9
                    '+ Row 0'), 2)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                'Commits \n      ' +
Oliver Gutierrez 9e99d9
                '
Oliver Gutierrez 9e99d9
                'class="label label-default label-pill hidden-sm-down">' +
Oliver Gutierrez 9e99d9
                '\n        3\n      ',
Oliver Gutierrez 9e99d9
                output.data)
Pierre-Yves Chibon 3c6ab6
            self.assertIn(
Pierre-Yves Chibon 3c6ab6
                'title="View file as of 4829cf">Å ource', output.data)
Pierre-Yves Chibon 3c6ab6
            self.assertIn(
Pierre-Yves Chibon 3c6ab6
                '
<small>file added</small>
', output.data)
Pierre-Yves Chibon 3c6ab6
Oliver Gutierrez 9e99d9
            # View inverse commits comparison
Oliver Gutierrez 9e99d9
            output = self.app.get(
Oliver Gutierrez 9e99d9
                '/test/c/%s..%s' % (c3.oid.hex, c1.oid.hex))
Oliver Gutierrez 9e99d9
            self.assertEqual(output.status_code, 200)
Oliver Gutierrez 9e99d9
            self.assertIn(
Pierre-Yves Chibon 8544f4
                '<title>Diff from %s to %s - test\n - Pagure</title>' %
Oliver Gutierrez 9e99d9
                (c3.oid.hex, c1.oid.hex), output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '
%s .. %s
' %
Oliver Gutierrez 9e99d9
                (c3.oid.hex, c1.oid.hex),
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '' +
Pierre-Yves Chibon 3c6ab6
                '@@ -1,2 +1,1 @@',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                '- Row 0',
Oliver Gutierrez 9e99d9
                output.data)
Oliver Gutierrez 9e99d9
            self.assertEqual(
Oliver Gutierrez 9e99d9
                output.data.count(
Pierre-Yves Chibon 3c6ab6
                    '- Row 0'), 1)
Oliver Gutierrez 9e99d9
            self.assertIn(
Oliver Gutierrez 9e99d9
                'Commits \n      ' +
Oliver Gutierrez 9e99d9
                '
Oliver Gutierrez 9e99d9
                'class="label label-default label-pill hidden-sm-down">' +
Oliver Gutierrez 9e99d9
                '\n        3\n      ',
Oliver Gutierrez 9e99d9
                output.data)
Pierre-Yves Chibon 3c6ab6
            self.assertIn(
Pierre-Yves Chibon 3c6ab6
                'title="View file as of 000000">Å ource', output.data)
Pierre-Yves Chibon 3c6ab6
            self.assertIn(
Pierre-Yves Chibon 3c6ab6
                '
<small>file removed</small>
', output.data)
Oliver Gutierrez 9e99d9
Oliver Gutierrez 38f510
        output = self.app.get('/foo/bar')
Oliver Gutierrez 38f510
        # No project registered in the DB
Oliver Gutierrez 38f510
        self.assertEqual(output.status_code, 404)
Oliver Gutierrez 38f510
Oliver Gutierrez 38f510
        tests.create_projects(self.session)
Oliver Gutierrez 38f510
Oliver Gutierrez 38f510
        output = self.app.get('/test/bar')
Oliver Gutierrez 38f510
        # No git repo associated
Oliver Gutierrez 38f510
        self.assertEqual(output.status_code, 404)
Oliver Gutierrez 38f510
Oliver Gutierrez 38f510
        tests.create_projects_git(tests.HERE, bare=True)
Oliver Gutierrez 38f510
Oliver Gutierrez 38f510
        output = self.app.get('/test/bar')
Oliver Gutierrez 38f510
        self.assertEqual(output.status_code, 404)
Oliver Gutierrez 38f510
Oliver Gutierrez 38f510
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Oliver Gutierrez 38f510
Oliver Gutierrez 9e99d9
        # Add one commit to git repo
Oliver Gutierrez 9e99d9
        tests.add_commit_git_repo(
Oliver Gutierrez 9e99d9
            os.path.join(tests.HERE, 'test.git'), ncommits=1)
Oliver Gutierrez 9e99d9
        c1 = repo.revparse_single('HEAD')
Oliver Gutierrez 38f510
Oliver Gutierrez 9e99d9
        # Add another commit to git repo
Oliver Gutierrez 9e99d9
        tests.add_commit_git_repo(
Oliver Gutierrez 9e99d9
            os.path.join(tests.HERE, 'test.git'), ncommits=1)
Oliver Gutierrez 38f510
        c2 = repo.revparse_single('HEAD')
Oliver Gutierrez 38f510
Oliver Gutierrez 9e99d9
        # Add one more commit to git repo
Oliver Gutierrez 9e99d9
        tests.add_commit_git_repo(
Pierre-Yves Chibon f487a0
            os.path.join(tests.HERE, 'test.git'),
Pierre-Yves Chibon f487a0
            ncommits=1, filename='Å ource')
Oliver Gutierrez 9e99d9
        c3 = repo.revparse_single('HEAD')
Oliver Gutierrez 38f510
Oliver Gutierrez 9e99d9
        compare_first_two(c1, c2)
Oliver Gutierrez 9e99d9
        compare_all(c1, c3)
Oliver Gutierrez 38f510
Oliver Gutierrez 9e99d9
        user = tests.FakeUser()
Oliver Gutierrez 38f510
        # Set user logged in
Oliver Gutierrez 38f510
        with tests.user_set(pagure.APP, user):
Oliver Gutierrez 9e99d9
            compare_first_two(c1, c2)
Oliver Gutierrez 9e99d9
            compare_all(c1, c3)
Oliver Gutierrez 38f510
Pierre-Yves Chibon c56993
    def test_view_file(self):
Pierre-Yves Chibon c56993
        """ Test the view_file endpoint. """
Pierre-Yves Chibon fee94a
        output = self.app.get('/foo/blob/foo/f/sources')
Pierre-Yves Chibon c56993
        # No project registered in the DB
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        tests.create_projects(self.session)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/foo/f/sources')
Pierre-Yves Chibon c56993
        # No git repo associated
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/foo/f/sources')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # Add some content to the git repo
Pierre-Yves Chibon c56993
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon c56993
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon c56993
        tests.add_binary_git_repo(
Pierre-Yves Chibon c56993
            os.path.join(tests.HERE, 'test.git'), 'test.jpg')
Pierre-Yves Chibon c56993
        tests.add_binary_git_repo(
Pierre-Yves Chibon c56993
            os.path.join(tests.HERE, 'test.git'), 'test_binary')
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        output = self.app.get('/test/blob/master/foofile')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View in a branch
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/master/f/sources')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertTrue('' in output.data)
Pierre-Yves Chibon c56993
        self.assertTrue(
Sayan Chowdhury 1ff55f
            ''
Pierre-Yves Chibon c56993
            in output.data)
Pierre-Yves Chibon c56993
        self.assertTrue(
Pierre-Yves Chibon c56993
            '
 bar
' in output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View what's supposed to be an image
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/master/f/test.jpg')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            'Binary files cannot be rendered.
', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            'view the raw version',
Pierre-Yves Chibon efb2ec
            output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View by commit id
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon c56993
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon c56993
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/%s/f/test.jpg' % commit.oid.hex)
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            'Binary files cannot be rendered.
', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('/f/test.jpg">view the raw version', output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View by image name -- somehow we support this
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/sources/f/test.jpg')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            'Binary files cannot be rendered.
', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('/f/test.jpg">view the raw version', output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View binary file
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/sources/f/test_binary')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 7ae126
        self.assertIn('/f/test_binary">view the raw version', output.data)
Pierre-Yves Chibon 7ae126
        self.assertTrue(
Pierre-Yves Chibon 7ae126
            'Binary files cannot be rendered.
'
Pierre-Yves Chibon 7ae126
            in output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View folder
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/master/f/folder1')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            '',
Pierre-Yves Chibon efb2ec
            output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('<title>Tree - test - Pagure</title>', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            '', output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        # View by image name -- with a non-existant file
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/sources/f/testfoo.jpg')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon fee94a
        output = self.app.get('/test/blob/master/f/folder1/testfoo.jpg')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon 17de87
        # View file with a non-ascii name
Pierre-Yves Chibon 17de87
        tests.add_commit_git_repo(
Pierre-Yves Chibon 17de87
            os.path.join(tests.HERE, 'test.git'),
Pierre-Yves Chibon 17de87
            ncommits=1, filename='Å ource')
Pierre-Yves Chibon 17de87
        output = self.app.get('/test/blob/master/f/Å ource')
Pierre-Yves Chibon 17de87
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 17de87
        self.assertIn('  Šource', output.data)
Pierre-Yves Chibon 17de87
        self.assertIn('', output.data)
Pierre-Yves Chibon 17de87
        self.assertIn(
Pierre-Yves Chibon 17de87
            '
Pierre-Yves Chibon 17de87
            'data-line-number="1">', output.data)
Pierre-Yves Chibon 7ded1e
        self.assertTrue(
Pierre-Yves Chibon 7ded1e
            '
Row 0
'
Pierre-Yves Chibon 7ded1e
            in output.data
Pierre-Yves Chibon 7ded1e
            or
Pierre-Yves Chibon 7ded1e
            '
Row 0
' in output.data
Pierre-Yves Chibon 7ded1e
        )
Pierre-Yves Chibon 17de87
Pierre-Yves Chibon c56993
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon c56993
            user_id=1,  # pingou
Pierre-Yves Chibon c56993
            name='test3',
Pierre-Yves Chibon c56993
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon c56993
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbbppp',
Pierre-Yves Chibon c56993
        )
Pierre-Yves Chibon c56993
        self.session.add(item)
Pierre-Yves Chibon c56993
        self.session.commit()
Pierre-Yves Chibon c56993
Pierre-Yves Chibon c56993
        tests.add_content_git_repo(
Pierre-Yves Chibon c56993
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon c56993
        tests.add_readme_git_repo(
Pierre-Yves Chibon c56993
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon c56993
        tests.add_commit_git_repo(
Pierre-Yves Chibon c56993
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'),
Pierre-Yves Chibon c56993
            ncommits=10)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon fee94a
        output = self.app.get('/fork/pingou/test3/blob/master/f/sources')
Pierre-Yves Chibon c56993
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon efb2ec
        self.assertIn('', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            '',
Pierre-Yves Chibon efb2ec
            output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn(
Pierre-Yves Chibon efb2ec
            '
 barRow 0
', output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon 0b62d0
    def test_view_raw_file(self):
Pierre-Yves Chibon 0b62d0
        """ Test the view_raw_file endpoint. """
Pierre-Yves Chibon 0b62d0
        output = self.app.get('/foo/raw/foo/sources')
Pierre-Yves Chibon 0b62d0
        # No project registered in the DB
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        tests.create_projects(self.session)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        output = self.app.get('/test/raw/foo/sources')
Pierre-Yves Chibon 0b62d0
        # No git repo associated
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        output = self.app.get('/test/raw/foo/sources')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # Add some content to the git repo
Pierre-Yves Chibon 0b62d0
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 79dff7
Pierre-Yves Chibon 79dff7
        # View first commit
Pierre-Yves Chibon 79dff7
        output = self.app.get('/test/raw/master')
Pierre-Yves Chibon 79dff7
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 79dff7
        self.assertTrue(':Author: Pierre-Yves Chibon' in output.data)
Pierre-Yves Chibon 79dff7
Pierre-Yves Chibon 79dff7
        # Add some more content to the repo
Pierre-Yves Chibon 79dff7
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 0b62d0
        tests.add_binary_git_repo(
Pierre-Yves Chibon 0b62d0
            os.path.join(tests.HERE, 'test.git'), 'test.jpg')
Pierre-Yves Chibon 0b62d0
        tests.add_binary_git_repo(
Pierre-Yves Chibon 0b62d0
            os.path.join(tests.HERE, 'test.git'), 'test_binary')
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 8d4122
        output = self.app.get('/test/raw/master/f/foofile')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View in a branch
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/master/f/sources')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0b62d0
        self.assertTrue('foo\n bar' in output.data)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View what's supposed to be an image
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/master/f/test.jpg')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 56a350
        self.assertTrue(output.data.startswith('\x00\x00\x01\x00'))
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View by commit id
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 0b62d0
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/%s/f/test.jpg' % commit.oid.hex)
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 56a350
        self.assertTrue(output.data.startswith('\x00\x00\x01\x00'))
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View by image name -- somehow we support this
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/sources/f/test.jpg')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 56a350
        self.assertTrue(output.data.startswith('\x00\x00\x01\x00'))
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View binary file
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/sources/f/test_binary')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 56a350
        self.assertTrue(output.data.startswith('\x00\x00\x01\x00'))
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View folder
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/master/f/folder1')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # View by image name -- with a non-existant file
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/sources/f/testfoo.jpg')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon ce7643
        output = self.app.get('/test/raw/master/f/folder1/testfoo.jpg')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 8d4122
        output = self.app.get('/test/raw/master/f/')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 8d4122
        output = self.app.get('/test/raw/master')
Pierre-Yves Chibon 8d4122
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 8d4122
        self.assertTrue(output.data.startswith(
Pierre-Yves Chibon 8d4122
            'diff --git a/test_binary b/test_binary\n'))
Pierre-Yves Chibon 8d4122
Pierre-Yves Chibon 0b62d0
        output = self.app.get('/test/raw/%s' % commit.oid.hex)
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0b62d0
        self.assertTrue(output.data.startswith(
Pierre-Yves Chibon 0b62d0
            'diff --git a/test_binary b/test_binary\n'))
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 0b62d0
            user_id=1,  # pingou
Pierre-Yves Chibon 0b62d0
            name='test3',
Pierre-Yves Chibon 0b62d0
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon 0b62d0
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbbqqq',
Pierre-Yves Chibon 0b62d0
        )
Pierre-Yves Chibon 0b62d0
        self.session.add(item)
Pierre-Yves Chibon 0b62d0
        self.session.commit()
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon 0b62d0
        tests.add_content_git_repo(
Pierre-Yves Chibon 0b62d0
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon 0b62d0
        tests.add_readme_git_repo(
Pierre-Yves Chibon 0b62d0
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
Pierre-Yves Chibon 0b62d0
        tests.add_commit_git_repo(
Pierre-Yves Chibon 0b62d0
            os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'),
Pierre-Yves Chibon 0b62d0
            ncommits=10)
Pierre-Yves Chibon 0b62d0
Pierre-Yves Chibon ce7643
        output = self.app.get('/fork/pingou/test3/raw/master/f/sources')
Pierre-Yves Chibon 0b62d0
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 0b62d0
        self.assertTrue('foo\n bar' in output.data)
Pierre-Yves Chibon c56993
Pierre-Yves Chibon 020fcf
    def test_view_commit(self):
Pierre-Yves Chibon 020fcf
        """ Test the view_commit endpoint. """
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/foo/c/bar')
Pierre-Yves Chibon 020fcf
        # No project registered in the DB
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        tests.create_projects(self.session)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/bar')
Pierre-Yves Chibon 020fcf
        # No git repo associated
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/bar')
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        # Add a README to the git repo - First commit
Pierre-Yves Chibon 020fcf
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 020fcf
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        # View first commit
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4449a5
        self.assertTrue(
Pierre-Yves Chibon 4449a5
            '
'
Pierre-Yves Chibon 4449a5
            in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Authored by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue(
Pierre-Yves Chibon fe5017
            '+ Pagure' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue(
Pierre-Yves Chibon 020fcf
            '+ ======' in output.data)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 1d1633
        # View first commit - with the old URL scheme disabled - default
Pierre-Yves Chibon bc4ec4
        output = self.app.get(
Pierre-Yves Chibon bc4ec4
            '/test/%s' % commit.oid.hex, follow_redirects=True)
Pierre-Yves Chibon bc4ec4
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon bc4ec4
        self.assertIn('

Project not found

', output.data)
Pierre-Yves Chibon 30757a
Pierre-Yves Chibon 020fcf
        # Add some content to the git repo
Pierre-Yves Chibon 020fcf
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 020fcf
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        # View another commit
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4449a5
        self.assertTrue(
Pierre-Yves Chibon 4449a5
            '
'
Pierre-Yves Chibon 4449a5
            in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Authored by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue(
Pierre-Yves Chibon 0cbbd3
            # new version of pygments
Pierre-Yves Chibon 0cbbd3
            '
'
Pierre-Yves Chibon 0cbbd3
            '
'
Pierre-Yves Chibon 0cbbd3
            ''
Pierre-Yves Chibon 0cbbd3
            ''
Pierre-Yves Chibon 0cbbd3
            '@@ -0,0 +1,3 @@' in output.data
Pierre-Yves Chibon 0cbbd3
            or
Pierre-Yves Chibon 0cbbd3
            # old version of pygments
Pierre-Yves Chibon 020fcf
            '
'
Pierre-Yves Chibon 020fcf
            '
'
Pierre-Yves Chibon 020fcf
            ''
Pierre-Yves Chibon 020fcf
            '@@ -0,0 +1,3 @@' in output.data)
Pierre-Yves Chibon 020fcf
Vivek Anand a10b3f
        #View the commit when branch name is provided
Vivek Anand a10b3f
        output = self.app.get('/test/c/%s?branch=master' % commit.oid.hex)
Vivek Anand a10b3f
        self.assertEqual(output.status_code, 200)
Vivek Anand a10b3f
        self.assertTrue(
Vivek Anand a10b3f
            ''
Vivek Anand a10b3f
            in output.data)
Vivek Anand a10b3f
Vivek Anand b85449
        #View the commit when branch name is wrong, show the commit
Vivek Anand b85449
        output = self.app.get('/test/c/%s?branch=abcxyz' % commit.oid.hex)
Vivek Anand b85449
        self.assertEqual(output.status_code, 200)
Vivek Anand b85449
        self.assertTrue(
Vivek Anand 8e8c5a
            ''
Vivek Anand b85449
            in output.data)
Vivek Anand b85449
Pierre-Yves Chibon 020fcf
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon 020fcf
            user_id=1,  # pingou
Pierre-Yves Chibon 020fcf
            name='test3',
Pierre-Yves Chibon 020fcf
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon 020fcf
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbbkkk',
Pierre-Yves Chibon 020fcf
        )
Pierre-Yves Chibon 020fcf
        self.session.add(item)
Pierre-Yves Chibon 020fcf
        self.session.commit()
Pierre-Yves Chibon 128dfb
        forkedgit = os.path.join(
Pierre-Yves Chibon 128dfb
            tests.HERE, 'forks', 'pingou', 'test3.git')
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        tests.add_content_git_repo(forkedgit)
Pierre-Yves Chibon 020fcf
        tests.add_readme_git_repo(forkedgit)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(forkedgit)
Pierre-Yves Chibon 020fcf
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        # Commit does not exist in anothe repo :)
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 020fcf
        # View commit of fork
Pierre-Yves Chibon 5bf6f1
        output = self.app.get(
Pierre-Yves Chibon 5bf6f1
            '/fork/pingou/test3/c/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 4449a5
        self.assertTrue(
Pierre-Yves Chibon 4449a5
            '
'
Pierre-Yves Chibon 4449a5
            in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Authored by Alice Author\n' in output.data)
Pierre-Yves Chibon 8544f4
        self.assertTrue('  Committed by Cecil Committer\n' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue(
Pierre-Yves Chibon fe5017
            '+ Pagure' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue(
Pierre-Yves Chibon 020fcf
            '+ ======' in output.data)
Pierre-Yves Chibon 020fcf
Pierre-Yves Chibon 30757a
        # Try the old URL scheme with a short hash
Pierre-Yves Chibon 30757a
        output = self.app.get(
Pierre-Yves Chibon 30757a
            '/fork/pingou/test3/%s' % commit.oid.hex[:10],
Pierre-Yves Chibon 30757a
            follow_redirects=True)
Pierre-Yves Chibon 30757a
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 30757a
        self.assertIn('

Project not found

', output.data)
Pierre-Yves Chibon 30757a
Vivek Anand a10b3f
        #View the commit of the fork when branch name is provided
Vivek Anand a10b3f
        output = self.app.get('/fork/pingou/test3/c/%s?branch=master' % commit.oid.hex)
Vivek Anand a10b3f
        self.assertEqual(output.status_code, 200)
Vivek Anand a10b3f
        self.assertTrue(
Vivek Anand a10b3f
            ''
Vivek Anand a10b3f
            in output.data)
Vivek Anand a10b3f
Vivek Anand b85449
        #View the commit of the fork when branch name is wrong
Vivek Anand b85449
        output = self.app.get('/fork/pingou/test3/c/%s?branch=abcxyz' % commit.oid.hex)
Vivek Anand b85449
        self.assertEqual(output.status_code, 200)
Vivek Anand b85449
        self.assertTrue(
Vivek Anand 8e8c5a
            ''
Vivek Anand b85449
            in output.data)
Vivek Anand b85449
Vivek Anand a10b3f
Pierre-Yves Chibon aa655b
    def test_view_commit_patch(self):
Pierre-Yves Chibon aa655b
        """ Test the view_commit_patch endpoint. """
Pierre-Yves Chibon 5bf6f1
Pierre-Yves Chibon aa655b
        # No project registered in the DB
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/foo/c/bar.patch')
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        tests.create_projects(self.session)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/bar.patch')
Pierre-Yves Chibon aa655b
        # No git repo associated
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/bar.patch')
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # Add a README to the git repo - First commit
Pierre-Yves Chibon aa655b
        tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon aa655b
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # View first commit
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/%s.patch' % commit.oid.hex)
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon aa655b
        self.assertTrue('''diff --git a/README.rst b/README.rst
Pierre-Yves Chibon aa655b
new file mode 100644
Pierre-Yves Chibon fe5017
index 0000000..fb7093d
Pierre-Yves Chibon aa655b
--- /dev/null
Pierre-Yves Chibon aa655b
+++ b/README.rst
Pierre-Yves Chibon fe5017
@@ -0,0 +1,16 @@
Pierre-Yves Chibon fe5017
+Pagure
Pierre-Yves Chibon aa655b
+======
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+:Author: Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon fe5017
+Pagure is a light-weight git-centered forge based on pygit2.
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon fe5017
+Currently, Pagure offers a web-interface for git repositories, a ticket
Pierre-Yves Chibon fe5017
+system and possibilities to create new projects, fork existing ones and
Pierre-Yves Chibon fe5017
+create/merge pull-requests across or within projects.
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon fe5017
+Homepage: https://github.com/pypingou/pagure
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+Dev instance: http://209.132.184.222/ (/!\ May change unexpectedly, it's a dev instance ;-))
Pierre-Yves Chibon aa655b
''' in output.data)
Pierre-Yves Chibon aa655b
        self.assertTrue('Subject: Add a README file' in output.data)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # Add some content to the git repo
Pierre-Yves Chibon aa655b
        tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
Pierre-Yves Chibon aa655b
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # View another commit
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/%s.patch' % commit.oid.hex)
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon aa655b
        self.assertTrue(
Pierre-Yves Chibon aa655b
            'Subject: Add some directory and a file for more testing'
Pierre-Yves Chibon aa655b
            in output.data)
Pierre-Yves Chibon aa655b
        self.assertTrue('''diff --git a/folder1/folder2/file b/folder1/folder2/file
Pierre-Yves Chibon aa655b
new file mode 100644
Pierre-Yves Chibon aa655b
index 0000000..11980b1
Pierre-Yves Chibon aa655b
--- /dev/null
Pierre-Yves Chibon aa655b
+++ b/folder1/folder2/file
Pierre-Yves Chibon aa655b
@@ -0,0 +1,3 @@
Pierre-Yves Chibon aa655b
+foo
Pierre-Yves Chibon aa655b
+ bar
Pierre-Yves Chibon aa655b
+baz
Pierre-Yves Chibon aa655b
\ No newline at end of file
Pierre-Yves Chibon aa655b
''' in output.data)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # Add a fork of a fork
Pierre-Yves Chibon fe5017
        item = pagure.lib.model.Project(
Pierre-Yves Chibon aa655b
            user_id=1,  # pingou
Pierre-Yves Chibon aa655b
            name='test3',
Pierre-Yves Chibon aa655b
            description='test project #3',
farhaanbukhsh 907098
            is_fork=True,
Pierre-Yves Chibon aa655b
            parent_id=1,
Pierre-Yves Chibon e2259d
            hook_token='aaabbblll',
Pierre-Yves Chibon aa655b
        )
Pierre-Yves Chibon aa655b
        self.session.add(item)
Pierre-Yves Chibon aa655b
        self.session.commit()
Pierre-Yves Chibon aa655b
        forkedgit = os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git')
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        tests.add_content_git_repo(forkedgit)
Pierre-Yves Chibon aa655b
        tests.add_readme_git_repo(forkedgit)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon 128dfb
        repo = pygit2.Repository(forkedgit)
Pierre-Yves Chibon aa655b
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # Commit does not exist in anothe repo :)
Pierre-Yves Chibon 5bf6f1
        output = self.app.get('/test/c/%s.patch' % commit.oid.hex)
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon aa655b
        # View commit of fork
Pierre-Yves Chibon 5bf6f1
        output = self.app.get(
Pierre-Yves Chibon 5bf6f1
            '/fork/pingou/test3/c/%s.patch' % commit.oid.hex)
Pierre-Yves Chibon aa655b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon aa655b
        self.assertTrue('''diff --git a/README.rst b/README.rst
Pierre-Yves Chibon aa655b
new file mode 100644
Pierre-Yves Chibon fe5017
index 0000000..fb7093d
Pierre-Yves Chibon aa655b
--- /dev/null
Pierre-Yves Chibon aa655b
+++ b/README.rst
Pierre-Yves Chibon fe5017
@@ -0,0 +1,16 @@
Pierre-Yves Chibon fe5017
+Pagure
Pierre-Yves Chibon aa655b
+======
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+:Author: Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon fe5017
+Pagure is a light-weight git-centered forge based on pygit2.
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon fe5017
+Currently, Pagure offers a web-interface for git repositories, a ticket
Pierre-Yves Chibon fe5017
+system and possibilities to create new projects, fork existing ones and
Pierre-Yves Chibon fe5017
+create/merge pull-requests across or within projects.
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon fe5017
+Homepage: https://github.com/pypingou/pagure
Pierre-Yves Chibon aa655b
+
Pierre-Yves Chibon aa655b
+Dev instance: http://209.132.184.222/ (/!\ May change unexpectedly, it's a dev instance ;-))
Pierre-Yves Chibon aa655b
''' in output.data)
Pierre-Yves Chibon aa655b
Pierre-Yves Chibon 027b38
    def test_view_tree(self):
Pierre-Yves Chibon 027b38
        """ Test the view_tree endpoint. """
Pierre-Yves Chibon 027b38
        output = self.app.get('/foo/tree/')
Pierre-Yves Chibon 027b38
        # No project registered in the DB
Pierre-Yves Chibon 027b38
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 027b38
Pierre-Yves Chibon 027b38
        tests.create_projects(self.session)
Pierre-Yves Chibon 027b38
Pierre-Yves Chibon 027b38
        output = self.app.get('/test/tree/')
Pierre-Yves Chibon 027b38
        # No git repo associated
Pierre-Yves Chibon 027b38
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 027b38
Pierre-Yves Chibon 128dfb
        tests.create_projects_git(tests.HERE, bare=True)
Pierre-Yves Chibon 027b38
Pierre-Yves Chibon 027b38
        output = self.app.get('/test/tree/')
Pierre-Yves Chibon 027b38
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 557220
        self.assertIn(
Pierre-Yves Chibon 557220
            '''
Pierre-Yves Chibon 557220
        
    Pierre-Yves Chibon 557220
              
  1. Pierre-Yves Chibon 557220
                
    Pierre-Yves Chibon 557220
                  
    Pierre-Yves Chibon 557220
                    None
    Pierre-Yves Chibon 557220
                
    Pierre-Yves Chibon 557220
              
    Pierre-Yves Chibon 557220
            ''', output.data)
    Pierre-Yves Chibon 027b38
            self.assertTrue(
    Pierre-Yves Chibon 027b38
                'No content found in this repository' in output.data)
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 027b38
            # Add a README to the git repo - First commit
    Pierre-Yves Chibon 027b38
            tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 128dfb
            repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 027b38
            commit = repo.revparse_single('HEAD')
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 027b38
            # View first commit
    Pierre-Yves Chibon 027b38
            output = self.app.get('/test/tree/%s' % commit.oid.hex)
    Pierre-Yves Chibon 027b38
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 98f2af
            self.assertIn(
    Pierre-Yves Chibon 98f2af
                '
    \n'
    Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
    Pierre-Yves Chibon efb2ec
            self.assertIn('<title>Tree - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 027b38
            self.assertTrue('README.rst' in output.data)
    Pierre-Yves Chibon 027b38
            self.assertFalse(
    Pierre-Yves Chibon 027b38
                'No content found in this repository' in output.data)
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 027b38
            # View tree by branch
    Pierre-Yves Chibon 027b38
            output = self.app.get('/test/tree/master')
    Pierre-Yves Chibon 027b38
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 98f2af
            self.assertIn(
    Pierre-Yves Chibon 98f2af
                '
    \n'
    Pierre-Yves Chibon 98f2af
                'test project #1        ', output.data)
    Pierre-Yves Chibon efb2ec
            self.assertIn('<title>Tree - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 027b38
            self.assertTrue('README.rst' in output.data)
    Pierre-Yves Chibon 027b38
            self.assertFalse(
    Pierre-Yves Chibon 027b38
                'No content found in this repository' in output.data)
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 027b38
            # Add a fork of a fork
    Pierre-Yves Chibon fe5017
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon 027b38
                user_id=1,  # pingou
    Pierre-Yves Chibon 027b38
                name='test3',
    Pierre-Yves Chibon 027b38
                description='test project #3',
    farhaanbukhsh 907098
                is_fork=True,
    Pierre-Yves Chibon 027b38
                parent_id=1,
    Pierre-Yves Chibon e2259d
                hook_token='aaabbbfff',
    Pierre-Yves Chibon 027b38
            )
    Pierre-Yves Chibon 027b38
            self.session.add(item)
    Pierre-Yves Chibon 027b38
            self.session.commit()
    Pierre-Yves Chibon 027b38
            forkedgit = os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git')
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 027b38
            tests.add_content_git_repo(forkedgit)
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 027b38
            output = self.app.get('/fork/pingou/test3/tree/')
    Pierre-Yves Chibon 027b38
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 98f2af
            self.assertIn(
    Pierre-Yves Chibon 98f2af
                '
    \n'
    Pierre-Yves Chibon 98f2af
                'test project #3        ', output.data)
    Pierre-Yves Chibon efb2ec
            self.assertIn('<title>Tree - test3 - Pagure</title>', output.data)
    Pierre-Yves Chibon 027b38
            self.assertTrue(
    Pierre-Yves Chibon fee94a
                ''
    Pierre-Yves Chibon 027b38
                in output.data)
    Pierre-Yves Chibon 027b38
            self.assertTrue(
    Pierre-Yves Chibon fee94a
                ''
    Pierre-Yves Chibon 027b38
                in output.data)
    Pierre-Yves Chibon 027b38
            self.assertFalse(
    Pierre-Yves Chibon 027b38
                'No content found in this repository' in output.data)
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon 557220
            output = self.app.get(
    Pierre-Yves Chibon 557220
                '/fork/pingou/test3/blob/master/f/folder1/folder2')
    Pierre-Yves Chibon 557220
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 557220
            self.assertTrue(
    Pierre-Yves Chibon 557220
                '
    Pierre-Yves Chibon 557220
                'f/folder1/folder2/file%C5%A0">' in output.data)
    Pierre-Yves Chibon 557220
    Vivek Anand 3b0299
    Vivek Anand 3b0299
        @patch('pagure.lib.notify.send_email')
    Vivek Anand 3b0299
        @patch('pagure.ui.repo.admin_session_timedout')
    Vivek Anand 3b0299
        def test_delete_repo_when_turned_off(self, ast, send_email):
    Vivek Anand 3b0299
            """ Test the delete_repo endpoint when deletion of a repo is
    Vivek Anand 3b0299
            turned off in the pagure instance """
    Vivek Anand 3b0299
            ast.return_value = False
    Vivek Anand 3b0299
            send_email.return_value = True
    Vivek Anand 3b0299
            pagure.APP.config['ENABLE_DEL_PROJECTS'] = False
    Vivek Anand 3b0299
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Vivek Anand 3b0299
            output = self.app.post('/foo/delete')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
            user = tests.FakeUser(username='pingou')
    Vivek Anand 3b0299
            with tests.user_set(pagure.APP, user):
    Vivek Anand 3b0299
                tests.create_projects(self.session)
    Pierre-Yves Chibon 3f60e3
                tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 3f60e3
    Vivek Anand 3b0299
                output = self.app.post('/test/delete', follow_redirects=True)
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 404)
    Vivek Anand 3b0299
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/delete')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon 3f60e3
            with tests.user_set(pagure.APP, user):
    Vivek Anand 3b0299
                # Only git repo
    Vivek Anand 3b0299
                item = pagure.lib.model.Project(
    Vivek Anand 3b0299
                    user_id=1,  # pingou
    Vivek Anand 3b0299
                    name='test',
    Vivek Anand 3b0299
                    description='test project #1',
    Vivek Anand 3b0299
                    hook_token='aaabbbggg',
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.add(item)
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                output = self.app.post('/test/delete', follow_redirects=True)
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 404)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Only git and doc repo
    Vivek Anand 3b0299
                item = pagure.lib.model.Project(
    Vivek Anand 3b0299
                    user_id=1,  # pingou
    Vivek Anand 3b0299
                    name='test',
    Vivek Anand 3b0299
                    description='test project #1',
    Vivek Anand 3b0299
                    hook_token='aaabbbhhh',
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.add(item)
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                tests.create_projects_git(tests.HERE)
    Vivek Anand 3b0299
                tests.create_projects_git(os.path.join(tests.HERE, 'docs'))
    Vivek Anand 3b0299
                output = self.app.post('/test/delete', follow_redirects=True)
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 404)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # All repo there
    Vivek Anand 3b0299
                item = pagure.lib.model.Project(
    Vivek Anand 3b0299
                    user_id=1,  # pingou
    Vivek Anand 3b0299
                    name='test',
    Vivek Anand 3b0299
                    description='test project #1',
    Vivek Anand 3b0299
                    hook_token='aaabbbiii',
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.add(item)
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Create all the git repos
    Vivek Anand 3b0299
                tests.create_projects_git(tests.HERE)
    Vivek Anand 3b0299
                tests.create_projects_git(os.path.join(tests.HERE, 'docs'))
    Vivek Anand 3b0299
                tests.create_projects_git(
    Vivek Anand 3b0299
                    os.path.join(tests.HERE, 'tickets'), bare=True)
    Vivek Anand 3b0299
                tests.create_projects_git(
    Vivek Anand 3b0299
                    os.path.join(tests.HERE, 'requests'), bare=True)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Check repo was created
    Vivek Anand 3b0299
                output = self.app.get('/')
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 200)
    Vivek Anand 3b0299
                self.assertIn(
    Vivek Anand 3b0299
                    '
    \n My Projects
    Vivek Anand 3b0299
                    'class="label label-default">5', output.data)
    Vivek Anand 3b0299
                self.assertIn(
    Vivek Anand 3b0299
                    'Forks 0',
    Vivek Anand 3b0299
                    output.data)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # add issues
    Vivek Anand 3b0299
                repo = pagure.lib.get_project(self.session, 'test')
    Vivek Anand 3b0299
                msg = pagure.lib.new_issue(
    Vivek Anand 3b0299
                    session=self.session,
    Vivek Anand 3b0299
                    repo=repo,
    Vivek Anand 3b0299
                    title='Test issue',
    Vivek Anand 3b0299
                    content='We should work on this',
    Vivek Anand 3b0299
                    user='pingou',
    Vivek Anand 3b0299
                    ticketfolder=os.path.join(tests.HERE, 'tickets')
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                self.assertEqual(msg.title, 'Test issue')
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                msg = pagure.lib.new_issue(
    Vivek Anand 3b0299
                    session=self.session,
    Vivek Anand 3b0299
                    repo=repo,
    Vivek Anand 3b0299
                    title='Test issue #2',
    Vivek Anand 3b0299
                    content='We should work on this, really',
    Vivek Anand 3b0299
                    user='pingou',
    Vivek Anand 3b0299
                    ticketfolder=os.path.join(tests.HERE, 'tickets')
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                self.assertEqual(msg.title, 'Test issue #2')
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Add a comment to an issue
    Vivek Anand 3b0299
                issue = pagure.lib.search_issues(self.session, repo, issueid=1)
    Vivek Anand 3b0299
                msg = pagure.lib.add_issue_comment(
    Vivek Anand 3b0299
                    session=self.session,
    Vivek Anand 3b0299
                    issue=issue,
    Vivek Anand 3b0299
                    comment='Hey look a comment!',
    Vivek Anand 3b0299
                    user='foo',
    Vivek Anand 3b0299
                    ticketfolder=None
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                self.assertEqual(msg, 'Comment added')
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # add pull-requests
    Vivek Anand 3b0299
                req = pagure.lib.new_pull_request(
    Vivek Anand 3b0299
                    session=self.session,
    Vivek Anand 3b0299
                    repo_from=repo,
    Vivek Anand 3b0299
                    branch_from='feature',
    Vivek Anand 3b0299
                    repo_to=repo,
    Vivek Anand 3b0299
                    branch_to='master',
    Vivek Anand 3b0299
                    title='test pull-request',
    Vivek Anand 3b0299
                    user='pingou',
    Vivek Anand 3b0299
                    requestfolder=os.path.join(tests.HERE, 'requests'),
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                self.assertEqual(req.id, 3)
    Vivek Anand 3b0299
                self.assertEqual(req.title, 'test pull-request')
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                req = pagure.lib.new_pull_request(
    Vivek Anand 3b0299
                    session=self.session,
    Vivek Anand 3b0299
                    repo_from=repo,
    Vivek Anand 3b0299
                    branch_from='feature2',
    Vivek Anand 3b0299
                    repo_to=repo,
    Vivek Anand 3b0299
                    branch_to='master',
    Vivek Anand 3b0299
                    title='test pull-request',
    Vivek Anand 3b0299
                    user='pingou',
    Vivek Anand 3b0299
                    requestfolder=os.path.join(tests.HERE, 'requests'),
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                self.assertEqual(req.id, 4)
    Vivek Anand 3b0299
                self.assertEqual(req.title, 'test pull-request')
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Add comment on a pull-request
    Vivek Anand 3b0299
                request = pagure.lib.search_pull_requests(
    Vivek Anand 3b0299
                    self.session, requestid=3)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                msg = pagure.lib.add_pull_request_comment(
    Vivek Anand 3b0299
                    session=self.session,
    Vivek Anand 3b0299
                    request=request,
    Vivek Anand 3b0299
                    commit='commithash',
    Vivek Anand 3b0299
                    tree_id=None,
    Vivek Anand 3b0299
                    filename='file',
    Vivek Anand 3b0299
                    row=None,
    Vivek Anand 3b0299
                    comment='This is awesome, I got to remember it!',
    Vivek Anand 3b0299
                    user='foo',
    Vivek Anand 3b0299
                    requestfolder=None,
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.assertEqual(msg, 'Comment added')
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Check before deleting the project
    Vivek Anand 3b0299
                output = self.app.get('/')
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 200)
    Vivek Anand 3b0299
                self.assertIn(
    Vivek Anand 3b0299
                    '
    \n My Projects
    Vivek Anand 3b0299
                    'class="label label-default">5', output.data)
    Vivek Anand 3b0299
                self.assertIn(
    Vivek Anand 3b0299
                    'Forks 0',
    Vivek Anand 3b0299
                    output.data)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                output = self.app.post('/test/delete', follow_redirects=True)
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 404)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                repo = pagure.lib.get_project(self.session, 'test')
    Vivek Anand 3b0299
                self.assertNotEqual(repo, None)
    Vivek Anand 3b0299
                repo = pagure.lib.get_project(self.session, 'test2')
    Vivek Anand 3b0299
                self.assertNotEqual(repo, None)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Add a fork of a fork
    Vivek Anand 3b0299
                item = pagure.lib.model.Project(
    Vivek Anand 3b0299
                    user_id=1,  # pingou
    Vivek Anand 3b0299
                    name='test3',
    Vivek Anand 3b0299
                    description='test project #3',
    farhaanbukhsh 907098
                    is_fork=True,
    Vivek Anand 3b0299
                    parent_id=2,
    Vivek Anand 3b0299
                    hook_token='aaabbbjjj',
    Vivek Anand 3b0299
                )
    Vivek Anand 3b0299
                self.session.add(item)
    Vivek Anand 3b0299
                self.session.commit()
    Vivek Anand 3b0299
                tests.add_content_git_repo(
    Vivek Anand 3b0299
                    os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
    Vivek Anand 3b0299
                tests.add_content_git_repo(
    Vivek Anand 3b0299
                    os.path.join(tests.HERE, 'docs', 'pingou', 'test3.git'))
    Vivek Anand 3b0299
                tests.add_content_git_repo(
    Vivek Anand 3b0299
                    os.path.join(tests.HERE, 'tickets', 'pingou', 'test3.git'))
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                # Check before deleting the fork
    Vivek Anand 3b0299
                output = self.app.get('/')
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 200)
    Vivek Anand 3b0299
                self.assertIn(
    Vivek Anand 3b0299
                    '
    \n My Projects
    Vivek Anand 3b0299
                    'class="label label-default">5', output.data)
    Vivek Anand 3b0299
                self.assertIn(
    Vivek Anand 3b0299
                    'Forks 1',
    Vivek Anand 3b0299
                    output.data)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
                output = self.app.post(
    Vivek Anand 3b0299
                    '/fork/pingou/test3/delete', follow_redirects=True)
    Vivek Anand 3b0299
                self.assertEqual(output.status_code, 404)
    Vivek Anand 3b0299
    Vivek Anand 3b0299
            pagure.APP.config['ENABLE_DEL_PROJECTS'] = True
    Vivek Anand 3b0299
    Vivek Anand 3b0299
    Pierre-Yves Chibon 1e42d7
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 116cb7
        @patch('pagure.ui.repo.admin_session_timedout')
    Pierre-Yves Chibon 1e42d7
        def test_delete_repo(self, ast, send_email):
    Pierre-Yves Chibon 550d2b
            """ Test the delete_repo endpoint. """
    Pierre-Yves Chibon 116cb7
            ast.return_value = False
    Pierre-Yves Chibon 1e42d7
            send_email.return_value = True
    Pierre-Yves Chibon 116cb7
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Pierre-Yves Chibon 550d2b
            output = self.app.post('/foo/delete')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
            user = tests.FakeUser()
    Pierre-Yves Chibon fe5017
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 550d2b
                tests.create_projects(self.session)
    Pierre-Yves Chibon 3f60e3
                tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 3f60e3
                # No project registered in the DB (no git repo)
    Pierre-Yves Chibon 3f60e3
                output = self.app.post('/foo/delete')
    Pierre-Yves Chibon 72ed6b
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon d824d1
                # User not allowed
    Pierre-Yves Chibon d824d1
                output = self.app.post('/test/delete')
    Pierre-Yves Chibon d824d1
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon d824d1
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/delete')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon 550d2b
            user = tests.FakeUser(username='pingou')
    Pierre-Yves Chibon fe5017
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 72ed6b
                tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 72ed6b
    Pierre-Yves Chibon 116cb7
                ast.return_value = True
    Pierre-Yves Chibon 116cb7
                output = self.app.post('/test/delete')
    Pierre-Yves Chibon 116cb7
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 116cb7
                ast.return_value = False
    Pierre-Yves Chibon 72ed6b
    Pierre-Yves Chibon 550d2b
                output = self.app.post('/test/delete', follow_redirects=True)
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Could not delete all the '
    Pierre-Yves Chibon efb2ec
                    'repos from the system', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    '
    \n Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 0',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
                # Only git repo
    Pierre-Yves Chibon fe5017
                item = pagure.lib.model.Project(
    Pierre-Yves Chibon 550d2b
                    user_id=1,  # pingou
    Pierre-Yves Chibon 550d2b
                    name='test',
    Pierre-Yves Chibon 550d2b
                    description='test project #1',
    Pierre-Yves Chibon e2259d
                    hook_token='aaabbbggg',
    Pierre-Yves Chibon 550d2b
                )
    Pierre-Yves Chibon 550d2b
                self.session.add(item)
    Pierre-Yves Chibon 550d2b
                self.session.commit()
    Pierre-Yves Chibon 550d2b
                tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 72ed6b
    Pierre-Yves Chibon 550d2b
                output = self.app.post('/test/delete', follow_redirects=True)
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 550d2b
                self.assertTrue(
    Pierre-Yves Chibon efb2ec
                    '\n                      Could not delete all the '
    Pierre-Yves Chibon efb2ec
                    'repos from the system' in output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    '
    \n Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 0',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
                # Only git and doc repo
    Pierre-Yves Chibon fe5017
                item = pagure.lib.model.Project(
    Pierre-Yves Chibon 550d2b
                    user_id=1,  # pingou
    Pierre-Yves Chibon 550d2b
                    name='test',
    Pierre-Yves Chibon 550d2b
                    description='test project #1',
    Pierre-Yves Chibon e2259d
                    hook_token='aaabbbhhh',
    Pierre-Yves Chibon 550d2b
                )
    Pierre-Yves Chibon 550d2b
                self.session.add(item)
    Pierre-Yves Chibon 550d2b
                self.session.commit()
    Pierre-Yves Chibon 550d2b
                tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 550d2b
                tests.create_projects_git(os.path.join(tests.HERE, 'docs'))
    Pierre-Yves Chibon 550d2b
                output = self.app.post('/test/delete', follow_redirects=True)
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 550d2b
                self.assertTrue(
    Pierre-Yves Chibon efb2ec
                    '\n                      Could not delete all the '
    Pierre-Yves Chibon efb2ec
                    'repos from the system' in output.data)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
                # All repo there
    Pierre-Yves Chibon fe5017
                item = pagure.lib.model.Project(
    Pierre-Yves Chibon 550d2b
                    user_id=1,  # pingou
    Pierre-Yves Chibon 550d2b
                    name='test',
    Pierre-Yves Chibon 550d2b
                    description='test project #1',
    Pierre-Yves Chibon e2259d
                    hook_token='aaabbbiii',
    Pierre-Yves Chibon 550d2b
                )
    Pierre-Yves Chibon 550d2b
                self.session.add(item)
    Pierre-Yves Chibon 550d2b
                self.session.commit()
    Pierre-Yves Chibon 8a488f
    Pierre-Yves Chibon 8a488f
                # Create all the git repos
    Pierre-Yves Chibon 550d2b
                tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 550d2b
                tests.create_projects_git(os.path.join(tests.HERE, 'docs'))
    Pierre-Yves Chibon 97e4e8
                tests.create_projects_git(
    Pierre-Yves Chibon 97e4e8
                    os.path.join(tests.HERE, 'tickets'), bare=True)
    Pierre-Yves Chibon 97e4e8
                tests.create_projects_git(
    Pierre-Yves Chibon 97e4e8
                    os.path.join(tests.HERE, 'requests'), bare=True)
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon fb5b9d
                # Check repo was created
    Pierre-Yves Chibon fb5b9d
                output = self.app.get('/')
    Pierre-Yves Chibon fb5b9d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon fb5b9d
                self.assertIn(
    Pierre-Yves Chibon 8a488f
                    '
    \n My Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">2', output.data)
    Pierre-Yves Chibon fb5b9d
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 0',
    Pierre-Yves Chibon fb5b9d
                    output.data)
    Pierre-Yves Chibon fb5b9d
    Pierre-Yves Chibon 97e4e8
                # add issues
    Pierre-Yves Chibon 97e4e8
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 97e4e8
                msg = pagure.lib.new_issue(
    Pierre-Yves Chibon 97e4e8
                    session=self.session,
    Pierre-Yves Chibon 97e4e8
                    repo=repo,
    Pierre-Yves Chibon 97e4e8
                    title='Test issue',
    Pierre-Yves Chibon 97e4e8
                    content='We should work on this',
    Pierre-Yves Chibon 97e4e8
                    user='pingou',
    Pierre-Yves Chibon 97e4e8
                    ticketfolder=os.path.join(tests.HERE, 'tickets')
    Pierre-Yves Chibon 97e4e8
                )
    Pierre-Yves Chibon 97e4e8
                self.session.commit()
    Pierre-Yves Chibon 97e4e8
                self.assertEqual(msg.title, 'Test issue')
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon 97e4e8
                msg = pagure.lib.new_issue(
    Pierre-Yves Chibon 97e4e8
                    session=self.session,
    Pierre-Yves Chibon 97e4e8
                    repo=repo,
    Pierre-Yves Chibon 97e4e8
                    title='Test issue #2',
    Pierre-Yves Chibon 97e4e8
                    content='We should work on this, really',
    Pierre-Yves Chibon 97e4e8
                    user='pingou',
    Pierre-Yves Chibon 97e4e8
                    ticketfolder=os.path.join(tests.HERE, 'tickets')
    Pierre-Yves Chibon 97e4e8
                )
    Pierre-Yves Chibon 97e4e8
                self.session.commit()
    Pierre-Yves Chibon 97e4e8
                self.assertEqual(msg.title, 'Test issue #2')
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon 97e4e8
                # Add a comment to an issue
    Pierre-Yves Chibon 97e4e8
                issue = pagure.lib.search_issues(self.session, repo, issueid=1)
    Pierre-Yves Chibon 97e4e8
                msg = pagure.lib.add_issue_comment(
    Pierre-Yves Chibon 97e4e8
                    session=self.session,
    Pierre-Yves Chibon 97e4e8
                    issue=issue,
    Pierre-Yves Chibon 97e4e8
                    comment='Hey look a comment!',
    Pierre-Yves Chibon 97e4e8
                    user='foo',
    Pierre-Yves Chibon 97e4e8
                    ticketfolder=None
    Pierre-Yves Chibon 97e4e8
                )
    Pierre-Yves Chibon 97e4e8
                self.session.commit()
    Pierre-Yves Chibon 97e4e8
                self.assertEqual(msg, 'Comment added')
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon 97e4e8
                # add pull-requests
    Pierre-Yves Chibon f9c5f9
                req = pagure.lib.new_pull_request(
    Pierre-Yves Chibon 97e4e8
                    session=self.session,
    Pierre-Yves Chibon 97e4e8
                    repo_from=repo,
    Pierre-Yves Chibon 97e4e8
                    branch_from='feature',
    Pierre-Yves Chibon 97e4e8
                    repo_to=repo,
    Pierre-Yves Chibon 97e4e8
                    branch_to='master',
    Pierre-Yves Chibon 97e4e8
                    title='test pull-request',
    Pierre-Yves Chibon 97e4e8
                    user='pingou',
    Pierre-Yves Chibon 97e4e8
                    requestfolder=os.path.join(tests.HERE, 'requests'),
    Pierre-Yves Chibon 97e4e8
                )
    Pierre-Yves Chibon 97e4e8
                self.session.commit()
    Pierre-Yves Chibon f9c5f9
                self.assertEqual(req.id, 3)
    Pierre-Yves Chibon f9c5f9
                self.assertEqual(req.title, 'test pull-request')
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon f9c5f9
                req = pagure.lib.new_pull_request(
    Pierre-Yves Chibon 97e4e8
                    session=self.session,
    Pierre-Yves Chibon 97e4e8
                    repo_from=repo,
    Pierre-Yves Chibon 97e4e8
                    branch_from='feature2',
    Pierre-Yves Chibon 97e4e8
                    repo_to=repo,
    Pierre-Yves Chibon 97e4e8
                    branch_to='master',
    Pierre-Yves Chibon 97e4e8
                    title='test pull-request',
    Pierre-Yves Chibon 97e4e8
                    user='pingou',
    Pierre-Yves Chibon 97e4e8
                    requestfolder=os.path.join(tests.HERE, 'requests'),
    Pierre-Yves Chibon 97e4e8
                )
    Pierre-Yves Chibon 97e4e8
                self.session.commit()
    Pierre-Yves Chibon f9c5f9
                self.assertEqual(req.id, 4)
    Pierre-Yves Chibon f9c5f9
                self.assertEqual(req.title, 'test pull-request')
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon 97e4e8
                # Add comment on a pull-request
    Pierre-Yves Chibon 97e4e8
                request = pagure.lib.search_pull_requests(
    Pierre-Yves Chibon 97e4e8
                    self.session, requestid=3)
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon 97e4e8
                msg = pagure.lib.add_pull_request_comment(
    Pierre-Yves Chibon 97e4e8
                    session=self.session,
    Pierre-Yves Chibon 97e4e8
                    request=request,
    Pierre-Yves Chibon 97e4e8
                    commit='commithash',
    Pierre-Yves Chibon c18b96
                    tree_id=None,
    Pierre-Yves Chibon 97e4e8
                    filename='file',
    Pierre-Yves Chibon 97e4e8
                    row=None,
    Pierre-Yves Chibon 97e4e8
                    comment='This is awesome, I got to remember it!',
    Pierre-Yves Chibon 97e4e8
                    user='foo',
    Pierre-Yves Chibon 97e4e8
                    requestfolder=None,
    Pierre-Yves Chibon 97e4e8
                )
    Pierre-Yves Chibon 97e4e8
                self.assertEqual(msg, 'Comment added')
    Pierre-Yves Chibon 97e4e8
    Pierre-Yves Chibon fb5b9d
                # Check before deleting the project
    Pierre-Yves Chibon fb5b9d
                output = self.app.get('/')
    Pierre-Yves Chibon fb5b9d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon fb5b9d
                self.assertIn(
    Pierre-Yves Chibon 8a488f
                    '
    \n My Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">2', output.data)
    Pierre-Yves Chibon fb5b9d
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 0',
    Pierre-Yves Chibon fb5b9d
                    output.data)
    Pierre-Yves Chibon fb5b9d
    Pierre-Yves Chibon 550d2b
                output = self.app.post('/test/delete', follow_redirects=True)
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    '
    \n Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 0',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 52c8a4
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 52c8a4
                self.assertEqual(repo, None)
    Pierre-Yves Chibon 52c8a4
                repo = pagure.lib.get_project(self.session, 'test2')
    Pierre-Yves Chibon 52c8a4
                self.assertNotEqual(repo, None)
    Pierre-Yves Chibon 52c8a4
    Pierre-Yves Chibon 550d2b
                # Add a fork of a fork
    Pierre-Yves Chibon fe5017
                item = pagure.lib.model.Project(
    Pierre-Yves Chibon 550d2b
                    user_id=1,  # pingou
    Pierre-Yves Chibon 550d2b
                    name='test3',
    Pierre-Yves Chibon 550d2b
                    description='test project #3',
    farhaanbukhsh 907098
                    is_fork=True,
    Pierre-Yves Chibon 52c8a4
                    parent_id=2,
    Pierre-Yves Chibon e2259d
                    hook_token='aaabbbjjj',
    Pierre-Yves Chibon 550d2b
                )
    Pierre-Yves Chibon 550d2b
                self.session.add(item)
    Pierre-Yves Chibon 550d2b
                self.session.commit()
    Pierre-Yves Chibon 550d2b
                tests.add_content_git_repo(
    Pierre-Yves Chibon 550d2b
                    os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
    Pierre-Yves Chibon 550d2b
                tests.add_content_git_repo(
    Pierre-Yves Chibon 550d2b
                    os.path.join(tests.HERE, 'docs', 'pingou', 'test3.git'))
    Pierre-Yves Chibon 550d2b
                tests.add_content_git_repo(
    Pierre-Yves Chibon 550d2b
                    os.path.join(tests.HERE, 'tickets', 'pingou', 'test3.git'))
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon fb5b9d
                # Check before deleting the fork
    Pierre-Yves Chibon fb5b9d
                output = self.app.get('/')
    Pierre-Yves Chibon fb5b9d
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon fb5b9d
                self.assertIn(
    Pierre-Yves Chibon 8a488f
                    '
    \n My Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">1', output.data)
    Pierre-Yves Chibon fb5b9d
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 1',
    Pierre-Yves Chibon fb5b9d
                    output.data)
    Pierre-Yves Chibon fb5b9d
    Pierre-Yves Chibon 550d2b
                output = self.app.post(
    Pierre-Yves Chibon 550d2b
                    '/fork/pingou/test3/delete', follow_redirects=True)
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    '
    \n Projects
    Pierre-Yves Chibon fb5b9d
                    'class="label label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon fb5b9d
                    'Forks 0',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 027b38
    Pierre-Yves Chibon a8f15b
        @patch('pagure.ui.repo.admin_session_timedout')
    Pierre-Yves Chibon a8f15b
        def test_new_repo_hook_token(self, ast):
    Pierre-Yves Chibon a8f15b
            """ Test the new_repo_hook_token endpoint. """
    Pierre-Yves Chibon a8f15b
            ast.return_value = False
    Pierre-Yves Chibon a8f15b
            tests.create_projects(self.session)
    Pierre-Yves Chibon 72ed6b
            tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon a8f15b
            self.assertEqual(repo.hook_token, 'aaabbbccc')
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
            user = tests.FakeUser()
    Pierre-Yves Chibon a8f15b
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon fb7f0c
                pagure.APP.config['WEBHOOK'] = True
    Pierre-Yves Chibon a8f15b
                output = self.app.get('/new/')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn('Create new Project', output.data)
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                csrf_token = output.data.split(
    Pierre-Yves Chibon a8f15b
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                output = self.app.post('/foo/hook_token')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                output = self.app.post('/test/hook_token')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                ast.return_value = True
    Pierre-Yves Chibon a8f15b
                output = self.app.post('/test/hook_token')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon a8f15b
                ast.return_value = False
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon fb7f0c
                pagure.APP.config['WEBHOOK'] = False
    Pierre-Yves Chibon fb7f0c
    Pierre-Yves Chibon a8f15b
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon a8f15b
            self.assertEqual(repo.hook_token, 'aaabbbccc')
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
            user.username = 'pingou'
    Pierre-Yves Chibon a8f15b
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon fb7f0c
                pagure.APP.config['WEBHOOK'] = True
    Pierre-Yves Chibon a8f15b
                output = self.app.post('/test/hook_token')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(repo.hook_token, 'aaabbbccc')
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                output = self.app.post(
    Pierre-Yves Chibon a8f15b
                    '/test/hook_token', data=data, follow_redirects=True)
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon a8f15b
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      New hook token generated',
    Pierre-Yves Chibon a8f15b
                    output.data)
    Pierre-Yves Chibon fb7f0c
                pagure.APP.config['WEBHOOK'] = False
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
            repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon a8f15b
            self.assertNotEqual(repo.hook_token, 'aaabbbccc')
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon d4ef3d
        @patch('pagure.lib.notify.send_email')
    Pierre-Yves Chibon 270cef
        @patch('pagure.ui.repo.admin_session_timedout')
    Pierre-Yves Chibon 270cef
        @patch('pagure.lib.git.update_git')
    Pierre-Yves Chibon d4ef3d
        def test_regenerate_git(self, upgit, ast, sendmail):
    Pierre-Yves Chibon 270cef
            """ Test the regenerate_git endpoint. """
    Pierre-Yves Chibon 270cef
            ast.return_value = False
    Pierre-Yves Chibon 270cef
            upgit.return_value = True
    Pierre-Yves Chibon d4ef3d
            sendmail.return_value = True
    Pierre-Yves Chibon 270cef
            tests.create_projects(self.session)
    Pierre-Yves Chibon 3f60e3
            tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
            user = tests.FakeUser()
    Pierre-Yves Chibon 270cef
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 270cef
                output = self.app.get('/new/')
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn('Create new Project', output.data)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                csrf_token = output.data.split(
    Pierre-Yves Chibon 270cef
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                output = self.app.post('/foo/regenerate')
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                output = self.app.post('/test/regenerate')
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                ast.return_value = True
    Pierre-Yves Chibon 270cef
                output = self.app.post('/test/regenerate')
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 270cef
                ast.return_value = False
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
            user.username = 'pingou'
    Pierre-Yves Chibon 270cef
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 270cef
                output = self.app.post('/test/regenerate')
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                output = self.app.post('/test/regenerate', data=data)
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 270cef
                data['regenerate'] = 'ticket'
    Pierre-Yves Chibon 270cef
                output = self.app.post('/test/regenerate', data=data)
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 8e3bbb
                # Create an issue to play with
    Pierre-Yves Chibon 8e3bbb
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 8e3bbb
                msg = pagure.lib.new_issue(
    Pierre-Yves Chibon 8e3bbb
                    session=self.session,
    Pierre-Yves Chibon 8e3bbb
                    repo=repo,
    Pierre-Yves Chibon 8e3bbb
                    title='Test issue',
    Pierre-Yves Chibon 8e3bbb
                    content='We should work on this',
    Pierre-Yves Chibon 8e3bbb
                    user='pingou',
    Pierre-Yves Chibon 8e3bbb
                    ticketfolder=None
    Pierre-Yves Chibon 8e3bbb
                )
    Pierre-Yves Chibon 8e3bbb
                self.session.commit()
    Pierre-Yves Chibon 8e3bbb
                self.assertEqual(msg.title, 'Test issue')
    Pierre-Yves Chibon 8e3bbb
    Pierre-Yves Chibon 270cef
                data['regenerate'] = 'tickets'
    Pierre-Yves Chibon 270cef
                output = self.app.post(
    Pierre-Yves Chibon 270cef
                    '/test/regenerate', data=data, follow_redirects=True)
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 270cef
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Tickets git repo updated',
    Pierre-Yves Chibon 270cef
                    output.data)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon 8e3bbb
                # Create a request to play with
    Pierre-Yves Chibon 8e3bbb
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 8e3bbb
                msg = pagure.lib.new_pull_request(
    Pierre-Yves Chibon 8e3bbb
                    session=self.session,
    Pierre-Yves Chibon 8e3bbb
                    repo_from=repo,
    Pierre-Yves Chibon 8e3bbb
                    branch_from='branch',
    Pierre-Yves Chibon 8e3bbb
                    repo_to=repo,
    Pierre-Yves Chibon 8e3bbb
                    branch_to='master',
    Pierre-Yves Chibon 8e3bbb
                    title='Test pull-request',
    Pierre-Yves Chibon 8e3bbb
                    user='pingou',
    Pierre-Yves Chibon 8e3bbb
                    requestfolder=None,
    Pierre-Yves Chibon 8e3bbb
                )
    Pierre-Yves Chibon 8e3bbb
                self.session.commit()
    Pierre-Yves Chibon 8e3bbb
                self.assertEqual(msg.title, 'Test pull-request')
    Pierre-Yves Chibon 8e3bbb
    Pierre-Yves Chibon 270cef
                data['regenerate'] = 'requests'
    Pierre-Yves Chibon 270cef
                output = self.app.post(
    Pierre-Yves Chibon 270cef
                    '/test/regenerate', data=data, follow_redirects=True)
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 270cef
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Requests git repo updated',
    Pierre-Yves Chibon 270cef
                    output.data)
    Pierre-Yves Chibon 270cef
    Pierre-Yves Chibon d5c012
        def test_view_tags(self):
    Pierre-Yves Chibon d5c012
            """ Test the view_tags endpoint. """
    Pierre-Yves Chibon 9b6360
            output = self.app.get('/foo/releases')
    Pierre-Yves Chibon d5c012
            # No project registered in the DB
    Pierre-Yves Chibon d5c012
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon d5c012
            tests.create_projects(self.session)
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon 9b6360
            output = self.app.get('/test/releases')
    Pierre-Yves Chibon d5c012
            # No git repo associated
    Pierre-Yves Chibon d5c012
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon 128dfb
            tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon 9b6360
            output = self.app.get('/test/releases')
    Pierre-Yves Chibon d5c012
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon d5c012
            self.assertIn('This project has not been tagged.', output.data)
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon d5c012
            # Add a README to the git repo - First commit
    Pierre-Yves Chibon d5c012
            tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 128dfb
            repo = pygit2.Repository(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon d5c012
            first_commit = repo.revparse_single('HEAD')
    Pierre-Yves Chibon d5c012
            tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0)
    Pierre-Yves Chibon d5c012
            repo.create_tag(
    Pierre-Yves Chibon d5c012
                "0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
    Pierre-Yves Chibon d5c012
                "Release 0.0.1")
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon 9b6360
            output = self.app.get('/test/releases')
    Pierre-Yves Chibon d5c012
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon d5c012
            self.assertIn('0.0.1', output.data)
    Ryan Lerch f6c9d8
            self.assertIn('', output.data)
    Pierre-Yves Chibon d5c012
            self.assertTrue(output.data.count('tagid'), 1)
    Pierre-Yves Chibon d5c012
    Pierre-Yves Chibon 39d6c0
        def test_edit_file(self):
    Pierre-Yves Chibon 39d6c0
            """ Test the edit_file endpoint. """
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Pierre-Yves Chibon 39d6c0
            output = self.app.get('/foo/edit/foo/f/sources')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
            user = tests.FakeUser()
    Pierre-Yves Chibon 39d6c0
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 39d6c0
                # No project registered in the DB
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/foo/edit/foo/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                tests.create_projects(self.session)
    Pierre-Yves Chibon ae3cda
                tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # No a repo admin
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/edit/foo/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.get('/test/edit/foo/f/sources')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon 39d6c0
            user.username = 'pingou'
    Pierre-Yves Chibon 39d6c0
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon ae3cda
                # No such file
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/edit/foo/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # Add some content to the git repo
    Pierre-Yves Chibon 39d6c0
                tests.add_content_git_repo(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 39d6c0
                tests.add_readme_git_repo(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 39d6c0
                tests.add_binary_git_repo(
    Pierre-Yves Chibon 39d6c0
                    os.path.join(tests.HERE, 'test.git'), 'test.jpg')
    Pierre-Yves Chibon 39d6c0
                tests.add_binary_git_repo(
    Pierre-Yves Chibon 39d6c0
                    os.path.join(tests.HERE, 'test.git'), 'test_binary')
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/edit/master/foofile')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # Edit page
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/edit/master/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '
  2. '
  3. Pierre-Yves Chibon efb2ec
                    '  master'
    Pierre-Yves Chibon efb2ec
                    '
  4. '
  5. Pierre-Yves Chibon efb2ec
                    '  sources',
    Pierre-Yves Chibon 39d6c0
                    output.data)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<textarea id="textareaCode" name="content">foo\n bar</textarea>',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                csrf_token = output.data.split(
    Pierre-Yves Chibon 39d6c0
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # View what's supposed to be an image
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/edit/master/f/test.jpg')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon 39d6c0
                self.assertIn('

    Cannot edit binary files

    ', output.data)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # Check file before the commit:
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/raw/master/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.data, 'foo\n bar')
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # No CSRF Token
    Pierre-Yves Chibon 39d6c0
                data = {
    Pierre-Yves Chibon 39d6c0
                    'content': 'foo\n bar\n  baz',
    Pierre-Yves Chibon 39d6c0
                    'commit_title': 'test commit',
    Pierre-Yves Chibon 39d6c0
                    'commit_message': 'Online commits from the tests',
    Pierre-Yves Chibon 39d6c0
                }
    Pierre-Yves Chibon 39d6c0
                output = self.app.post('/test/edit/master/f/sources', data=data)
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon 39d6c0
                    '<title>Edit - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # Check that nothing changed
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/raw/master/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.data, 'foo\n bar')
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon badd09
                # Missing email
    Pierre-Yves Chibon 39d6c0
                data['csrf_token'] = csrf_token
    Pierre-Yves Chibon badd09
                output = self.app.post('/test/edit/master/f/sources', data=data)
    Pierre-Yves Chibon badd09
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon badd09
                self.assertIn(
    Pierre-Yves Chibon badd09
                    '<title>Edit - test - Pagure</title>', output.data)
    Pierre-Yves Chibon badd09
    Pierre-Yves Chibon badd09
                # Invalid email
    Pierre-Yves Chibon badd09
                data['email'] = 'pingou@fp.o'
    Pierre-Yves Chibon badd09
                output = self.app.post('/test/edit/master/f/sources', data=data)
    Pierre-Yves Chibon badd09
                self.assertIn(
    Pierre-Yves Chibon badd09
                    '<title>Edit - test - Pagure</title>', output.data)
    Pierre-Yves Chibon badd09
    Pierre-Yves Chibon badd09
                # Works
    Pierre-Yves Chibon badd09
                data['email'] = 'bar@pingou.com'
    Pierre-Yves Chibon cd15ac
                data['branch'] = 'master'
    Pierre-Yves Chibon 39d6c0
                output = self.app.post(
    Pierre-Yves Chibon 39d6c0
                    '/test/edit/master/f/sources', data=data,
    Pierre-Yves Chibon 39d6c0
                    follow_redirects=True)
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Ryan Lerch c3b81e
                    '<title>Commits - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Changes committed',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # Check file after the commit:
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/test/raw/master/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.data, 'foo\n bar\n  baz')
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # Add a fork of a fork
    Pierre-Yves Chibon 39d6c0
                item = pagure.lib.model.Project(
    Pierre-Yves Chibon 39d6c0
                    user_id=1,  # pingou
    Pierre-Yves Chibon 39d6c0
                    name='test3',
    Pierre-Yves Chibon 39d6c0
                    description='test project #3',
    farhaanbukhsh 907098
                    is_fork=True,
    Pierre-Yves Chibon 39d6c0
                    parent_id=1,
    Pierre-Yves Chibon 39d6c0
                    hook_token='aaabbbppp',
    Pierre-Yves Chibon 39d6c0
                )
    Pierre-Yves Chibon 39d6c0
                self.session.add(item)
    Pierre-Yves Chibon 39d6c0
                self.session.commit()
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                tests.add_content_git_repo(
    Pierre-Yves Chibon 39d6c0
                    os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
    Pierre-Yves Chibon 39d6c0
                tests.add_readme_git_repo(
    Pierre-Yves Chibon 39d6c0
                    os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'))
    Pierre-Yves Chibon 39d6c0
                tests.add_commit_git_repo(
    Pierre-Yves Chibon 39d6c0
                    os.path.join(tests.HERE, 'forks', 'pingou', 'test3.git'),
    Pierre-Yves Chibon 39d6c0
                    ncommits=10)
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                output = self.app.get('/fork/pingou/test3/edit/master/f/sources')
    Pierre-Yves Chibon 39d6c0
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '
  6. '
  7. Pierre-Yves Chibon efb2ec
                    '  master'
    Pierre-Yves Chibon efb2ec
                    '
  8. '
  9. Pierre-Yves Chibon efb2ec
                    '  sources'
    Pierre-Yves Chibon efb2ec
                    '', output.data)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<textarea id="textareaCode" name="content">foo\n barRow 0\n',</textarea>
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 39d6c0
    Ghost-script ac44e3
        @patch('pagure.ui.repo.admin_session_timedout')
    Ghost-script ac44e3
        def test_change_ref_head(self,ast):
    Ghost-script ac44e3
            """ Test the change_ref_head endpoint. """
    Pierre-Yves Chibon c62a10
            ast.return_value = True
    Ghost-script ac44e3
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Ghost-script ac44e3
            output = self.app.post('/foo/default/branch/')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Ghost-script ac44e3
    Ghost-script ac44e3
            user = tests.FakeUser()
    Ghost-script ac44e3
            with tests.user_set(pagure.APP, user):
    Ghost-script ac44e3
                output = self.app.post('/foo/default/branch/')
    Pierre-Yves Chibon ae3cda
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon c62a10
    Pierre-Yves Chibon c62a10
                ast.return_value = False
    Pierre-Yves Chibon c62a10
    Pierre-Yves Chibon c62a10
                output = self.app.post('/foo/default/branch/')
    Ghost-script ac44e3
                self.assertEqual(output.status_code, 404)
    Ghost-script ac44e3
    Ghost-script ac44e3
                tests.create_projects(self.session)
    Pierre-Yves Chibon ae3cda
                repos = tests.create_projects_git(tests.HERE)
    Ghost-script ac44e3
    Ghost-script ac44e3
                output = self.app.post('/test/default/branch/')
    Ghost-script ac44e3
                self.assertEqual(output.status_code, 403)
    Ghost-script ac44e3
    Pierre-Yves Chibon 3f60e3
            # User no logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/default/branch/')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Ghost-script ac44e3
            user.username = 'pingou'
    Ghost-script ac44e3
            with tests.user_set(pagure.APP, user):
    Ghost-script ac44e3
                output = self.app.post('/test/default/branch/',
    Ghost-script ac44e3
                                        follow_redirects=True) # without git branch
    Ghost-script ac44e3
                self.assertEqual(output.status_code, 200)
    Ghost-script ac44e3
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<title>Settings - test - Pagure</title>', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn('

    Settings for test

    ', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<select class="c-select" id="branches" name="branches">'</select>
    Pierre-Yves Chibon efb2ec
                    '', output.data)
    Ghost-script ac44e3
                csrf_token = output.data.split(
    Ghost-script ac44e3
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Ghost-script ac44e3
    Pierre-Yves Chibon ae3cda
                repo_obj = pygit2.Repository(repos[0])
    Ghost-script ac44e3
                tree = repo_obj.index.write_tree()
    Ghost-script ac44e3
                author = pygit2.Signature(
    Ghost-script ac44e3
                    'Alice Author', 'alice@authors.tld')
    Ghost-script ac44e3
                committer = pygit2.Signature(
    Ghost-script ac44e3
                    'Cecil Committer', 'cecil@committers.tld')
    Ghost-script ac44e3
                repo_obj.create_commit(
    Ghost-script ac44e3
                    'refs/heads/master',  # the name of the reference to update
    Ghost-script ac44e3
                    author,
    Ghost-script ac44e3
                    committer,
    Ghost-script ac44e3
                    'Add sources file for testing',
    Ghost-script ac44e3
                    # binary string representing the tree object ID
    Ghost-script ac44e3
                    tree,
    Ghost-script ac44e3
                    # list of binary strings representing parents of the new commit
    Ghost-script ac44e3
                    []
    Ghost-script ac44e3
                )
    Ghost-script ac44e3
                repo_obj.create_branch("feature",repo_obj.head.get_object())
    Ghost-script ac44e3
    Ghost-script ac44e3
                data = {
    Ghost-script ac44e3
                    'branches': 'feature',
    Ghost-script ac44e3
                    'csrf_token': csrf_token,
    Ghost-script ac44e3
                }
    Ghost-script ac44e3
    Ghost-script ac44e3
                output = self.app.post('/test/default/branch/',     # changing head to feature branch
    Ghost-script ac44e3
                                        data=data,
    Ghost-script ac44e3
                                        follow_redirects=True)
    Ghost-script ac44e3
                self.assertEqual(output.status_code, 200)
    Ghost-script ac44e3
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<title>Settings - test - Pagure</title>', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn('

    Settings for test

    ', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<select class="c-select" id="branches" name="branches">'</select>
    Pierre-Yves Chibon bb4b96
                    '<option selected="" value="feature">feature</option>'
    Pierre-Yves Chibon efb2ec
                    '<option value="master">master</option>'
    Pierre-Yves Chibon efb2ec
                    '', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Default branch updated '
    Pierre-Yves Chibon efb2ec
                    'to feature', output.data)
    Ghost-script ac44e3
    Ghost-script ac44e3
                data = {
    Ghost-script ac44e3
                    'branches': 'master',
    Ghost-script ac44e3
                    'csrf_token': csrf_token,
    Ghost-script ac44e3
                }
    Ghost-script ac44e3
    Ghost-script ac44e3
                output = self.app.post('/test/default/branch/',     # changing head to master branch
    Ghost-script ac44e3
                                        data=data,
    Ghost-script ac44e3
                                        follow_redirects=True)
    Ghost-script ac44e3
                self.assertEqual(output.status_code, 200)
    Ghost-script ac44e3
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<title>Settings - test - Pagure</title>', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn('

    Settings for test

    ', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<select class="c-select" id="branches" name="branches">'</select>
    Pierre-Yves Chibon efb2ec
                    '<option value="feature">feature</option>'
    Pierre-Yves Chibon bb4b96
                    '<option selected="" value="master">master</option>'
    Pierre-Yves Chibon efb2ec
                    '', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Default branch updated '
    Pierre-Yves Chibon efb2ec
                    'to master', output.data)
    Ghost-script ac44e3
    Pierre-Yves Chibon ff69ce
        def test_new_release(self):
    Pierre-Yves Chibon ff69ce
            """ Test the new_release endpoint. """
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Pierre-Yves Chibon ff69ce
            output = self.app.post('/foo/upload/')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
            user = tests.FakeUser()
    Pierre-Yves Chibon ff69ce
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon ff69ce
                output = self.app.post('/foo/upload/')
    Pierre-Yves Chibon ff69ce
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
                tests.create_projects(self.session)
    Pierre-Yves Chibon 3f60e3
                repo = tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
                output = self.app.post('/test/upload/')
    Pierre-Yves Chibon ff69ce
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/upload/')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon ff69ce
            user.username = 'pingou'
    Pierre-Yves Chibon ff69ce
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon ff69ce
                img = os.path.join(tests.HERE, 'placebo.png')
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
                # Missing CSRF Token
    Pierre-Yves Chibon ff69ce
                data = {'filestream': open(img)}
    Pierre-Yves Chibon ff69ce
                output = self.app.post('/test/upload/', data=data)
    Pierre-Yves Chibon ff69ce
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon ff69ce
                self.assertIn('

    Upload a new release

    ', output.data)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
                csrf_token = output.data.split(
    Pierre-Yves Chibon ff69ce
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
                # Upload successful
    Pierre-Yves Chibon ff69ce
                data = {'filestream': open(img), 'csrf_token': csrf_token}
    Pierre-Yves Chibon ff69ce
                output = self.app.post(
    Pierre-Yves Chibon ff69ce
                    '/test/upload/', data=data, follow_redirects=True)
    Pierre-Yves Chibon ff69ce
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      File', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    'uploaded\n                    ', output.data)
    Pierre-Yves Chibon ff69ce
                self.assertIn('This project has not been tagged.', output.data)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon 58ebb2
        @patch('pagure.ui.repo.admin_session_timedout')
    Pierre-Yves Chibon 58ebb2
        def test_add_token(self, ast):
    Pierre-Yves Chibon a26be4
            """ Test the add_token endpoint. """
    Pierre-Yves Chibon 58ebb2
            ast.return_value = False
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Pierre-Yves Chibon a26be4
            output = self.app.get('/foo/token/new/')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
            user = tests.FakeUser()
    Pierre-Yves Chibon a26be4
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon a26be4
                output = self.app.get('/foo/token/new/')
    Pierre-Yves Chibon a26be4
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                tests.create_projects(self.session)
    Pierre-Yves Chibon ae3cda
                tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                output = self.app.get('/test/token/new/')
    Pierre-Yves Chibon a26be4
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.get('/test/token/new/')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon a26be4
            user.username = 'pingou'
    Pierre-Yves Chibon a26be4
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon a26be4
                output = self.app.get('/test/token/new/')
    Pierre-Yves Chibon a26be4
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn('Create a new token', output.data)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                csrf_token = output.data.split(
    Pierre-Yves Chibon a26be4
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 58ebb2
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon 58ebb2
    Pierre-Yves Chibon 58ebb2
                ast.return_value = True
    Pierre-Yves Chibon 58ebb2
                # Test when the session timed-out
    Pierre-Yves Chibon 58ebb2
                output = self.app.post('/test/token/new/', data=data)
    Pierre-Yves Chibon 58ebb2
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 58ebb2
                output = self.app.get('/')
    Pierre-Yves Chibon 58ebb2
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 58ebb2
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Action canceled, try it '
    Pierre-Yves Chibon efb2ec
                    'again', output.data)
    Pierre-Yves Chibon 58ebb2
                ast.return_value = False
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                # Missing acls
    Pierre-Yves Chibon a26be4
                output = self.app.post('/test/token/new/', data=data)
    Pierre-Yves Chibon a26be4
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn('Create a new token', output.data)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                data = {'csrf_token': csrf_token, 'acls': ['issue_create']}
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                # Upload successful
    Pierre-Yves Chibon a26be4
                data = {'csrf_token': csrf_token, 'acls': ['issue_create']}
    Pierre-Yves Chibon a26be4
                output = self.app.post(
    Pierre-Yves Chibon a26be4
                    '/test/token/new/', data=data, follow_redirects=True)
    Pierre-Yves Chibon a26be4
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Token created', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '<title>Settings - test - Pagure</title>', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn('

    Settings for test

    ', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Lubomír Sedlář 60ab63
                    'Valid until: ',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon 66632f
        @patch('pagure.ui.repo.admin_session_timedout')
    Pierre-Yves Chibon 66632f
        def test_revoke_api_token(self, ast):
    Pierre-Yves Chibon 66632f
            """ Test the revoke_api_token endpoint. """
    Pierre-Yves Chibon 66632f
            ast.return_value = False
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Pierre-Yves Chibon 66632f
            output = self.app.post('/foo/token/revoke/123')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
            user = tests.FakeUser()
    Pierre-Yves Chibon 66632f
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 66632f
                output = self.app.post('/foo/token/revoke/123')
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                tests.create_projects(self.session)
    Pierre-Yves Chibon ae3cda
                tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                output = self.app.post('/test/token/revoke/123')
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/token/revoke/123')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon 66632f
            user.username = 'pingou'
    Pierre-Yves Chibon 66632f
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 66632f
                output = self.app.get('/test/token/new')
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn('Create a new token', output.data)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                csrf_token = output.data.split(
    Pierre-Yves Chibon 66632f
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Pierre-Yves Chibon 66632f
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                ast.return_value = True
    Pierre-Yves Chibon 66632f
                # Test when the session timed-out
    Pierre-Yves Chibon 66632f
                output = self.app.post('/test/token/revoke/123', data=data)
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 66632f
                output = self.app.get('/')
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 66632f
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Action canceled, try it again',
    Pierre-Yves Chibon 66632f
                    output.data)
    Pierre-Yves Chibon 66632f
                ast.return_value = False
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                output = self.app.post('/test/token/revoke/123', data=data)
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 2aeccd
                self.assertIn('

    Token not found

    ', output.data)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                # Create a token to revoke
    Pierre-Yves Chibon 66632f
                data = {'csrf_token': csrf_token, 'acls': ['issue_create']}
    Pierre-Yves Chibon 66632f
                output = self.app.post(
    Pierre-Yves Chibon 66632f
                    '/test/token/new/', data=data, follow_redirects=True)
    Pierre-Yves Chibon 66632f
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Token created',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                # Existing token will expire in 60 days
    Pierre-Yves Chibon 66632f
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 66632f
                self.assertEqual(
    Pierre-Yves Chibon 66632f
                    repo.tokens[0].expiration.date(),
    Pierre-Yves Chibon 66632f
                    datetime.datetime.utcnow().date() + datetime.timedelta(days=60))
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                token = repo.tokens[0].id
    Pierre-Yves Chibon 66632f
                output = self.app.post(
    Pierre-Yves Chibon 66632f
                    '/test/token/revoke/%s' % token,
    Pierre-Yves Chibon 66632f
                    data=data,
    Pierre-Yves Chibon 66632f
                    follow_redirects=True)
    Pierre-Yves Chibon 66632f
                self.assertIn(
    Pierre-Yves Chibon 66632f
                    '<title>Settings - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 66632f
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Token revoked',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                # Existing token has been expired
    Pierre-Yves Chibon 66632f
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 66632f
                self.assertEqual(
    Pierre-Yves Chibon 66632f
                    repo.tokens[0].expiration.date(),
    Pierre-Yves Chibon 66632f
                    repo.tokens[0].created.date())
    Pierre-Yves Chibon 66632f
                self.assertEqual(
    Pierre-Yves Chibon 66632f
                    repo.tokens[0].expiration.date(),
    Pierre-Yves Chibon 66632f
                    datetime.datetime.utcnow().date())
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 0a9fcb
        def test_delete_branch(self):
    Pierre-Yves Chibon 0a9fcb
            """ Test the delete_branch endpoint. """
    Pierre-Yves Chibon 3f60e3
            # No Git repo
    Pierre-Yves Chibon 5bf6f1
            output = self.app.post('/foo/b/master/delete')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
            tests.create_projects(self.session)
    Pierre-Yves Chibon ae3cda
            tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 3f60e3
            # User not logged in
    Pierre-Yves Chibon 3f60e3
            output = self.app.post('/test/b/master/delete')
    Pierre-Yves Chibon 3f60e3
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 3f60e3
    Pierre-Yves Chibon 0a9fcb
            user = tests.FakeUser()
    Pierre-Yves Chibon 0a9fcb
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 0a9fcb
                # Unknown repo
    Pierre-Yves Chibon 3f60e3
                output = self.app.post('/foo/b/master/delete')
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 5bf6f1
                output = self.app.post('/test/b/master/delete')
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
            user.username = 'pingou'
    Pierre-Yves Chibon 0a9fcb
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 5bf6f1
                output = self.app.post('/test/b/master/delete')
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 0a9fcb
                self.assertIn(
    Pierre-Yves Chibon 0a9fcb
                    '

    You are not allowed to delete the master branch

    ',
    Pierre-Yves Chibon 0a9fcb
                    output.data)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 5bf6f1
                output = self.app.post('/test/b/bar/delete')
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 2aeccd
                self.assertIn('

    Branch no found

    ', output.data)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
                # Add a branch that we can delete
    Pierre-Yves Chibon 0a9fcb
                path = os.path.join(tests.HERE, 'test.git')
    Pierre-Yves Chibon 0a9fcb
                tests.add_content_git_repo(path)
    Pierre-Yves Chibon 0a9fcb
                repo = pygit2.Repository(path)
    Pierre-Yves Chibon 0a9fcb
                repo.create_branch('foo', repo.head.get_object())
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
                # Check before deletion
    Pierre-Yves Chibon 5bf6f1
                output = self.app.get('/test')
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Ryan Lerch 1c9a10
                    'data-toggle="tooltip">foo',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 2623d5
                self.assertIn('
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Ryan Lerch 1c9a10
                    '
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
                # Delete the branch
    Pierre-Yves Chibon 5bf6f1
                output = self.app.post('/test/b/foo/delete', follow_redirects=True)
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertNotIn(
    Ryan Lerch 1c9a10
                    'data-toggle="tooltip">foo',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 2623d5
                self.assertNotIn(
    Pierre-Yves Chibon 2623d5
                    '
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Ryan Lerch 1c9a10
                    '
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon f8ff28
                # Add a branch with a '/' in its name that we can delete
    Pierre-Yves Chibon f8ff28
                path = os.path.join(tests.HERE, 'test.git')
    Pierre-Yves Chibon f8ff28
                tests.add_content_git_repo(path)
    Pierre-Yves Chibon f8ff28
                repo = pygit2.Repository(path)
    Pierre-Yves Chibon f8ff28
                repo.create_branch('feature/foo', repo.head.get_object())
    Pierre-Yves Chibon f8ff28
    Pierre-Yves Chibon f8ff28
                # Check before deletion
    Pierre-Yves Chibon 5bf6f1
                output = self.app.get('/test')
    Pierre-Yves Chibon f8ff28
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon f8ff28
                self.assertIn(
    Ryan Lerch 1c9a10
                    'data-toggle="tooltip">feature/foo',
    Pierre-Yves Chibon f8ff28
                    output.data)
    Pierre-Yves Chibon f8ff28
                self.assertIn(
    Pierre-Yves Chibon 2623d5
                    '
    Pierre-Yves Chibon 2623d5
                self.assertIn(
    Ryan Lerch 1c9a10
                    '
    Pierre-Yves Chibon f8ff28
                    output.data)
    Pierre-Yves Chibon f8ff28
    Pierre-Yves Chibon f8ff28
                # Delete the branch
    Pierre-Yves Chibon 5bf6f1
                output = self.app.post('/test/b/feature/foo/delete', follow_redirects=True)
    Pierre-Yves Chibon f8ff28
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon f8ff28
                self.assertNotIn(
    Ryan Lerch 1c9a10
                    'data-toggle="tooltip">feature/foo',
    Pierre-Yves Chibon f8ff28
                    output.data)
    Pierre-Yves Chibon 2623d5
                self.assertNotIn(
    Pierre-Yves Chibon 2623d5
                    '
    Pierre-Yves Chibon f8ff28
                self.assertIn(
    Ryan Lerch 1c9a10
                    '
    Pierre-Yves Chibon f8ff28
                    output.data)
    Pierre-Yves Chibon f8ff28
    Pierre-Yves Chibon 24b5ea
        def test_view_docs(self):
    Pierre-Yves Chibon 24b5ea
            """ Test the view_docs endpoint. """
    Pierre-Yves Chibon 24b5ea
            output = self.app.get('/docs/foo/')
    Pierre-Yves Chibon 24b5ea
            # No project registered in the DB
    Pierre-Yves Chibon 24b5ea
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 24b5ea
    Pierre-Yves Chibon 24b5ea
            tests.create_projects(self.session)
    Pierre-Yves Chibon 24b5ea
    Pierre-Yves Chibon 24b5ea
            output = self.app.get('/docs/test/')
    Pierre-Yves Chibon 24b5ea
            # No git repo associated
    Pierre-Yves Chibon 24b5ea
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 24b5ea
    Pierre-Yves Chibon 24b5ea
            tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon 24b5ea
    Pierre-Yves Chibon 24b5ea
            output = self.app.get('/docs/test/')
    Pierre-Yves Chibon 24b5ea
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 24b5ea
    Ryan Lerch 0fc819
        def test_view_project_activity(self):
    Ryan Lerch 0fc819
            """ Test the view_project_activity endpoint. """
    Ryan Lerch 0fc819
            tests.create_projects(self.session)
    Pierre-Yves Chibon 3f60e3
            tests.create_projects_git(tests.HERE, bare=True)
    Ryan Lerch 0fc819
    Ryan Lerch 0fc819
            # Project Exists, but No DATAGREPPER_URL set
    Pierre-Yves Chibon 68cdc3
            output = self.app.get('/test/activity/')
    Pierre-Yves Chibon 68cdc3
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 68cdc3
    Pierre-Yves Chibon 68cdc3
            # Project Exists, and DATAGREPPER_URL set
    Pierre-Yves Chibon 68cdc3
            pagure.APP.config['DATAGREPPER_URL'] = 'foo'
    Pierre-Yves Chibon 68cdc3
            output = self.app.get('/test/activity/')
    Pierre-Yves Chibon 68cdc3
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 68cdc3
            self.assertIn(
    Pierre-Yves Chibon 68cdc3
                '<title>Activity - test - Pagure</title>', output.data)
    Pierre-Yves Chibon 68cdc3
            self.assertIn(
    Pierre-Yves Chibon 68cdc3
                'No activity reported on the test project', output.data)
    Pierre-Yves Chibon 68cdc3
    Pierre-Yves Chibon 68cdc3
            # project doesnt exist
    Pierre-Yves Chibon 68cdc3
            output = self.app.get('/foo/activity/')
    Ryan Lerch 0fc819
            self.assertEqual(output.status_code, 404)
    Ryan Lerch 0fc819
    Gaurav Kumar 00f2c8
        def test_watch_repo(self):
    Gaurav Kumar 00f2c8
            """ Test the  watch_repo endpoint. """
    Gaurav Kumar 00f2c8
    Gaurav Kumar 604af6
            output = self.app.post('/watch/')
    Gaurav Kumar 604af6
            self.assertEqual(output.status_code, 405)
    Gaurav Kumar 604af6
    Gaurav Kumar 00f2c8
            tests.create_projects(self.session)
    Pierre-Yves Chibon 3f60e3
            tests.create_projects_git(tests.HERE, bare=True)
    Gaurav Kumar 00f2c8
    Gaurav Kumar 00f2c8
            user = tests.FakeUser()
    Gaurav Kumar 00f2c8
            user.username = 'pingou'
    Gaurav Kumar 00f2c8
            with tests.user_set(pagure.APP, user):
    Gaurav Kumar 00f2c8
    Gaurav Kumar 00f2c8
                output = self.app.get('/new/')
    Gaurav Kumar 00f2c8
                self.assertEqual(output.status_code, 200)
    Gaurav Kumar 00f2c8
                self.assertIn('Create new Project', output.data)
    Gaurav Kumar 00f2c8
    Gaurav Kumar 00f2c8
                csrf_token = output.data.split(
    Gaurav Kumar 00f2c8
                    'name="csrf_token" type="hidden" value="')[1].split('">')[0]
    Gaurav Kumar 00f2c8
    Gaurav Kumar 00f2c8
                data = {
    Gaurav Kumar 604af6
                    'csrf_token':csrf_token
    Gaurav Kumar 00f2c8
                }
    Gaurav Kumar 604af6
                output = self.app.post(
    Gaurav Kumar 604af6
                    '/watch', data=data, follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertEqual(output.status_code, 404)
    Gaurav Kumar 00f2c8
    Gaurav Kumar 00f2c8
                output = self.app.post(
    Pierre-Yves Chibon 8544f4
                    '/foo/watch/settings', data=data, follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertEqual(output.status_code, 404)
    Gaurav Kumar 00f2c8
    Gaurav Kumar 604af6
                output = self.app.post(
    Pierre-Yves Chibon 8544f4
                    '/test/watch/settings/2', data=data, follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertEqual(output.status_code, 400)
    Gaurav Kumar 00f2c8
    Gaurav Kumar 00f2c8
                output = self.app.post(
    Pierre-Yves Chibon 8544f4
                    '/test/watch/settings/0', data=data, follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertIn(
    Gaurav Kumar 604af6
                    '\n                      You are no longer'
    Gaurav Kumar 604af6
                    ' watching this repo.', output.data)
    Gaurav Kumar 604af6
    Gaurav Kumar 604af6
                output = self.app.post(
    Pierre-Yves Chibon 8544f4
                    '/test/watch/settings/1', data=data, follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertIn(
    Gaurav Kumar 6cf178
                    '\n                      You are now'
    Gaurav Kumar 604af6
                    ' watching this repo.', output.data)
    Gaurav Kumar 604af6
    Gaurav Kumar 604af6
                item = pagure.lib.model.Project(
    Gaurav Kumar 604af6
                    user_id=2,  # foo
    Gaurav Kumar 604af6
                    name='test',
    Pierre-Yves Chibon 3f60e3
                    description='foo project #1',
    Gaurav Kumar 604af6
                    hook_token='aaabbb',
    farhaanbukhsh 907098
                    is_fork=True,
    Gaurav Kumar 604af6
                    parent_id=1,
    Gaurav Kumar 00f2c8
                )
    Gaurav Kumar 604af6
                self.session.add(item)
    Gaurav Kumar 00f2c8
                self.session.commit()
    Pierre-Yves Chibon 3f60e3
                gitrepo = os.path.join(tests.HERE, 'forks', 'foo', 'test.git')
    Pierre-Yves Chibon 3f60e3
                pygit2.init_repository(gitrepo, bare=True)
    Gaurav Kumar 604af6
    Gaurav Kumar 604af6
                output = self.app.post(
    Pierre-Yves Chibon 8544f4
                    '/fork/foo/test/watch/settings/0', data=data,
    Pierre-Yves Chibon 8544f4
                    follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertIn(
    Gaurav Kumar 604af6
                    '\n                      You are no longer'
    Gaurav Kumar 604af6
                    ' watching this repo.', output.data)
    Gaurav Kumar 604af6
    Gaurav Kumar 604af6
                output = self.app.post(
    Pierre-Yves Chibon 8544f4
                    '/fork/foo/test/watch/settings/1', data=data,
    Pierre-Yves Chibon 8544f4
                    follow_redirects=True)
    Gaurav Kumar 604af6
                self.assertIn(
    Gaurav Kumar 6cf178
                    '\n                      You are now'
    Gaurav Kumar 604af6
                    ' watching this repo.', output.data)
    Pierre-Yves Chibon 78ce15
    Pierre-Yves Chibon 78ce15
    if __name__ == '__main__':
    Pierre-Yves Chibon fe5017
        SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskRepotests)
    Pierre-Yves Chibon 78ce15
        unittest.TextTestRunner(verbosity=2).run(SUITE)