Exemplo n.º 1
0
    def test_view_history_file_fork_of_a_fork(self):
        """ Test the view_history_file endpoint """
        item = pagure.lib.model.Project(
            user_id=1,  # pingou
            name="test3",
            description="test project #3",
            is_fork=True,
            parent_id=1,
            hook_token="aaabbbppp",
        )
        self.session.add(item)
        self.session.commit()

        tests.add_content_git_repo(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"))
        tests.add_readme_git_repo(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"))
        tests.add_commit_git_repo(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),
            ncommits=10,
        )
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),
            content="✨☃🍰☃✨",
        )

        output = self.app.get("/fork/pingou/test3/history/sources")
        self.assertEqual(output.status_code, 200)
        output_text = output.get_data(as_text=True)
        self.assertIn("<strong>Add row 2 to sources file</strong>",
                      output_text)
Exemplo n.º 2
0
    def test_generate_revision_change_log_short_url(self, fixes_relation):
        """ Test generate_revision_change_log when the comment contains
        a short link to the same project.
        """

        # Add a commit with an url in the commit message
        tests.add_content_to_git(
            self.folder,
            branch="master",
            filename="sources",
            content="foo",
            message="Test commit message\n\nFixes #1",
        )

        project = pagure.lib.query.get_authorized_project(self.session, "test")

        pagure.hooks.pagure_hook.generate_revision_change_log(
            session=self.session,
            project=project,
            username=None,
            repodir=self.folder,
            new_commits_list=["HEAD"],
        )
        fixes_relation.assert_called_once_with(
            mock.ANY,
            None,
            mock.ANY,
            project.issues[0],
            "http://localhost.localdomain/",
        )
Exemplo n.º 3
0
    def test_generate_revision_change_log_full_url_fork(self, fixes_relation):
        """ Test generate_revision_change_log when the comment contains
        a full link to a fork.
        """

        # Add a commit with an url in the commit message
        tests.add_content_to_git(
            self.folder,
            branch='master',
            filename='sources',
            content='foo',
            message='Test commit message\n\n'
            'Fixes http://localhost.localdomain/fork/foo/test/issue/1')

        project = pagure.lib.query.get_authorized_project(self.session, 'test')
        project_fork = pagure.lib.query.get_authorized_project(self.session,
                                                               'test',
                                                               user="******")

        pagure.hooks.pagure_hook.generate_revision_change_log(
            session=self.session,
            project=project,
            username=None,
            repodir=self.folder,
            new_commits_list=['HEAD'])
        fixes_relation.assert_called_once_with(
            mock.ANY, None, mock.ANY, project_fork.issues[0],
            'http://localhost.localdomain/')
    def test_generate_revision_change_log_short_url(self, fixes_relation):
        """ Test generate_revision_change_log when the comment contains
        a short link to the same project.
        """

        # Add a commit with an url in the commit message
        tests.add_content_to_git(
            self.folder,
            branch="master",
            filename="sources",
            content="foo",
            message="Test commit message\n\nFixes #1",
        )

        project = pagure.lib.query.get_authorized_project(self.session, "test")

        pagure.hooks.pagure_hook.generate_revision_change_log(
            session=self.session,
            project=project,
            username=None,
            repodir=self.folder,
            new_commits_list=["HEAD"],
        )
        fixes_relation.assert_called_once_with(
            mock.ANY,
            None,
            mock.ANY,
            project.issues[0],
            "http://localhost.localdomain/",
        )
Exemplo n.º 5
0
    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(PagureRebasetests, self).setUp()

        pagure.config.config['REQUESTS_FOLDER'] = None
        tests.create_projects(self.session)
        tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True)
        tests.create_projects_git(os.path.join(self.path, 'requests'),
                                  bare=True)
        tests.add_content_to_git(os.path.join(self.path, 'repos', 'test.git'),
                                 branch='test',
                                 content="foobar")
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))

        # Create a PR for these changes
        project = pagure.lib.query.get_authorized_project(self.session, 'test')
        req = pagure.lib.query.new_pull_request(
            session=self.session,
            repo_from=project,
            branch_from='test',
            repo_to=project,
            branch_to='master',
            title='PR from the test branch',
            user='******',
        )
        self.session.commit()
        self.assertEqual(req.id, 1)
        self.assertEqual(req.title, 'PR from the test branch')

        self.project = pagure.lib.query.get_authorized_project(
            self.session, 'test')
        self.assertEqual(len(project.requests), 1)
        self.request = self.project.requests[0]
