Blame tests/test_progit_flask_ui_repo.py

Pierre-Yves Chibon 78ce15
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
"""
Pierre-Yves Chibon 78ce15
 (c) 2015 - 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 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 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')
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 78ce15
        output = self.app.get('/foo/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('/foo/adduser')
Pierre-Yves Chibon 78ce15
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
            tests.create_projects(self.session)
Pierre-Yves Chibon 78ce15
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
            # Check the message flashed during the redirect
Pierre-Yves Chibon 728eb1
            output = self.app.get('/')
Pierre-Yves Chibon 728eb1
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 728eb1
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Action canceled, try it '
Pierre-Yves Chibon efb2ec
                'again',output.data)
Pierre-Yves Chibon 728eb1
Pierre-Yves Chibon e213e7
            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)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Add user

', 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)
Pierre-Yves Chibon 78ce15
            self.assertTrue('

Add user

' 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)
Pierre-Yves Chibon efb2ec
            self.assertIn('

Add user

', 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'
Ghost-script ac44e3
            tests.create_projects_git(tests.HERE)
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
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 8b9ecb
        output = self.app.get('/foo/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('/foo/addgroup')
Pierre-Yves Chibon 8b9ecb
            self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 8b9ecb
Pierre-Yves Chibon 8b9ecb
            tests.create_projects(self.session)
Pierre-Yves Chibon 8b9ecb
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
            # Check the message flashed during the redirect
Pierre-Yves Chibon 7de9f5
            output = self.app.get('/')
Pierre-Yves Chibon 7de9f5
            self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 7de9f5
            self.assertIn(
Pierre-Yves Chibon efb2ec
                '\n                      Action canceled, try it '
Pierre-Yves Chibon efb2ec
                'again', output.data)
Pierre-Yves Chibon 7de9f5
Pierre-Yves Chibon 8b9ecb
            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 8b9ecb
            group_type='bar',
Pierre-Yves Chibon 8b9ecb
            user='pingou',
Pierre-Yves Chibon 8b9ecb
            is_admin=False,
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)
Pierre-Yves Chibon 8b9ecb
            self.assertTrue('

Add group

' 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)
Pierre-Yves Chibon 8b9ecb
            self.assertTrue('

Add group

' 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)
Pierre-Yves Chibon 8b9ecb
            self.assertTrue('

Add group

' 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'
Ghost-script ac44e3
            tests.create_projects_git(tests.HERE)
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
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 5980f6
        output = self.app.post('/foo/dropuser/1')
Pierre-Yves Chibon 5980f6
        self.assertEqual(output.status_code, 302)
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 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 5980f6
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Ghost-script ac44e3
            tests.create_projects_git(tests.HERE)
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
Pierre-Yves Chibon e2fa89
    @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 21b196
        output = self.app.post('/foo/update')
Pierre-Yves Chibon 8cae39
        self.assertEqual(output.status_code, 302)
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 21b196
            output = self.app.post('/foo/update')
Pierre-Yves Chibon e2fa89
            self.assertEqual(output.status_code, 302)
Pierre-Yves Chibon e2fa89
Pierre-Yves Chibon e2fa89
            ast.return_value = False
Pierre-Yves Chibon e2fa89
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 8cae39
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 8cae39
        user.username = 'pingou'
Pierre-Yves Chibon fe5017
        with tests.user_set(pagure.APP, user):
Ghost-script ac44e3
            tests.create_projects_git(tests.HERE)
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 490ff9
        output = self.app.get('/foo/settings')
Pierre-Yves Chibon 490ff9
        self.assertEqual(output.status_code, 302)
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 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 efb2ec
                '
\n

test project #1

',
Pierre-Yves Chibon efb2ec
                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 efb2ec
                '
\n

test project #1

',
Pierre-Yves Chibon efb2ec
                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 aca486
        output = self.app.get('/foo/forks')
Pierre-Yves Chibon aca486
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon aca486
Pierre-Yves Chibon aca486
        tests.create_projects(self.session)
Pierre-Yves Chibon aca486
Pierre-Yves Chibon aca486
        output = self.app.get('/test/forks')
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 0447df
        self.assertTrue('

test project #1

' in output.data)
Pierre-Yves Chibon 0447df
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 0447df
        self.assertTrue('

test project #1

' in 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
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 0447df
        self.assertTrue('

test project #1

' in 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',
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 0447df
        self.assertTrue('

test project #3

' in 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 184a05
        self.assertTrue('

test project #1

' in output.data)
Pierre-Yves Chibon 184a05
        self.assertEqual(
Pierre-Yves Chibon 184a05
            output.data.count(''), 0)
Pierre-Yves Chibon 184a05
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 faa629
        self.assertTrue('

test project #1

' in 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
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 faa629
        self.assertTrue('

test project #1

' in 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',
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 faa629
        self.assertTrue('

test project #3

' in 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 efb2ec
        self.assertIn('

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 efb2ec
        self.assertIn('

test project #1

', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('<title>Logs - 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 efb2ec
        self.assertIn('

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
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 efb2ec
        self.assertIn('

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',
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 efb2ec
        self.assertIn('

test project #3

', output.data)
Pierre-Yves Chibon efb2ec
        self.assertIn('Forked from', output.data)
Pierre-Yves Chibon 85d878
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 efb2ec
        self.assertIn('/f/test_binary">view the raw version', output.data)
Pierre-Yves Chibon a55741
        # In newer pygit2 patch.is_binary behaves differently
Pierre-Yves Chibon a55741
        #self.assertTrue(
Pierre-Yves Chibon a55741
            #'Binary files cannot be rendered.
'
Pierre-Yves Chibon a55741
            #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 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',
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 0b62d0
        self.assertTrue(output.data.startswith('<89>PNG^M'))
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 0b62d0
        self.assertTrue(output.data.startswith('<89>PNG^M'))
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 0b62d0
        self.assertTrue(output.data.startswith('<89>PNG^M'))
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 0b62d0
        self.assertTrue(output.data.startswith('<89>PNG^M'))
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',
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 020fcf
        output = self.app.get('/foo/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 020fcf
        output = self.app.get('/test/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 020fcf
        output = self.app.get('/test/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 020fcf
        output = self.app.get('/test/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 020fcf
        self.assertTrue('<section class="commit_diff">' in output.data)</section>
Pierre-Yves Chibon 020fcf
        self.assertTrue('Author' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue('Committer' 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 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 020fcf
        output = self.app.get('/test/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 020fcf
        self.assertTrue('<section class="commit_diff">' in output.data)</section>
Pierre-Yves Chibon 020fcf
        self.assertTrue('Author' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue('Committer' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue(
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
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',
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 020fcf
        output = self.app.get('/test/%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 020fcf
        output = self.app.get('/fork/pingou/test3/%s' % commit.oid.hex)
Pierre-Yves Chibon 020fcf
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 020fcf
        self.assertTrue('<section class="commit_diff">' in output.data)</section>
Pierre-Yves Chibon 020fcf
        self.assertTrue('Author' in output.data)
Pierre-Yves Chibon 020fcf
        self.assertTrue('Committer' 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 aa655b
    def test_view_commit_patch(self):
Pierre-Yves Chibon aa655b
        """ Test the view_commit_patch endpoint. """
Pierre-Yves Chibon aa655b
        output = self.app.get('/foo/bar.patch')
Pierre-Yves Chibon aa655b
        # No project registered in the DB
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 aa655b
        output = self.app.get('/test/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 aa655b
        output = self.app.get('/test/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 aa655b
        output = self.app.get('/test/%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 aa655b
        output = self.app.get('/test/%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',
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 aa655b
        output = self.app.get('/test/%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 aa655b
        output = self.app.get('/fork/pingou/test3/%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 027b38
        self.assertTrue(
Pierre-Yves Chibon efb2ec
            '
  • '
  • Pierre-Yves Chibon efb2ec
                '  None        ' in 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 027b38
            self.assertTrue('

    test project #1

    ' in 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 027b38
            self.assertTrue('

    test project #1

    ' in 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',
    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 027b38
            self.assertTrue('

    test project #3

    ' in 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 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 550d2b
            output = self.app.post('/foo/delete')
    Pierre-Yves Chibon 550d2b
            # User not logged in
    Pierre-Yves Chibon 550d2b
            self.assertEqual(output.status_code, 302)
    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
                output = self.app.post('/foo/delete')
    Pierre-Yves Chibon 550d2b
                # No project registered in the DB
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
                tests.create_projects(self.session)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
                output = self.app.post('/test/delete')
    Pierre-Yves Chibon 550d2b
                # No git repo associated
    Pierre-Yves Chibon 550d2b
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 550d2b
    Pierre-Yves Chibon 550d2b
            user = tests.FakeUser(username='pingou')
    Pierre-Yves Chibon fe5017
            with tests.user_set(pagure.APP, user):
    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
    Pierre-Yves Chibon 116cb7
                ast.return_value = False
    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 efb2ec
                    '

    Projects

    Pierre-Yves Chibon efb2ec
                    'label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '
    '
    Pierre-Yves Chibon efb2ec
                    '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 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 efb2ec
                    '

    Projects

    Pierre-Yves Chibon efb2ec
                    'label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '
    '
    Pierre-Yves Chibon efb2ec
                    '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 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 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 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 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
                    '

    Projects

    Pierre-Yves Chibon efb2ec
                    'label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '
    '
    Pierre-Yves Chibon efb2ec
                    '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',
    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 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 efb2ec
                    '

    Projects

    Pierre-Yves Chibon efb2ec
                    'label-default">1', output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '
    '
    Pierre-Yves Chibon efb2ec
                    '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 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
    Ghost-script ac44e3
                tests.create_projects_git(tests.HERE)
    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 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'
    Ghost-script ac44e3
                tests.create_projects_git(tests.HERE)
    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)
    Pierre-Yves Chibon d5c012
            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 39d6c0
            output = self.app.get('/foo/edit/foo/f/sources')
    Pierre-Yves Chibon 39d6c0
            self.assertEqual(output.status_code, 302)
    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 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 39d6c0
            user.username = 'pingou'
    Pierre-Yves Chibon 39d6c0
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 39d6c0
    Pierre-Yves Chibon 39d6c0
                # No associated git repo
    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
                tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon 39d6c0
    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
                    '
  • '
  • Pierre-Yves Chibon efb2ec
                    '  master'
    Pierre-Yves Chibon efb2ec
                    '
  • '
  • 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(
    Pierre-Yves Chibon cd15ac
                    '<title>Logs - 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',
    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
                    '
  • '
  • Pierre-Yves Chibon efb2ec
                    '  master'
    Pierre-Yves Chibon efb2ec
                    '
  • '
  • 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
    Ghost-script ac44e3
            output = self.app.post('/foo/default/branch/')
    Ghost-script ac44e3
            self.assertEqual(output.status_code, 302)
    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 c62a10
                self.assertEqual(output.status_code, 302)
    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)
    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
    Ghost-script ac44e3
            user.username = 'pingou'
    Ghost-script ac44e3
            with tests.user_set(pagure.APP, user):
    Ghost-script ac44e3
                repo = tests.create_projects_git(tests.HERE)
    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
    Ghost-script ac44e3
                repo_obj = pygit2.Repository(repo[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 ff69ce
            output = self.app.post('/foo/upload/')
    Pierre-Yves Chibon ff69ce
            self.assertEqual(output.status_code, 302)
    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 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 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 Ok but No git repo
    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, 404)
    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('
    No git repo found
    ', output.data)
    Pierre-Yves Chibon ff69ce
    Pierre-Yves Chibon ff69ce
                repo = tests.create_projects_git(tests.HERE)
    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 a26be4
            output = self.app.get('/foo/token/new/')
    Pierre-Yves Chibon a26be4
            self.assertEqual(output.status_code, 302)
    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 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 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
                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, 404)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '\n                      Token created',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon a26be4
                self.assertIn('
    No git repo found
    ', output.data)
    Pierre-Yves Chibon a26be4
    Pierre-Yves Chibon a26be4
                repo = tests.create_projects_git(tests.HERE)
    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(
    Pierre-Yves Chibon efb2ec
                    '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 66632f
            output = self.app.post('/foo/token/revoke/123')
    Pierre-Yves Chibon 66632f
            self.assertEqual(output.status_code, 302)
    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 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 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 66632f
                self.assertIn('
    Token not found
    ', output.data)
    Pierre-Yves Chibon 66632f
    Pierre-Yves Chibon 66632f
                # Create a token to revoke
    Pierre-Yves Chibon 66632f
                repo = tests.create_projects_git(tests.HERE)
    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 0a9fcb
            output = self.app.post('/foo/master/delete')
    Pierre-Yves Chibon 0a9fcb
            # No project registered in the DB
    Pierre-Yves Chibon 0a9fcb
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
            tests.create_projects(self.session)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
            user = tests.FakeUser()
    Pierre-Yves Chibon 0a9fcb
            with tests.user_set(pagure.APP, user):
    Pierre-Yves Chibon 0a9fcb
                output = self.app.post('/foo/master/delete')
    Pierre-Yves Chibon 0a9fcb
                # Unknown repo
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
                output = self.app.post('/test/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 0a9fcb
                output = self.app.post('/test/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 0a9fcb
                tests.create_projects_git(tests.HERE, bare=True)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
                output = self.app.post('/test/bar/delete')
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0a9fcb
                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 0a9fcb
                output = self.app.post('/test', follow_redirects=True)
    Pierre-Yves Chibon 0a9fcb
                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(
    Pierre-Yves Chibon efb2ec
                    '',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 0a9fcb
    Pierre-Yves Chibon 0a9fcb
                # Delete the branch
    Pierre-Yves Chibon 0a9fcb
                output = self.app.post('/test/foo/delete', follow_redirects=True)
    Pierre-Yves Chibon 0a9fcb
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon efb2ec
                self.assertNotIn(
    Pierre-Yves Chibon efb2ec
                    '',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon efb2ec
                self.assertIn(
    Pierre-Yves Chibon efb2ec
                    '',
    Pierre-Yves Chibon efb2ec
                    output.data)
    Pierre-Yves Chibon 0a9fcb
    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
    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)