Blame tests/test_pagure_flask_ui_slash_branch_name.py

Pierre-Yves Chibon 016a1b
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
"""
Pierre-Yves Chibon 016a1b
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
 Authors:
Pierre-Yves Chibon 016a1b
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
"""
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon 016a1b
import pkg_resources
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
import json
Pierre-Yves Chibon 016a1b
import unittest
Pierre-Yves Chibon 016a1b
import shutil
Pierre-Yves Chibon 016a1b
import sys
Pierre-Yves Chibon 016a1b
import tempfile
Pierre-Yves Chibon 016a1b
import os
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
import pygit2
Pierre-Yves Chibon 016a1b
from mock import patch
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 016a1b
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
import pagure.lib
Pierre-Yves Chibon 016a1b
import tests
Pierre-Yves Chibon 27a73d
from pagure.lib.repo import PagureRepo
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
class PagureFlaskSlashInBranchtests(tests.Modeltests):
Pierre-Yves Chibon 016a1b
    """ Tests for flask application when the branch name contains a '/'.
Pierre-Yves Chibon 016a1b
    """
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
    def setUp(self):
Pierre-Yves Chibon 016a1b
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 016a1b
        super(PagureFlaskSlashInBranchtests, self).setUp()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        pagure.APP.config['TESTING'] = True
Pierre-Yves Chibon 016a1b
        pagure.SESSION = self.session
Pierre-Yves Chibon 016a1b
        pagure.lib.SESSION = self.session
Pierre-Yves Chibon 016a1b
        pagure.ui.app.SESSION = self.session
Pierre-Yves Chibon 016a1b
        pagure.ui.filters.SESSION = self.session
Pierre-Yves Chibon 016a1b
        pagure.ui.fork.SESSION = self.session
Pierre-Yves Chibon 016a1b
        pagure.ui.repo.SESSION = self.session
Pierre-Yves Chibon 016a1b
Jeremy Cline 20109f
        pagure.APP.config['GIT_FOLDER'] = os.path.join(self.path, 'repos')
