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 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 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 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 78ce15
            self.assertTrue('

Add user

' in output.data)
Pierre-Yves Chibon 78ce15
            self.assertTrue(
Pierre-Yves Chibon 78ce15
                '
    \n
' in 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
            self.assertTrue(
Pierre-Yves Chibon 78ce15
                '
    \n
' 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 78ce15
            self.assertTrue('

Add user

' in output.data)
Pierre-Yves Chibon 78ce15
            self.assertTrue(
Pierre-Yves Chibon 78ce15
                '
  • No user "ralph" found
  • '
    Pierre-Yves Chibon 78ce15
                    in output.data)
    Pierre-Yves Chibon 78ce15
    Pierre-Yves Chibon 78ce15
                data['user'] = 'foo'
    Pierre-Yves Chibon 78ce15
                output = self.app.post(
    Pierre-Yves Chibon 78ce15
                    '/test/adduser', data=data, follow_redirects=True)
    Pierre-Yves Chibon 78ce15
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 78ce15
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 78ce15
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 78ce15
                self.assertTrue(
    Pierre-Yves Chibon 78ce15
                    '
  • User added
  • ' in 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 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
                self.assertTrue(
    Pierre-Yves Chibon 8b9ecb
                    '
      \n
    ' 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
                self.assertTrue(
    Pierre-Yves Chibon 8b9ecb
                    '
      \n
    ' 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 8b9ecb
                self.assertTrue(
    Pierre-Yves Chibon 8b9ecb
                    '
  • No group ralph found.
  • '
    Pierre-Yves Chibon 8b9ecb
                    in output.data)
    Pierre-Yves Chibon 8b9ecb
    Pierre-Yves Chibon 8b9ecb
                data['group'] = 'foo'
    Pierre-Yves Chibon 8b9ecb
                output = self.app.post(
    Pierre-Yves Chibon 8b9ecb
                    '/test/addgroup', data=data, follow_redirects=True)
    Pierre-Yves Chibon 8b9ecb
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 8b9ecb
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 8b9ecb
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 8b9ecb
                self.assertTrue(
    Pierre-Yves Chibon 8b9ecb
                    '
  • Group added
  • ' in 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):
    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 7c0d1e
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 7c0d1e
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 5980f6
                self.assertTrue(
    Pierre-Yves Chibon 5980f6
                    '
  • User does not have commit or cannot '
  • Pierre-Yves Chibon 5980f6
                    'loose it right' in 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 7c0d1e
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 2c15da
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 2c15da
                self.assertTrue(
    Pierre-Yves Chibon 2c15da
                    '
      \n
    ' in output.data)
    Pierre-Yves Chibon 2c15da
                self.assertFalse(
    Pierre-Yves Chibon 2c15da
                    '
  • User removed
  • ' in 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 2c15da
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 7c0d1e
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 5980f6
                self.assertTrue(
    Pierre-Yves Chibon 5980f6
                    '
  • User removed
  • ' in output.data)
    Pierre-Yves Chibon 5980f6
    Pierre-Yves Chibon 21b196
        def test_update_project(self):
    Pierre-Yves Chibon 21b196
            """ Test the update_project endpoint. """
    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 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):
    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 8cae39
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 8cae39
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 8cae39
                self.assertTrue(
    Pierre-Yves Chibon 8cae39
                    '
      \n
    ' in 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 8cae39
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 8cae39
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon a3121e
                self.assertIn(
    Pierre-Yves Chibon a3121e
                    '<input name="avatar_email" value="">', output.data)
    Pierre-Yves Chibon 8cae39
                self.assertTrue(
    Pierre-Yves Chibon a3121e
                    '
  • Project updated
  • '
    Pierre-Yves Chibon a3121e
                    in 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.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon a3121e
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon a3121e
                self.assertIn(
    Pierre-Yves Chibon a3121e
                    '<input name="avatar_email" value="pingou@fp.o">',
    Pierre-Yves Chibon a3121e
                    output.data)
    Pierre-Yves Chibon a3121e
                self.assertTrue(
    Pierre-Yves Chibon a3121e
                    '
  • Project updated
  • '
    Pierre-Yves Chibon a3121e
                    in 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.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon a3121e
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon a3121e
                self.assertIn(
    Pierre-Yves Chibon a3121e
                    '<input name="avatar_email" value="">',
    Pierre-Yves Chibon a3121e
                    output.data)
    Pierre-Yves Chibon a3121e
                self.assertTrue(
    Pierre-Yves Chibon a3121e
                    '
  • Project updated
  • '
    Pierre-Yves Chibon 8cae39
                    in 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 490ff9
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 490ff9
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
      \n
    ' in output.data)
    Pierre-Yves Chibon 490ff9
                # Both checkbox checked before
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 719bdd
                    '
    Pierre-Yves Chibon e2259d
                    'name="project_documentation" checked=""/>' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 719bdd
                    '
    Pierre-Yves Chibon e2259d
                    'name="issue_tracker" checked=""/>' in 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 490ff9
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 490ff9
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
      \n
    ' in 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 490ff9
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 490ff9
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
      \n
    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 719bdd
                    '
    Pierre-Yves Chibon e2259d
                    'name="project_documentation" checked=""/>' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 719bdd
                    '
    Pierre-Yves Chibon e2259d
                    'name="issue_tracker" checked=""/>' in 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 490ff9
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 490ff9
                self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon fe5017
                    '<title>Overview - test - Pagure</title>' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
  • Edited successfully settings of '
  • Pierre-Yves Chibon 490ff9
                    'repo: test' in 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 490ff9
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon 490ff9
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
      \n
    ' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 719bdd
                    '
    Pierre-Yves Chibon e2259d
                    'name="project_documentation" />' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 719bdd
                    '
    Pierre-Yves Chibon e2259d
                    'name="issue_tracker" />' in output.data)
    Pierre-Yves Chibon 490ff9
    Pierre-Yves Chibon c104d3
                data = {
    Pierre-Yves Chibon c104d3
                    'csrf_token': csrf_token,
    Pierre-Yves Chibon c104d3
                    'project_documentation': '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 c104d3
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon c104d3
                self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon c104d3
                self.assertTrue(
    Pierre-Yves Chibon c104d3
                    '<title>Overview - test - Pagure</title>' in output.data)
    Pierre-Yves Chibon c104d3
                self.assertTrue(
    Pierre-Yves Chibon c104d3
                    '
  • Edited successfully settings of '
  • Pierre-Yves Chibon c104d3
                    'repo: test' in 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 c104d3
                self.assertTrue('<header class="repo">' in output.data)</header>
    Pierre-Yves Chibon c104d3
                self.assertTrue('

    Settings

    ' in output.data)
    Pierre-Yves Chibon c104d3
                self.assertTrue(
    Pierre-Yves Chibon c104d3
                    '
      \n
    ' in output.data)
    Pierre-Yves Chibon c104d3
                self.assertTrue(
    Pierre-Yves Chibon c104d3
                    '
    Pierre-Yves Chibon c104d3
                    'name="project_documentation" checked=""/>' in output.data)
    Pierre-Yves Chibon c104d3
                self.assertTrue(
    Pierre-Yves Chibon c104d3
                    '
    Pierre-Yves Chibon c104d3
                    'name="issue_tracker" checked=""/>' in 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
            self.assertEqual(
    Pierre-Yves Chibon 0447df
                output.data.count(''), 3)
    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
            self.assertEqual(
    Pierre-Yves Chibon 0447df
                output.data.count(''), 3)
    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
            self.assertEqual(
    Pierre-Yves Chibon 170590
                output.data.count(''), 3)
    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
            self.assertEqual(
    Pierre-Yves Chibon faa629
                output.data.count(''), 3)
    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
            self.assertEqual(
    Pierre-Yves Chibon faa629
                output.data.count(''), 3)
    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
            self.assertEqual(
    Pierre-Yves Chibon faa629
                output.data.count(''), 10)
    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 85d878
            self.assertTrue('

    This repo is brand new!

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertTrue('

    test project #1

    ' in 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 85d878
            self.assertFalse('

    This repo is brand new!

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertFalse('Forked from' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertEqual(
    Pierre-Yves Chibon 85d878
                output.data.count(''), 3)
    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 a923d1
            self.assertFalse('

    This repo is brand new!

    ' in output.data)
    Pierre-Yves Chibon a923d1
            self.assertFalse('Forked from' in output.data)
    Pierre-Yves Chibon a923d1
            self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon a923d1
            self.assertEqual(
    Pierre-Yves Chibon a923d1
                output.data.count(''), 3)
    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 85d878
            self.assertFalse('

    This repo is brand new!

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertTrue('

    test project #1

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertTrue('Forked from' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertEqual(
    Pierre-Yves Chibon 85d878
                output.data.count(''), 3)
    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 85d878
            self.assertFalse('

    This repo is brand new!

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertTrue('

    test project #3

    ' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertTrue('Forked from' in output.data)
    Pierre-Yves Chibon 85d878
            self.assertEqual(
    Pierre-Yves Chibon 85d878
                output.data.count(''), 13)
    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 c56993
            self.assertTrue('<section class="file_content">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                '1'
    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 c56993
            self.assertTrue('<section class="file_content">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                'Binary files cannot be rendered.
    ' in 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 c56993
            self.assertTrue('<section class="file_content">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                'Binary files cannot be rendered.
    ' in 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 c56993
            self.assertTrue('<section class="file_content">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                'Binary files cannot be rendered.
    '
    Pierre-Yves Chibon c56993
                in 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 c56993
            self.assertTrue('<section class="file_content">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                'Binary files cannot be rendered.
    '
    Pierre-Yves Chibon c56993
                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 c56993
            self.assertTrue('<section class="tree_list">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue('

    Tree

    ' in output.data)
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon fee94a
                '' in 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 c56993
            self.assertTrue('<section class="file_content">' in output.data)</section>
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                '1'
    Pierre-Yves Chibon c56993
                in output.data)
    Pierre-Yves Chibon c56993
            self.assertTrue(
    Pierre-Yves Chibon c56993
                '
     barRow 0
    ' in 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 9fab0b
                '

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

    Tree

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

    Tree

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

    Tree

    ' 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.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 550d2b
                self.assertTrue(
    Pierre-Yves Chibon 550d2b
                    '
  • Could not delete all the repos from the '
  • Pierre-Yves Chibon 550d2b
                    'system' in output.data)
    Pierre-Yves Chibon 550d2b
                self.assertTrue('

    Projects (1)

    ' in output.data)
    Pierre-Yves Chibon 550d2b
                self.assertTrue('

    Forks (0)

    ' in 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 550d2b
                    '
  • Could not delete all the repos from the '
  • Pierre-Yves Chibon 550d2b
                    'system' in output.data)
    Pierre-Yves Chibon 550d2b
                self.assertTrue('

    Projects (1)

    ' in output.data)
    Pierre-Yves Chibon 550d2b
                self.assertTrue('

    Forks (0)

    ' in 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 550d2b
                    '
  • Could not delete all the repos from the '
  • Pierre-Yves Chibon 550d2b
                    '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 550d2b
                self.assertTrue('

    Projects (1)

    ' in output.data)
    Pierre-Yves Chibon 550d2b
                self.assertTrue('

    Forks (0)

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

    Projects (1)

    ' in output.data)
    Pierre-Yves Chibon 550d2b
                self.assertTrue('

    Forks (0)

    ' in 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 a8f15b
                output = self.app.get('/new/')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon a8f15b
                self.assertTrue('

    New project

    ' in 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 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 a8f15b
                output = self.app.post('/test/hook_token')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 400)
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                data = {'csrf_token': csrf_token}
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                repo = pagure.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon a8f15b
                self.assertEqual(repo.hook_token, 'aaabbbccc')
    Pierre-Yves Chibon a8f15b
    Pierre-Yves Chibon a8f15b
                output = self.app.post(
    Pierre-Yves Chibon a8f15b
                    '/test/hook_token', data=data, follow_redirects=True)
    Pierre-Yves Chibon a8f15b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon a8f15b
                self.assertIn(
    Pierre-Yves Chibon a8f15b
                    '
  • New hook token generated
  • ',
    Pierre-Yves Chibon a8f15b
                    output.data)
    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 270cef
        @patch('pagure.ui.repo.admin_session_timedout')
    Pierre-Yves Chibon 270cef
        @patch('pagure.lib.git.update_git')
    Pierre-Yves Chibon 270cef
        def test_regenerate_git(self, upgit, ast):
    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 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 270cef
                self.assertTrue('

    New project

    ' in 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 270cef
                data['regenerate'] = 'tickets'
    Pierre-Yves Chibon 270cef
                output = self.app.post(
    Pierre-Yves Chibon 270cef
                    '/test/regenerate', data=data, follow_redirects=True)
    Pierre-Yves Chibon 270cef
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 270cef
                self.assertIn(
    Pierre-Yves Chibon 270cef
                    '
  • Tickets git repo updated
  • ',
    Pierre-Yves Chibon 270cef
                    output.data)
    Pierre-Yves Chibon 270cef
    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 270cef
                    '
  • 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 d5c012
            output = self.app.get('/foo/tags')
    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 d5c012
            output = self.app.get('/test/tags')
    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 d5c012
            output = self.app.get('/test/tags')
    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 d5c012
            output = self.app.get('/test/tags')
    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 39d6c0
                    'master/sources',
    Pierre-Yves Chibon 39d6c0
                    output.data)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon 39d6c0
                    '
    Pierre-Yves Chibon 39d6c0
                    'name="content">', 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 39d6c0
                    '
  • Changes committed
  • ', 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 39d6c0
                    ''
    Pierre-Yves Chibon 39d6c0
                    'master/sources', output.data)
    Pierre-Yves Chibon 39d6c0
                self.assertIn(
    Pierre-Yves Chibon 39d6c0
                    '
    Pierre-Yves Chibon 39d6c0
                    'name="content">', output.data)
    Pierre-Yves Chibon 39d6c0
    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)