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 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 78ce15
import progit.lib
Pierre-Yves Chibon 78ce15
import tests
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
class ProgitFlaskRepotests(tests.Modeltests):
Pierre-Yves Chibon 78ce15
    """ Tests for flask app controller of progit """
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 78ce15
        super(ProgitFlaskRepotests, self).setUp()
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
        progit.APP.config['TESTING'] = True
Pierre-Yves Chibon 78ce15
        progit.SESSION = self.session
Pierre-Yves Chibon 78ce15
        progit.ui.SESSION = self.session
Pierre-Yves Chibon 78ce15
        progit.ui.app.SESSION = self.session
Pierre-Yves Chibon 78ce15
        progit.ui.repo.SESSION = self.session
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
        progit.APP.config['GIT_FOLDER'] = tests.HERE
Pierre-Yves Chibon 78ce15
        progit.APP.config['FORK_FOLDER'] = os.path.join(
Pierre-Yves Chibon 78ce15
            tests.HERE, 'forks')
Pierre-Yves Chibon 78ce15
        progit.APP.config['TICKETS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 78ce15
            tests.HERE, 'tickets')
Pierre-Yves Chibon 78ce15
        progit.APP.config['DOCS_FOLDER'] = os.path.join(
Pierre-Yves Chibon 78ce15
            tests.HERE, 'docs')
Pierre-Yves Chibon 78ce15
        self.app = progit.APP.test_client()
Pierre-Yves Chibon 78ce15
Pierre-Yves Chibon 78ce15
    def test_add_user(self):