Exemplo n.º 6
0
    def test_rebase_api_conflicts(self):
        """ Test the rebase PR API endpoint when logged in from the UI and
        its outcome. """
        tests.add_content_to_git(os.path.join(self.path, 'repos', 'test.git'),
                                 branch='master',
                                 content="foobar baz")

        user = tests.FakeUser(username='******')
        with tests.user_set(self.app.application, user):
            output = self.app.post('/api/0/test/pull-request/1/rebase')
            self.assertEqual(output.status_code, 400)
            data = json.loads(output.get_data(as_text=True))
            self.assertEqual(
                data, {
                    u'error': u'Did not manage to rebase this pull-request',
                    u'error_code': u'ENOCODE'
                })

            data = {
                'requestid': self.request.uid,
                'csrf_token': self.get_csrf()
            }
            output = self.app.post('/pv/pull-request/merge', data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.get_data(as_text=True))
            self.assertEqual(
                data, {
                    u'code': u'CONFLICTS',
                    u'message': u'The pull-request cannot be merged due '
                    u'to conflicts',
                    u'short_code': u'Conflicts'
                })
Exemplo n.º 7
0
    def test_view_history_file_existing_folder(self):
        """ Test the view_history_file endpoint """
        tests.add_content_to_git(os.path.join(self.path, "repos", "test.git"),
                                 folders="foo/bar")

        output = self.app.get("/test/history/foo/bar/")
        self.assertEqual(output.status_code, 200)
        output_text = output.get_data(as_text=True)
        self.assertIn("<strong>Add content to file foo/bar/sources</strong>",
                      output_text)
        data = self.regex.findall(output_text)
        self.assertEqual(len(data), 1)
Exemplo n.º 8
0
    def test_view_file_empty_file(self):
        """ Test the view_file with an empty file. """

        # Empty files should also be displayed
        tests.add_content_to_git(os.path.join(self.path, 'repos', 'test.git'),
                                 filename="emptyfile.md",
                                 content="")
        output = self.app.get('/test/blob/master/f/emptyfile.md')
        self.assertEqual(output.status_code, 200)
        self.assertIn(
            '<a class="btn btn-secondary btn-sm" '
            'href="/test/raw/master/f/emptyfile.md" '
            'title="View as raw">Raw</a>', output.data)
        self.assertIn('<div class="m-a-2">\n'
                      '        \n      </div>', output.data)
Exemplo n.º 9
0
    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(PagureRebaseNotAllowedtests, self).setUp()

        pagure.config.config["REQUESTS_FOLDER"] = None
        tests.create_projects(self.session)
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
        tests.create_projects_git(
            os.path.join(self.path, "requests"), bare=True
        )
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            branch="master",
            content="foobarbaz",
            filename="testfile",
        )
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            branch="test",
            content="foobar",
            filename="sources",
        )
        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))

        # Create a PR for these changes
        project = pagure.lib.query.get_authorized_project(self.session, "test")
        req = pagure.lib.query.new_pull_request(
            session=self.session,
            repo_from=project,
            branch_from="test",
            repo_to=project,
            branch_to="master",
            title="PR from the test branch",
            user="******",
            allow_rebase=False,
        )
        self.session.commit()
        self.assertEqual(req.id, 1)
        self.assertEqual(req.title, "PR from the test branch")

        self.project = pagure.lib.query.get_authorized_project(
            self.session, "test"
        )
        self.assertEqual(len(project.requests), 1)
        self.request = self.project.requests[0]
Exemplo n.º 10
0
    def test_view_file_empty_file(self):
        """ Test the view_file with an empty file. """

        # Empty files should also be displayed
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            filename="emptyfile.md",
            content="",
        )
        output = self.app.get("/test/blob/master/f/emptyfile.md")
        self.assertEqual(output.status_code, 200)
        output_text = output.get_data(as_text=True)
        self.assertIn(
            '<a class="btn btn-secondary btn-sm" '
            'href="/test/raw/master/f/emptyfile.md" '
            'title="View as raw">Raw</a>',
            output_text,
        )
        self.assertIn('<div class="m-2">\n'
                      "        \n      </div>", output_text)