Pierre-Yves Chibon 016a1b
        pagure.APP.config['TICKETS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'tickets')
Pierre-Yves Chibon 016a1b
        pagure.APP.config['DOCS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'docs')
Pierre-Yves Chibon 016a1b
        pagure.APP.config['REQUESTS_FOLDER'] = os.path.join(
Jeremy Cline 20109f
            self.path, 'requests')
Pierre-Yves Chibon 016a1b
        self.app = pagure.APP.test_client()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
    def set_up_git_repo(self):
Pierre-Yves Chibon 016a1b
        """ Set up the git repo to play with. """
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # Create a git repo to play with
Jeremy Cline 20109f
        gitrepo = os.path.join(self.path, 'repos', 'test.git')
Pierre-Yves Chibon 016a1b
        repo = pygit2.init_repository(gitrepo, bare=True)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        newpath = tempfile.mkdtemp(prefix='pagure-other-test')
Pierre-Yves Chibon 016a1b
        repopath = os.path.join(newpath, 'test')
Pierre-Yves Chibon 016a1b
        clone_repo = pygit2.clone_repository(gitrepo, repopath)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # Create a file in that git repo
Pierre-Yves Chibon 016a1b
        with open(os.path.join(repopath, 'sources'), 'w') as stream:
Pierre-Yves Chibon 016a1b
            stream.write('foo\n bar')
Pierre-Yves Chibon 016a1b
        clone_repo.index.add('sources')
Pierre-Yves Chibon 016a1b
        clone_repo.index.write()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # Commits the files added
Pierre-Yves Chibon 016a1b
        tree = clone_repo.index.write_tree()
Pierre-Yves Chibon 016a1b
        author = pygit2.Signature(
Pierre-Yves Chibon 016a1b
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 016a1b
        committer = pygit2.Signature(
Pierre-Yves Chibon 016a1b
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 016a1b
        clone_repo.create_commit(
Pierre-Yves Chibon 016a1b
            'refs/heads/master',  # the name of the reference to update
Pierre-Yves Chibon 016a1b
            author,
Pierre-Yves Chibon 016a1b
            committer,
Pierre-Yves Chibon 016a1b
            'Add sources file for testing',
Pierre-Yves Chibon 016a1b
            # binary string representing the tree object ID
Pierre-Yves Chibon 016a1b
            tree,
Pierre-Yves Chibon 016a1b
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 016a1b
            []
Pierre-Yves Chibon 016a1b
        )
Pierre-Yves Chibon 016a1b
        refname = 'refs/heads/master'
Pierre-Yves Chibon 016a1b
        ori_remote = clone_repo.remotes[0]
Pierre-Yves Chibon 27a73d
        PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        master_branch = clone_repo.lookup_branch('master')
Pierre-Yves Chibon 016a1b
        first_commit = master_branch.get_object().hex
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # Second commit
Pierre-Yves Chibon 016a1b
        with open(os.path.join(repopath, '.gitignore'), 'w') as stream:
Pierre-Yves Chibon 016a1b
            stream.write('*~')
Pierre-Yves Chibon 016a1b
        clone_repo.index.add('.gitignore')
Pierre-Yves Chibon 016a1b
        clone_repo.index.write()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        tree = clone_repo.index.write_tree()
Pierre-Yves Chibon 016a1b
        author = pygit2.Signature(
Pierre-Yves Chibon 016a1b
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 016a1b
        committer = pygit2.Signature(
Pierre-Yves Chibon 016a1b
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 016a1b
        clone_repo.create_commit(
Pierre-Yves Chibon 016a1b
            'refs/heads/maxamilion/feature',
Pierre-Yves Chibon 016a1b
            author,
Pierre-Yves Chibon 016a1b
            committer,
Pierre-Yves Chibon 016a1b
            'Add .gitignore file for testing',
Pierre-Yves Chibon 016a1b
            # binary string representing the tree object ID
Pierre-Yves Chibon 016a1b
            tree,
Pierre-Yves Chibon 016a1b
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 016a1b
            [first_commit]
Pierre-Yves Chibon 016a1b
        )
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        refname = 'refs/heads/maxamilion/feature'
Pierre-Yves Chibon 016a1b
        ori_remote = clone_repo.remotes[0]
Pierre-Yves Chibon 27a73d
        PagureRepo.push(ori_remote, refname)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        shutil.rmtree(newpath)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 016a1b
    def test_view_repo(self, send_email):
Pierre-Yves Chibon 016a1b
        """ Test the view_repo endpoint when the git repo has no master
Pierre-Yves Chibon 016a1b
        branch.
Pierre-Yves Chibon 016a1b
        """
Pierre-Yves Chibon 016a1b
        send_email.return_value = True
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        tests.create_projects(self.session)
Pierre-Yves Chibon 016a1b
        # Non-existant git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        self.set_up_git_repo()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # With git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 19b2ae
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n '
Pierre-Yves Chibon 058fe8
            '
Contributors
', output.data)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 016a1b
    def test_view_repo_branch(self, send_email):
Pierre-Yves Chibon 016a1b
        """ Test the view_repo_branch endpoint when the git repo has no
Pierre-Yves Chibon 016a1b
        master branch.
Pierre-Yves Chibon 016a1b
        """
Pierre-Yves Chibon 016a1b
        send_email.return_value = True
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        tests.create_projects(self.session)
Pierre-Yves Chibon 016a1b
        # Non-existant git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/branch/master')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        self.set_up_git_repo()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # With git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/branch/maxamilion/feature')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 19b2ae
        self.assertIn(
Pierre-Yves Chibon 98f2af
            '
\n '
Pierre-Yves Chibon 058fe8
            '
Contributors
', output.data)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 016a1b
    def test_view_commits(self, send_email):
Pierre-Yves Chibon 016a1b
        """ Test the view_commits endpoint when the git repo has no
Pierre-Yves Chibon 016a1b
        master branch.
Pierre-Yves Chibon 016a1b
        """
Pierre-Yves Chibon 016a1b
        send_email.return_value = True
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        tests.create_projects(self.session)
Pierre-Yves Chibon 016a1b
        # Non-existant git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/commits')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        self.set_up_git_repo()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # With git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/commits')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.data.count('
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/commits/maxamilion/feature')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 200)
Ryan Lerch c3b81e
        self.assertIn('<title>Commits - test - Pagure</title>', output.data)
Pierre-Yves Chibon 016a1b
        self.assertIn('Add sources file for testing', output.data)
Pierre-Yves Chibon 016a1b
        self.assertIn('Add .gitignore file for testing', output.data)
Ryan Lerch 7bc3d6
        self.assertEqual(output.data.count('
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
    @patch('pagure.lib.notify.send_email')
Pierre-Yves Chibon 016a1b
    def test_view_file(self, send_email):
Pierre-Yves Chibon 016a1b
        """ Test the view_file endpoint when the git repo has no
Pierre-Yves Chibon 016a1b
        master branch.
Pierre-Yves Chibon 016a1b
        """
Pierre-Yves Chibon 016a1b
        send_email.return_value = True
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        tests.create_projects(self.session)
Pierre-Yves Chibon 016a1b
        # Non-existant git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/blob/master/f/sources')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        self.set_up_git_repo()
Pierre-Yves Chibon 016a1b
Pierre-Yves Chibon 016a1b
        # With git repo
Pierre-Yves Chibon 016a1b
        output = self.app.get('/test/blob/master/f/sources')
Pierre-Yves Chibon 016a1b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 016a1b
        self.assertIn(
Pierre-Yves Chibon 557220
            '''
Pierre-Yves Chibon 557220
        
    Pierre-Yves Chibon 557220
              
  1. Pierre-Yves Chibon 557220
                
    Pierre-Yves Chibon 557220
                  
    Pierre-Yves Chibon 557220
                    master
    Pierre-Yves Chibon 557220
                
    Pierre-Yves Chibon 557220
              
    Pierre-Yves Chibon 557220
              
  2. Pierre-Yves Chibon 557220
                
    Pierre-Yves Chibon 557220
                  sources
    Pierre-Yves Chibon 557220
              
    Pierre-Yves Chibon 557220
            ''', output.data)
    Pierre-Yves Chibon 016a1b
    Pierre-Yves Chibon 016a1b
            output = self.app.get('/test/blob/master/f/.gitignore')
    Pierre-Yves Chibon 016a1b
            self.assertEqual(output.status_code, 404)
    Pierre-Yves Chibon 016a1b
    Pierre-Yves Chibon 016a1b
            output = self.app.get('/test/blob/maxamilion/feature/f/.gitignore')
    Pierre-Yves Chibon 016a1b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 016a1b
            self.assertIn(
    Pierre-Yves Chibon 557220
                '''
    Pierre-Yves Chibon 557220
            
      Pierre-Yves Chibon 557220
                
    1. Pierre-Yves Chibon 557220
                  
      Pierre-Yves Chibon 557220
                    
      Pierre-Yves Chibon 557220
                      maxamilion/feature
      Pierre-Yves Chibon 557220
                  
      Pierre-Yves Chibon 557220
                
      Pierre-Yves Chibon 557220
                
    2. Pierre-Yves Chibon 557220
                  
      Pierre-Yves Chibon 557220
                    .gitignore
      Pierre-Yves Chibon 557220
                
      Pierre-Yves Chibon 557220
              ''', output.data)
      Pierre-Yves Chibon 0cbbd3
              self.assertTrue(
      Pierre-Yves Chibon 0cbbd3
                  # new version of pygments
      Pierre-Yves Chibon 0cbbd3
                  '
      *~
      ' in output.data
      Pierre-Yves Chibon 0cbbd3
                  or
      Pierre-Yves Chibon 0cbbd3
                  # old version of pygments
      Pierre-Yves Chibon 0cbbd3
                  '
      *~
      ' in output.data)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
          @patch('pagure.lib.notify.send_email')
      Pierre-Yves Chibon 016a1b
          def test_view_raw_file(self, send_email):
      Pierre-Yves Chibon 016a1b
              """ Test the view_raw_file endpoint when the git repo has no
      Pierre-Yves Chibon 016a1b
              master branch.
      Pierre-Yves Chibon 016a1b
              """
      Pierre-Yves Chibon 016a1b
              send_email.return_value = True
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              tests.create_projects(self.session)
      Pierre-Yves Chibon 016a1b
              # Non-existant git repo
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/raw/master')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 404)
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/raw/master/f/sources')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 404)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              self.set_up_git_repo()
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              # With git repo
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/raw/master')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn('diff --git a/sources b/sources', output.data)
      Pierre-Yves Chibon 016a1b
              self.assertIn('+foo\n+ bar', output.data)
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/raw/master/f/sources')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.data, 'foo\n bar')
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/raw/maxamilion/feature')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn('diff --git a/.gitignore b/.gitignore', output.data)
      Pierre-Yves Chibon 016a1b
              self.assertIn('+*~', output.data)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/raw/maxamilion/feature/f/sources')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertEqual('foo\n bar', output.data)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
          @patch('pagure.lib.notify.send_email')
      Pierre-Yves Chibon 016a1b
          def test_view_tree(self, send_email):
      Pierre-Yves Chibon 016a1b
              """ Test the view_tree endpoint when the git repo has no
      Pierre-Yves Chibon 016a1b
              master branch.
      Pierre-Yves Chibon 016a1b
              """
      Pierre-Yves Chibon 016a1b
              send_email.return_value = True
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              tests.create_projects(self.session)
      Pierre-Yves Chibon 016a1b
              # Non-existant git repo
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 404)
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/master')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 404)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              self.set_up_git_repo()
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              # With git repo
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/master')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn('', output.data)
      Pierre-Yves Chibon 19b2ae
              self.assertEqual(
      Pierre-Yves Chibon 19b2ae
                  output.data.count(''), 1)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/master/sources')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn('', output.data)
      Pierre-Yves Chibon 19b2ae
              self.assertEqual(
      Pierre-Yves Chibon 19b2ae
                  output.data.count(''), 1)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/feature')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn('', output.data)
      Pierre-Yves Chibon 19b2ae
              self.assertEqual(
      Pierre-Yves Chibon 19b2ae
                  output.data.count(''), 1)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/maxamilion/feature')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn(
      Pierre-Yves Chibon 016a1b
                  '',
      Pierre-Yves Chibon 016a1b
                  output.data)
      Pierre-Yves Chibon 19b2ae
              self.assertEqual(
      Pierre-Yves Chibon 19b2ae
                  output.data.count(''), 2)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              # Wrong identifier, back onto master
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/tree/maxamilion/feature/f/.gitignore')
      Pierre-Yves Chibon 016a1b
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
              self.assertIn('', output.data)
      Pierre-Yves Chibon 19b2ae
              self.assertEqual(
      Pierre-Yves Chibon 19b2ae
                  output.data.count(''), 1)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
          @patch('pagure.lib.notify.send_email')
      Pierre-Yves Chibon 016a1b
          def test_new_request_pull(self, send_email):
      Pierre-Yves Chibon 016a1b
              """ Test the new_request_pull endpoint when the git repo has no
      Pierre-Yves Chibon 016a1b
              master branch.
      Pierre-Yves Chibon 016a1b
              """
      Pierre-Yves Chibon 016a1b
              send_email.return_value = True
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              tests.create_projects(self.session)
      Pierre-Yves Chibon 016a1b
              # Non-existant git repo
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/diff/master..maxamilion/feature')
      Pierre-Yves Chibon 4fcf92
              # (used to be 302 but seeing a diff is allowed even logged out)
      Pierre-Yves Chibon 4fcf92
              self.assertEqual(output.status_code, 404)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              user = tests.FakeUser()
      Pierre-Yves Chibon 016a1b
              with tests.user_set(pagure.APP, user):
      Pierre-Yves Chibon 016a1b
                  output = self.app.get('/test/diff/master..maxamilion/feature')
      Pierre-Yves Chibon 016a1b
                  self.assertEqual(output.status_code, 404)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              self.set_up_git_repo()
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              output = self.app.get('/test/diff/master..maxamilion/feature')
      Pierre-Yves Chibon 4fcf92
              # (used to be 302 but seeing a diff is allowed even logged out)
      Pierre-Yves Chibon 4fcf92
              self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon fec7de
              self.assertEqual(
      Pierre-Yves Chibon fec7de
                  output.data.count('
      Pierre-Yves Chibon 15a1bc
              self.assertIn(
      Pierre-Yves Chibon 15a1bc
                  ''
      Pierre-Yves Chibon 15a1bc
                  '+1', output.data)
      Pierre-Yves Chibon 15a1bc
              self.assertIn(
      Pierre-Yves Chibon 15a1bc
                  '
      <small>file added</small>
      ', output.data)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
              user = tests.FakeUser()
      Pierre-Yves Chibon 016a1b
              with tests.user_set(pagure.APP, user):
      Pierre-Yves Chibon 016a1b
                  output = self.app.get('/test/diff/master..maxamilion/feature')
      Pierre-Yves Chibon 016a1b
                  self.assertEqual(output.status_code, 200)
      Pierre-Yves Chibon 016a1b
                  self.assertEqual(
      Pierre-Yves Chibon fec7de
                      output.data.count('
      Pierre-Yves Chibon 15a1bc
                  self.assertIn(
      Pierre-Yves Chibon 15a1bc
                      ''
      Pierre-Yves Chibon 15a1bc
                      '+1', output.data)
      Pierre-Yves Chibon 15a1bc
                  self.assertIn(
      Pierre-Yves Chibon 15a1bc
                      '
      <small>file added</small>
      ', output.data)
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
      Pierre-Yves Chibon 016a1b
      if __name__ == '__main__':
      Pierre-Yves Chibon 016a1b
          SUITE = unittest.TestLoader().loadTestsFromTestCase(
      Pierre-Yves Chibon 016a1b
              PagureFlaskSlashInBranchtests)
      Pierre-Yves Chibon 016a1b
          unittest.TextTestRunner(verbosity=2).run(SUITE)