Blame tests/test_pagure_flask_ui_repo_view_file.py

Pierre-Yves Chibon 12829b
# -*- coding: utf-8 -*-
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
"""
Pierre-Yves Chibon 12829b
 (c) 2017 - Copyright Red Hat Inc
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
 Authors:
Pierre-Yves Chibon 12829b
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
"""
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
import unittest
Pierre-Yves Chibon 12829b
import sys
Pierre-Yves Chibon 12829b
import os
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
import pygit2
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon 12829b
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
import pagure  # noqa
Pierre-Yves Chibon 12829b
import pagure.lib  # noqa
Pierre-Yves Chibon 12829b
import tests  # noqa
Pierre-Yves Chibon 12829b
from pagure.lib.repo import PagureRepo  # noqa
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
class LocalBasetests(tests.Modeltests):
Pierre-Yves Chibon 12829b
    """ Tests for view_file endpoint of the flask pagure app """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def setUp(self):
Pierre-Yves Chibon 12829b
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 12829b
        super(LocalBasetests, self).setUp()
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon b130e5
        pagure.config.config['VIRUS_SCAN_ATTACHMENTS'] = False
Pierre-Yves Chibon b130e5
        pagure.config.config['UPLOAD_FOLDER_URL'] = '/releases/'
Pierre-Yves Chibon b130e5
        pagure.config.config['UPLOAD_FOLDER_PATH'] = os.path.join(
Pierre-Yves Chibon 12829b
            self.path, 'releases')
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
class PagureFlaskRepoViewFileSimpletests(LocalBasetests):
Pierre-Yves Chibon 12829b
    """ Tests for view_file endpoint of the flask pagure app """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_no_project(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file when the project is unknown. """
Pierre-Yves Chibon 12829b
        output = self.app.get('/foo/blob/foo/f/sources')
Pierre-Yves Chibon 12829b
        # No project registered in the DB
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_no_git(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file when the project has no git repo. """
Pierre-Yves Chibon 12829b
        tests.create_projects(self.session)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/foo/f/sources')
Pierre-Yves Chibon 12829b
        # No git repo associated
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_no_git_content(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file when the file doesn't exist. """
Pierre-Yves Chibon 12829b
        tests.create_projects(self.session)
Pierre-Yves Chibon 12829b
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/foo/f/sources')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
class PagureFlaskRepoViewFiletests(LocalBasetests):
Pierre-Yves Chibon 12829b
    """ Tests for view_file endpoint of the flask pagure app """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def setUp(self):
Pierre-Yves Chibon 12829b
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon 12829b
        super(PagureFlaskRepoViewFiletests, self).setUp()
Pierre-Yves Chibon 12829b
        tests.create_projects(self.session)
Pierre-Yves Chibon 12829b
        tests.create_projects_git(
Pierre-Yves Chibon 12829b
            os.path.join(self.path, 'repos'), bare=True)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # Add some content to the git repo
Pierre-Yves Chibon 12829b
        tests.add_content_git_repo(
Pierre-Yves Chibon 12829b
            os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 12829b
        tests.add_readme_git_repo(
Pierre-Yves Chibon 12829b
            os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 12829b
        tests.add_binary_git_repo(
Pierre-Yves Chibon 12829b
            os.path.join(self.path, 'repos', 'test.git'), 'test.jpg')
Pierre-Yves Chibon 12829b
        tests.add_binary_git_repo(
Pierre-Yves Chibon 12829b
            os.path.join(self.path, 'repos', 'test.git'), 'test_binary')
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_invalid_file(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file when the file doesn't exist. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/foofile')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/sources/f/testfoo.jpg')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/f/folder1/testfoo.jpg')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 404)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_basic_text(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file with a basic text file. """
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/f/sources')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertTrue('' in output.data)
Pierre-Yves Chibon 12829b
        self.assertTrue(
Pierre-Yves Chibon 12829b
            '
Pierre-Yves Chibon 12829b
            'data-line-number="1">'
Pierre-Yves Chibon 12829b
            in output.data)
Pierre-Yves Chibon 12829b
        self.assertTrue(
Pierre-Yves Chibon 12829b
            '
 bar
' in output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_empty_file(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file with an empty file. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # Empty files should also be displayed
Pierre-Yves Chibon 12829b
        tests.add_content_to_git(
Pierre-Yves Chibon 12829b
            os.path.join(self.path, 'repos', 'test.git'),
Pierre-Yves Chibon 12829b
            filename="emptyfile.md",
Pierre-Yves Chibon 12829b
            content="")
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/f/emptyfile.md')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            '
Pierre-Yves Chibon 12829b
            'href="/test/raw/master/f/emptyfile.md" '
Pierre-Yves Chibon 12829b
            'title="View as raw">Raw', output.data)
Pierre-Yves Chibon 12829b
        self.assertIn(
Ryan Lerch eef090
            '
\n'
Pierre-Yves Chibon 12829b
            '        \n      ', output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_binary_file(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file with a binary file. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # View what's supposed to be an image
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/f/test.jpg')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            'Binary files cannot be rendered.
', output.data)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            'view the raw version',
Pierre-Yves Chibon 12829b
            output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_by_commit(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file in a specific commit. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # View by commit id
Pierre-Yves Chibon 12829b
        repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon 12829b
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/%s/f/test.jpg' % commit.oid.hex)
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            'Binary files cannot be rendered.
', output.data)
Pierre-Yves Chibon 12829b
        self.assertIn('/f/test.jpg">view the raw version', output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_by_name(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file via a image name. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # View by image name -- somehow we support this
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/sources/f/test.jpg')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            'Binary files cannot be rendered.
', output.data)
Pierre-Yves Chibon 12829b
        self.assertIn('/f/test.jpg">view the raw version', output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_binary_file2(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file with a binary file (2). """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # View binary file
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/sources/f/test_binary')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn('/f/test_binary">view the raw version', output.data)
Pierre-Yves Chibon 12829b
        self.assertTrue(
Pierre-Yves Chibon 12829b
            'Binary files cannot be rendered.
'
Pierre-Yves Chibon 12829b
            in output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_for_folder(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file with a folder. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # View folder
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/f/folder1')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            '',
Pierre-Yves Chibon 12829b
            output.data)
Pierre-Yves Chibon 12829b
        self.assertIn('<title>Tree - test - Pagure</title>', output.data)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            '', output.data)
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
    def test_view_file_nested_file(self):
Pierre-Yves Chibon 12829b
        """ Test the view_file with a nested file. """
Pierre-Yves Chibon 12829b
Pierre-Yves Chibon 12829b
        # Verify the nav links correctly when viewing a nested folder/file.
Pierre-Yves Chibon 12829b
        output = self.app.get('/test/blob/master/f/folder1/folder2/file')
Pierre-Yves Chibon 12829b
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 12829b
        self.assertIn(
Pierre-Yves Chibon 12829b
            '
  • \n'
  • Pierre-Yves Chibon 12829b
                '            '
    Pierre-Yves Chibon 12829b
                '  folder2\n'
    Pierre-Yves Chibon 12829b
                '          ', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_non_ascii_file(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file with a non-ascii file name. """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            # View file with a non-ascii name
    Pierre-Yves Chibon 12829b
            tests.add_commit_git_repo(
    Pierre-Yves Chibon 12829b
                os.path.join(self.path, 'repos', 'test.git'),
    Pierre-Yves Chibon 12829b
                ncommits=1, filename='Šource')
    Pierre-Yves Chibon 12829b
            output = self.app.get('/test/blob/master/f/Šource')
    Pierre-Yves Chibon 12829b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
            self.assertEqual(output.headers['Content-Type'].lower(),
    Pierre-Yves Chibon 12829b
                             'text/html; charset=utf-8')
    Pierre-Yves Chibon 12829b
            self.assertIn('  Šource', output.data)
    Pierre-Yves Chibon 12829b
            self.assertIn('', output.data)
    Pierre-Yves Chibon 12829b
            self.assertIn(
    Pierre-Yves Chibon 12829b
                '
    Pierre-Yves Chibon 12829b
                'data-line-number="1">', output.data)
    Pierre-Yves Chibon 12829b
            self.assertTrue(
    Pierre-Yves Chibon 12829b
                '
    Row 0
    '
    Pierre-Yves Chibon 12829b
                in output.data
    Pierre-Yves Chibon 12829b
                or
    Pierre-Yves Chibon 12829b
                '
    Row 0
    ' in output.data
    Pierre-Yves Chibon 12829b
            )
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_fork_and_edit_logged_out(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file fork and edit button presence when logged
    Pierre-Yves Chibon 12829b
            out.
    Pierre-Yves Chibon 12829b
            """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            # not logged in, no edit button but fork & edit is there
    Pierre-Yves Chibon 12829b
            output = self.app.get('/test/blob/master/f/sources')
    Pierre-Yves Chibon 12829b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
            self.assertNotIn(
    Pierre-Yves Chibon 12829b
                '
    Pierre-Yves Chibon 12829b
                'href="/test/edit/master/f/sources" title="Edit file">'
    Pierre-Yves Chibon 12829b
                'Edit', output.data)
    Pierre-Yves Chibon 12829b
            self.assertIn(
    Pierre-Yves Chibon 12829b
                'onclick="fork_project.submit();">\n                    '
    Pierre-Yves Chibon 12829b
                '        Fork and Edit', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 025aab
        def test_view_file_fork_and_edit_logged_in(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file fork and edit button presence when logged
    Pierre-Yves Chibon 12829b
            in.
    Pierre-Yves Chibon 12829b
            """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            # logged in, both buttons are there
    Pierre-Yves Chibon 12829b
            user = tests.FakeUser(username='pingou')
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 12829b
                output = self.app.get('/test/blob/master/f/sources')
    Pierre-Yves Chibon 12829b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
                self.assertIn(
    Pierre-Yves Chibon 12829b
                    '
    Pierre-Yves Chibon 12829b
                    'href="/test/edit/master/f/sources" title="Edit file">'
    Pierre-Yves Chibon 12829b
                    'Edit', output.data)
    Pierre-Yves Chibon 12829b
                self.assertIn(
    Pierre-Yves Chibon 12829b
                    'onclick="fork_project.submit();">\n                    '
    Pierre-Yves Chibon 12829b
                '        Fork and Edit', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 025aab
    class PagureFlaskRepoViewFileForktests(LocalBasetests):
    Pierre-Yves Chibon 12829b
        """ Tests for view_file endpoint of the flask pagure app for a fork """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def setUp(self):
    Pierre-Yves Chibon 12829b
            """ Set up the environnment, ran before every tests. """
    Pierre-Yves Chibon 12829b
            super(PagureFlaskRepoViewFileForktests, self).setUp()
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 025aab
            tests.create_projects(self.session)
    Pierre-Yves Chibon 025aab
            tests.create_projects_git(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos'), bare=True)
    Pierre-Yves Chibon 025aab
    Pierre-Yves Chibon 025aab
            # Add some content to the git repo
    Pierre-Yves Chibon 025aab
            tests.add_content_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'test.git'))
    Pierre-Yves Chibon 025aab
            tests.add_readme_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'test.git'))
    Pierre-Yves Chibon 025aab
            tests.add_binary_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'test.git'), 'test.jpg')
    Pierre-Yves Chibon 025aab
            tests.add_binary_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'test.git'), 'test_binary')
    Pierre-Yves Chibon 025aab
    Pierre-Yves Chibon 12829b
            # Add a fork of a fork
    Pierre-Yves Chibon 12829b
            item = pagure.lib.model.Project(
    Pierre-Yves Chibon 12829b
                user_id=1,  # pingou
    Pierre-Yves Chibon 025aab
                name='test',
    Pierre-Yves Chibon 12829b
                description='test project #3',
    Pierre-Yves Chibon 12829b
                is_fork=True,
    Pierre-Yves Chibon 12829b
                parent_id=1,
    Pierre-Yves Chibon 12829b
                hook_token='aaabbbppp',
    Pierre-Yves Chibon 12829b
            )
    Pierre-Yves Chibon 12829b
            self.session.add(item)
    Pierre-Yves Chibon 12829b
            self.session.commit()
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            tests.add_content_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'))
    Pierre-Yves Chibon 12829b
            tests.add_readme_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'))
    Pierre-Yves Chibon 12829b
            tests.add_commit_git_repo(
    Pierre-Yves Chibon 025aab
                os.path.join(self.path, 'repos', 'forks', 'pingou', 'test.git'),
    Pierre-Yves Chibon 12829b
                ncommits=10)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_nested_file_in_fork(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file with a nested file in fork. """
    Pierre-Yves Chibon 12829b
            # Verify the nav links correctly when viewing a file/folder in a fork.
    Pierre-Yves Chibon 12829b
            output = self.app.get(
    Pierre-Yves Chibon 025aab
                '/fork/pingou/test/blob/master/f/folder1/folder2/file')
    Pierre-Yves Chibon 12829b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
            self.assertIn(
    Pierre-Yves Chibon 025aab
                '
  • \n'
  • Pierre-Yves Chibon 12829b
                '              '
    Pierre-Yves Chibon 12829b
                'folder2\n          ', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_in_branch_in_fork(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file in a specific branch of a fork. """
    Pierre-Yves Chibon 025aab
            output = self.app.get('/fork/pingou/test/blob/master/f/sources')
    Pierre-Yves Chibon 12829b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
            self.assertIn('', output.data)
    Pierre-Yves Chibon 12829b
            self.assertIn(
    Pierre-Yves Chibon 12829b
                '
    Pierre-Yves Chibon 12829b
                'data-line-number="1">',
    Pierre-Yves Chibon 12829b
                output.data)
    Pierre-Yves Chibon 12829b
            self.assertIn(
    Pierre-Yves Chibon 12829b
                '
     barRow 0
    ', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_fork_and_edit_on_fork_logged_out(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file on a text file on a fork when logged out. """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            # not logged in, no edit button but fork & edit is there
    Pierre-Yves Chibon 025aab
            output = self.app.get('/fork/pingou/test/blob/master/f/sources')
    Pierre-Yves Chibon 12829b
            self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
            self.assertNotIn(
    Pierre-Yves Chibon 12829b
                '
    Pierre-Yves Chibon 12829b
                'href="/test/edit/master/f/sources" title="Edit file">'
    Pierre-Yves Chibon 12829b
                'Edit', output.data)
    Pierre-Yves Chibon 12829b
            self.assertIn(
    Pierre-Yves Chibon 12829b
                'onclick="fork_project.submit();">\n                    '
    Pierre-Yves Chibon 12829b
                '        Fork and Edit', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_fork_and_edit_on_your_fork(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file on a text file on your fork when logged in.
    Pierre-Yves Chibon 12829b
            """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            # logged in, but it's your own fork, so just edit button is there
    Pierre-Yves Chibon 12829b
            user = tests.FakeUser(username='pingou')
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 025aab
                output = self.app.get('/fork/pingou/test/blob/master/f/sources')
    Pierre-Yves Chibon 12829b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
                self.assertIn(
    Pierre-Yves Chibon 12829b
                    '
    Pierre-Yves Chibon 025aab
                    'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
    Pierre-Yves Chibon 12829b
                    'Edit', output.data)
    Pierre-Yves Chibon 12829b
                self.assertNotIn(
    Pierre-Yves Chibon 12829b
                    'onclick="fork_project.submit();">\n                    '
    Pierre-Yves Chibon 12829b
                '        Fork and Edit', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
        def test_view_file_fork_and_edit_on_a_fork(self):
    Pierre-Yves Chibon 12829b
            """ Test the view_file on a text file on somone else's fork when
    Pierre-Yves Chibon 12829b
            logged in.
    Pierre-Yves Chibon 12829b
            """
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
            # logged in, but it's not your fork, so only fork and edit button
    Pierre-Yves Chibon 12829b
            # is there
    Pierre-Yves Chibon 12829b
            user = tests.FakeUser(username='foo')
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 025aab
                output = self.app.get('/fork/pingou/test/blob/master/f/sources')
    Pierre-Yves Chibon 12829b
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 12829b
                self.assertNotIn(
    Pierre-Yves Chibon 12829b
                    '
    Pierre-Yves Chibon 025aab
                    'href="/fork/pingou/test/edit/master/f/sources" title="Edit file">'
    Pierre-Yves Chibon 12829b
                    'Edit', output.data)
    Pierre-Yves Chibon 12829b
                self.assertIn(
    Pierre-Yves Chibon 12829b
                    'onclick="fork_project.submit();">\n                    '
    Pierre-Yves Chibon 12829b
                '        Fork and Edit', output.data)
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 025aab
        def test_view_file_fork_and_edit_on_project(self):
    Pierre-Yves Chibon 025aab
            """ Test the view_file on a text file on somone else's fork when
    Pierre-Yves Chibon 025aab
            logged in.
    Pierre-Yves Chibon 025aab
            """
    Pierre-Yves Chibon 025aab
    Pierre-Yves Chibon 025aab
            # logged in and seeing the project you forked
    Pierre-Yves Chibon 025aab
            user = tests.FakeUser(username='pingou')
    Pierre-Yves Chibon b130e5
            with tests.user_set(self.app.application, user):
    Pierre-Yves Chibon 025aab
                output = self.app.get('/test/blob/master/f/sources')
    Pierre-Yves Chibon 025aab
                self.assertEqual(output.status_code, 200)
    Pierre-Yves Chibon 025aab
                self.assertIn(
    Pierre-Yves Chibon 025aab
                    '
    Pierre-Yves Chibon 025aab
                    'href="/test/edit/master/f/sources" title="Edit file">'
    Pierre-Yves Chibon 025aab
                    'Edit', output.data)
    Pierre-Yves Chibon 025aab
                self.assertIn(
    Pierre-Yves Chibon 025aab
                    'onclick="fork_project.submit();">\n                    '
    Pierre-Yves Chibon 025aab
                '        Edit in your fork', output.data)
    Pierre-Yves Chibon 025aab
    Pierre-Yves Chibon 12829b
    Pierre-Yves Chibon 12829b
    if __name__ == '__main__':
    Pierre-Yves Chibon 12829b
        unittest.main(verbosity=2)