Exemplo n.º 11
0
    def test_rebase_api_conflicts(self):
        """ Test the rebase PR API endpoint when logged in from the UI and
        its outcome. """
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            branch="master",
            content="foobar baz",
        )

        user = tests.FakeUser(username="******")
        with tests.user_set(self.app.application, user):
            output = self.app.post("/api/0/test/pull-request/1/rebase")
            self.assertEqual(output.status_code, 400)
            data = json.loads(output.get_data(as_text=True))
            self.assertEqual(
                data,
                {
                    "error": "Did not manage to rebase this pull-request",
                    "error_code": "ENOCODE",
                },
            )

            data = {
                "requestid": self.request.uid,
                "csrf_token": self.get_csrf(),
            }
            output = self.app.post("/pv/pull-request/merge", data=data)
            self.assertEqual(output.status_code, 200)
            data = json.loads(output.get_data(as_text=True))
            self.assertEqual(
                data,
                {
                    "code": "CONFLICTS",
                    "message": "The pull-request cannot be merged due "
                    "to conflicts",
                    "short_code": "Conflicts",
                },
            )
Exemplo n.º 12
0
    def test_view_blame_file_fork_of_a_fork(self):
        """ Test the view_blame_file endpoint """
        item = pagure.lib.model.Project(
            user_id=1,  # pingou
            name="test3",
            description="test project #3",
            is_fork=True,
            parent_id=1,
            hook_token="aaabbbppp",
        )
        self.session.add(item)
        self.session.commit()

        tests.add_content_git_repo(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"))
        tests.add_readme_git_repo(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"))
        tests.add_commit_git_repo(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),
            ncommits=10,
        )
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),
            content="✨☃🍰☃✨",
        )

        output = self.app.get("/fork/pingou/test3/blame/sources")
        self.assertEqual(output.status_code, 200)
        output_text = output.get_data(as_text=True)
        self.assertIn('<table class="code_table">', output_text)
        self.assertTrue('<tr><td class="cell1"><a id="1" href="#1" '
                        'data-line-number="1"></a></td>' in output_text
                        or '<tr><td class="cell1"><a data-line-number="1" '
                        'href="#1" id="1"></a></td>' in output_text)
        self.assertIn(
            '<td class="cell2"><pre><code> barRow 0</code></pre></td>',
            output_text,
        )
Exemplo n.º 13
0
    def setUp(self):
        """ Set up the environment, ran before every tests. """
        super(PagureFlaskRepoViewHistoryFiletests, self).setUp()
        self.regex = re.compile(r' <div class="list-group-item " id="c_')
        tests.create_projects(self.session)
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

        # Add some content to the git repo
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            message="initial commit",
        )
        tests.add_content_to_git(os.path.join(self.path, "repos", "test.git"),
                                 message="foo")
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            branch="feature",
            content="bar",
            message="bar",
            author=("Aritz Author", "*****@*****.**"),
        )
Exemplo n.º 14
0
    def setUp(self):
        """ Set up the environnment, ran before every tests. """
        super(PagureRebasetests, self).setUp()

        pagure.config.config["REQUESTS_FOLDER"] = None
        tests.create_projects(self.session)
        tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
        tests.create_projects_git(
            os.path.join(self.path, "requests"), bare=True
        )
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "test.git"),
            branch="master",
            content="foobarbaz",
            filename="testfile",
        )
        project = pagure.lib.query.get_authorized_project(self.session, "test")
        # Fork the project
        task = pagure.lib.query.fork_project(
            session=self.session, user="******", repo=project
        )
        self.session.commit()
        self.assertEqual(
            task.get(),
            {
                "endpoint": "ui_ns.view_repo",
                "repo": "test",
                "username": "******",
                "namespace": None,
            },
        )
        tests.add_content_to_git(
            os.path.join(self.path, "repos", "forks", "foo", "test.git"),
            branch="test",
            content="foobar",
            filename="sources",
        )
        fork_repo = pagure.lib.query.get_authorized_project(
            self.session, "test", user="******"
        )

        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))

        # Create a PR for these changes

        req = pagure.lib.query.new_pull_request(
            session=self.session,
            repo_from=fork_repo,
            branch_from="test",
            repo_to=project,
            branch_to="master",
            title="PR from the test branch",
            user="******",
            allow_rebase=True,
        )
        self.session.commit()
        self.assertEqual(req.id, 1)
        self.assertEqual(req.title, "PR from the test branch")

        self.project = pagure.lib.query.get_authorized_project(
            self.session, "test"
        )
        self.assertEqual(len(project.requests), 1)
        self.request = self.project.requests[0]