Pierre-Yves Chibon 78ce15
        """ Test the add_user endpoint. """
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 78ce15
        with tests.user_set(progit.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 78ce15
        user.username = 'pingou'
Pierre-Yves Chibon 78ce15
        with tests.user_set(progit.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 5980f6
        def test_remove_user(self):
    Pierre-Yves Chibon 5980f6
            """ Test the remove_user endpoint. """
    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 5980f6
            with tests.user_set(progit.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 5980f6
            user.username = 'pingou'
    Pierre-Yves Chibon 5980f6
            with tests.user_set(progit.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 5980f6
            repo = progit.lib.get_project(self.session, 'test')
    Pierre-Yves Chibon 5980f6
            msg = progit.lib.add_user_to_project(
    Pierre-Yves Chibon 5980f6
                session=self.session,
    Pierre-Yves Chibon 5980f6
                project=repo,
    Pierre-Yves Chibon 5980f6
                user='foo',
    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 5980f6
            with tests.user_set(progit.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 8cae39
        def test_update_description(self):
    Pierre-Yves Chibon 8cae39
            """ Test the update_description endpoint. """
    Pierre-Yves Chibon 8cae39
            output = self.app.post('/foo/updatedesc')
    Pierre-Yves Chibon 8cae39
            self.assertEqual(output.status_code, 302)
    Pierre-Yves Chibon 8cae39
    Pierre-Yves Chibon 8cae39
            user = tests.FakeUser()
    Pierre-Yves Chibon 8cae39
            with tests.user_set(progit.APP, user):
    Pierre-Yves Chibon 8cae39
                output = self.app.post('/foo/updatedesc')
    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 8cae39
                output = self.app.post('/test/updatedesc')
    Pierre-Yves Chibon 8cae39
                self.assertEqual(output.status_code, 403)
    Pierre-Yves Chibon 8cae39
    Pierre-Yves Chibon 8cae39
            user.username = 'pingou'
    Pierre-Yves Chibon 8cae39
            with tests.user_set(progit.APP, user):
    Pierre-Yves Chibon 8cae39
                output = self.app.post('/test/updatedesc', 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 8cae39
                    '/test/updatedesc', 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 8cae39
                self.assertTrue(
    Pierre-Yves Chibon 8cae39
                    '
  • Description updated
  • '
    Pierre-Yves Chibon 8cae39
                    in output.data)
    Pierre-Yves Chibon 8cae39
    Pierre-Yves Chibon 490ff9
        def test_view_settings(self):
    Pierre-Yves Chibon 490ff9
            """ Test the view_settings endpoint. """
    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 490ff9
            with tests.user_set(progit.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 490ff9
            with tests.user_set(progit.APP, user):
    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
                # Both checkbox checked before
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
    Pierre-Yves Chibon 490ff9
                    'type="checkbox" value="y">' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
    Pierre-Yves Chibon 490ff9
                    'type="checkbox" value="y">' 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 490ff9
                    '
    Pierre-Yves Chibon 490ff9
                    'type="checkbox" value="y">' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
    Pierre-Yves Chibon 490ff9
                    'type="checkbox" value="y">' 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 490ff9
                    '<title>Overview - test - ProGit</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 490ff9
                    '
    Pierre-Yves Chibon 490ff9
                    'type="checkbox" value="y">' in output.data)
    Pierre-Yves Chibon 490ff9
                self.assertTrue(
    Pierre-Yves Chibon 490ff9
                    '
    Pierre-Yves Chibon 490ff9
                    'type="checkbox" value="y">' in output.data)
    Pierre-Yves Chibon 490ff9
    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 0447df
            tests.create_projects_git(tests.HERE)
    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 0447df
            repo = progit.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 0447df
            item = progit.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 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 0447df
                output.data.count(''), 10)
    Pierre-Yves Chibon 0447df
    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 faa629
            tests.create_projects_git(tests.HERE)
    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 faa629
            repo = progit.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 faa629
            item = progit.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 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 85d878
        def test_view_log(self):
    Pierre-Yves Chibon 85d878
            """ Test the view_log endpoint. """
    Pierre-Yves Chibon 85d878
            output = self.app.get('/foo/log')
    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 85d878
            output = self.app.get('/test/log')
    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 85d878
            tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon 85d878
    Pierre-Yves Chibon 85d878
            output = self.app.get('/test/log')
    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 85d878
            output = self.app.get('/test/log')
    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 85d878
            # Turn that repo into a fork
    Pierre-Yves Chibon 85d878
            repo = progit.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 85d878
            output = self.app.get('/test/log')
    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 85d878
            output = self.app.get('/fork/pingou/test/log?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 85d878
            item = progit.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 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 85d878
            output = self.app.get('/fork/pingou/test3/log/fobranch')
    Pierre-Yves Chibon 85d878
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 85d878
    Pierre-Yves Chibon 85d878
            output = self.app.get('/fork/pingou/test3/log')
    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 c56993
            output = self.app.get('/foo/blob/foo/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 c56993
            output = self.app.get('/test/blob/foo/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 c56993
            tests.create_projects_git(tests.HERE)
    Pierre-Yves Chibon c56993
    Pierre-Yves Chibon c56993
            output = self.app.get('/test/blob/foo/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 c56993
            output = self.app.get('/test/blob/master/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 c56993
            output = self.app.get('/test/blob/master/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 c56993
            repo = pygit2.init_repository(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon c56993
            commit = repo.revparse_single('HEAD')
    Pierre-Yves Chibon c56993
    Pierre-Yves Chibon c56993
            output = self.app.get('/test/blob/%s/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 c56993
            output = self.app.get('/test/blob/sources/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 c56993
            output = self.app.get('/test/blob/sources/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 c56993
            output = self.app.get('/test/blob/master/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 c56993
                '' in output.data)
    Pierre-Yves Chibon c56993
    Pierre-Yves Chibon c56993
            # View by image name -- with a non-existant file
    Pierre-Yves Chibon c56993
            output = self.app.get('/test/blob/sources/testfoo.jpg')
    Pierre-Yves Chibon c56993
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon c56993
            output = self.app.get('/test/blob/master/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 c56993
            item = progit.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 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 c56993
            output = self.app.get('/fork/pingou/test3/blob/master/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 0b62d0
            tests.create_projects_git(tests.HERE)
    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_content_git_repo(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 0b62d0
            tests.add_readme_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 0b62d0
            output = self.app.get('/test/raw/master/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 0b62d0
            output = self.app.get('/test/raw/master/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 0b62d0
            output = self.app.get('/test/raw/master/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 0b62d0
            repo = pygit2.init_repository(os.path.join(tests.HERE, 'test.git'))
    Pierre-Yves Chibon 0b62d0
            commit = repo.revparse_single('HEAD')
    Pierre-Yves Chibon 0b62d0
    Pierre-Yves Chibon 0b62d0
            output = self.app.get('/test/raw/%s/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 0b62d0
            output = self.app.get('/test/raw/sources/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 0b62d0
            output = self.app.get('/test/raw/sources/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 0b62d0
            output = self.app.get('/test/raw/master/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 0b62d0
            output = self.app.get('/test/raw/sources/testfoo.jpg')
    Pierre-Yves Chibon 0b62d0
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0b62d0
            output = self.app.get('/test/raw/master/folder1/testfoo.jpg')
    Pierre-Yves Chibon 0b62d0
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0b62d0
    Pierre-Yves Chibon 0b62d0
            output = self.app.get('/test/raw/master/')
    Pierre-Yves Chibon 0b62d0
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 0b62d0
    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 0b62d0
            item = progit.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 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 0b62d0
            output = self.app.get('/fork/pingou/test3/raw/master/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 020fcf
            tests.create_projects_git(tests.HERE)
    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 020fcf
            repo = pygit2.init_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 020fcf
                '+ ProGit' 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 020fcf
            repo = pygit2.init_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 020fcf
            item = progit.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 020fcf
            )
    Pierre-Yves Chibon 020fcf
            self.session.add(item)
    Pierre-Yves Chibon 020fcf
            self.session.commit()
    Pierre-Yves Chibon 020fcf
            forkedgit = os.path.join(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 020fcf
            repo = pygit2.init_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 020fcf
                '+ ProGit' 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 aa655b
            tests.create_projects_git(tests.HERE)
    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 aa655b
            repo = pygit2.init_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 aa655b
    index 0000000..10d2e1c
    Pierre-Yves Chibon aa655b
    --- /dev/null
    Pierre-Yves Chibon aa655b
    +++ b/README.rst
    Pierre-Yves Chibon aa655b
    @@ -0,0 +1,17 @@
    Pierre-Yves Chibon aa655b
    +ProGit
    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 aa655b
    +ProGit is a light-weight git-centered forge based on pygit2.
    Pierre-Yves Chibon aa655b
    +
    Pierre-Yves Chibon aa655b
    +Currently, ProGit offers a decent web-interface for git repositories, a
    Pierre-Yves Chibon aa655b
    +simplistic ticket system (that needs improvements) and possibilities to create
    Pierre-Yves Chibon aa655b
    +new projects, fork existing ones and create/merge pull-requests across or
    Pierre-Yves Chibon aa655b
    +within projects.
    Pierre-Yves Chibon aa655b
    +
    Pierre-Yves Chibon aa655b
    +
    Pierre-Yves Chibon aa655b
    +Homepage: https://github.com/pypingou/ProGit
    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 aa655b
            repo = pygit2.init_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 aa655b
            item = progit.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 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 aa655b
            repo = pygit2.init_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 aa655b
    index 0000000..10d2e1c
    Pierre-Yves Chibon aa655b
    --- /dev/null
    Pierre-Yves Chibon aa655b
    +++ b/README.rst
    Pierre-Yves Chibon aa655b
    @@ -0,0 +1,17 @@
    Pierre-Yves Chibon aa655b
    +ProGit
    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 aa655b
    +ProGit is a light-weight git-centered forge based on pygit2.
    Pierre-Yves Chibon aa655b
    +
    Pierre-Yves Chibon aa655b
    +Currently, ProGit offers a decent web-interface for git repositories, a
    Pierre-Yves Chibon aa655b
    +simplistic ticket system (that needs improvements) and possibilities to create
    Pierre-Yves Chibon aa655b
    +new projects, fork existing ones and create/merge pull-requests across or
    Pierre-Yves Chibon aa655b
    +within projects.
    Pierre-Yves Chibon aa655b
    +
    Pierre-Yves Chibon aa655b
    +
    Pierre-Yves Chibon aa655b
    +Homepage: https://github.com/pypingou/ProGit
    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 027b38
            tests.create_projects_git(tests.HERE)
    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 027b38
                '

    \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 027b38
            repo = pygit2.init_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 027b38
            item = progit.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 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 027b38
                ''
    Pierre-Yves Chibon 027b38
                in output.data)
    Pierre-Yves Chibon 027b38
            self.assertTrue(
    Pierre-Yves Chibon 027b38
                ''
    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 550d2b
        def test_delete_repo(self):
    Pierre-Yves Chibon 550d2b
            """ Test the delete_repo endpoint. """
    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 550d2b
            with tests.user_set(progit.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 550d2b
            with tests.user_set(progit.APP, user):
    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 550d2b
                item = progit.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 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 550d2b
                item = progit.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 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 550d2b
                item = progit.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 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
                tests.create_projects_git(os.path.join(tests.HERE, 'tickets'))
    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 550d2b
                # Add a fork of a fork
    Pierre-Yves Chibon 550d2b
                item = progit.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 550d2b
                    parent_id=1,
    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 78ce15
    Pierre-Yves Chibon 78ce15
    if __name__ == '__main__':
    Pierre-Yves Chibon 78ce15
        SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitFlaskRepotests)
    Pierre-Yves Chibon 78ce15
        unittest.TextTestRunner(verbosity=2).run(SUITE)