|
Pierre-Yves Chibon |
ff9832 |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
"""
|
|
Pierre-Yves Chibon |
9071b6 |
(c) 2015-2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
Authors:
|
|
Pierre-Yves Chibon |
ff9832 |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
"""
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Aurélien Bompard |
dcf6f6 |
|
|
Pierre-Yves Chibon |
ff9832 |
import json
|
|
Pierre-Yves Chibon |
ff9832 |
import unittest
|
|
Pierre-Yves Chibon |
ff9832 |
import shutil
|
|
Pierre-Yves Chibon |
ff9832 |
import sys
|
|
Pierre-Yves Chibon |
ff9832 |
import tempfile
|
|
Pierre-Yves Chibon |
ff9832 |
import time
|
|
Pierre-Yves Chibon |
ff9832 |
import os
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
import pygit2
|
|
Pierre-Yves Chibon |
ff9832 |
from mock import patch, MagicMock
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
sys.path.insert(
|
|
Pierre-Yves Chibon |
73d120 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
ff9832 |
import tests
|
|
Pierre-Yves Chibon |
ff9832 |
from pagure.lib.repo import PagureRepo
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
class PagureFlaskPrNoSourcestests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Tests PR in pagure when the source is gone """
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
maxDiff = None
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.send_email", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.notify.fedmsg_publish", MagicMock(return_value=True))
|
|
Pierre-Yves Chibon |
ff9832 |
def setUp(self):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
ff9832 |
super(PagureFlaskPrNoSourcestests, self).setUp()
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Create foo's fork of pingou's test project
|
|
Pierre-Yves Chibon |
ff9832 |
item = pagure.lib.model.Project(
|
|
Pierre-Yves Chibon |
ff9832 |
user_id=2, # foo
|
|
Pierre-Yves Chibon |
73d120 |
name="test",
|
|
Pierre-Yves Chibon |
73d120 |
description="test project #1",
|
|
Pierre-Yves Chibon |
73d120 |
hook_token="aaabbb",
|
|
Pierre-Yves Chibon |
ff9832 |
is_fork=True,
|
|
Pierre-Yves Chibon |
ff9832 |
parent_id=1,
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
self.session.add(item)
|
|
Pierre-Yves Chibon |
ff9832 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ff9832 |
# Create the fork's git repo
|
|
Pierre-Yves Chibon |
73d120 |
repo_path = os.path.join(self.path, "repos", item.path)
|
|
Pierre-Yves Chibon |
ff9832 |
pygit2.init_repository(repo_path, bare=True)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
fork = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test", user="foo"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
self.set_up_git_repo(repo=project, fork=fork)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Ensure things got setup straight
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(len(project.requests), 1)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
0fe9c9 |
# wait for the worker to process the task
|
|
Pierre-Yves Chibon |
0fe9c9 |
path = os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
self.path, "repos", "test.git", "refs", "pull", "1", "head"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
4babe0 |
self.assertTrue(os.path.exists(path))
|
|
Pierre-Yves Chibon |
0fe9c9 |
|
|
Pierre-Yves Chibon |
73d120 |
def set_up_git_repo(self, repo, fork, branch_from="feature"):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Set up the git repo and create the corresponding PullRequest
|
|
Pierre-Yves Chibon |
ff9832 |
object.
|
|
Pierre-Yves Chibon |
ff9832 |
"""
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Clone the main repo
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", repo.path)
|
|
Pierre-Yves Chibon |
73d120 |
newpath = tempfile.mkdtemp(prefix="pagure-fork-test")
|
|
Pierre-Yves Chibon |
73d120 |
repopath = os.path.join(newpath, "test")
|
|
Pierre-Yves Chibon |
ff9832 |
clone_repo = pygit2.clone_repository(gitrepo, repopath)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Create a file in that git repo
|
|
Pierre-Yves Chibon |
73d120 |
with open(os.path.join(repopath, "sources"), "w") as stream:
|
|
Pierre-Yves Chibon |
73d120 |
stream.write("foo\n bar")
|
|
Pierre-Yves Chibon |
73d120 |
clone_repo.index.add("sources")
|
|
Pierre-Yves Chibon |
ff9832 |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Commits the files added
|
|
Pierre-Yves Chibon |
ff9832 |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
73d120 |
author = pygit2.Signature("Alice Author", "alice@authors.tld")
|
|
Pierre-Yves Chibon |
73d120 |
committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
|
|
Pierre-Yves Chibon |
ff9832 |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
73d120 |
"refs/heads/master", # the name of the reference to update
|
|
Pierre-Yves Chibon |
ff9832 |
author,
|
|
Pierre-Yves Chibon |
ff9832 |
committer,
|
|
Pierre-Yves Chibon |
73d120 |
"Add sources file for testing",
|
|
Pierre-Yves Chibon |
ff9832 |
# binary string representing the tree object ID
|
|
Pierre-Yves Chibon |
ff9832 |
tree,
|
|
Pierre-Yves Chibon |
ff9832 |
# list of binary strings representing parents of the new commit
|
|
Pierre-Yves Chibon |
73d120 |
[],
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
73d120 |
refname = "refs/heads/master:refs/heads/master"
|
|
Pierre-Yves Chibon |
ff9832 |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
ff9832 |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
first_commit = clone_repo.revparse_single("HEAD")
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Set the second repo
|
|
Pierre-Yves Chibon |
73d120 |
repopath = os.path.join(self.path, "repos", fork.path)
|
|
Pierre-Yves Chibon |
73d120 |
new_gitrepo = os.path.join(newpath, "fork_test")
|
|
Pierre-Yves Chibon |
ff9832 |
clone_repo = pygit2.clone_repository(repopath, new_gitrepo)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Add the main project as remote repo
|
|
Pierre-Yves Chibon |
73d120 |
upstream_path = os.path.join(self.path, "repos", repo.path)
|
|
Pierre-Yves Chibon |
73d120 |
remote = clone_repo.create_remote("upstream", upstream_path)
|
|
Pierre-Yves Chibon |
ff9832 |
remote.fetch()
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Edit the sources file again
|
|
Pierre-Yves Chibon |
73d120 |
with open(os.path.join(new_gitrepo, "sources"), "w") as stream:
|
|
Pierre-Yves Chibon |
73d120 |
stream.write("foo\n bar\nbaz\n boose")
|
|
Pierre-Yves Chibon |
73d120 |
clone_repo.index.add("sources")
|
|
Pierre-Yves Chibon |
ff9832 |
clone_repo.index.write()
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Commits the files added
|
|
Pierre-Yves Chibon |
ff9832 |
tree = clone_repo.index.write_tree()
|
|
Pierre-Yves Chibon |
73d120 |
author = pygit2.Signature("Alice Author", "alice@authors.tld")
|
|
Pierre-Yves Chibon |
73d120 |
committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
|
|
Pierre-Yves Chibon |
ff9832 |
clone_repo.create_commit(
|
|
Pierre-Yves Chibon |
73d120 |
"refs/heads/%s" % branch_from,
|
|
Pierre-Yves Chibon |
ff9832 |
author,
|
|
Pierre-Yves Chibon |
ff9832 |
committer,
|
|
Pierre-Yves Chibon |
73d120 |
"A commit on branch %s" % branch_from,
|
|
Pierre-Yves Chibon |
ff9832 |
tree,
|
|
Pierre-Yves Chibon |
73d120 |
[first_commit.oid.hex],
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
73d120 |
refname = "refs/heads/%s" % (branch_from)
|
|
Pierre-Yves Chibon |
ff9832 |
ori_remote = clone_repo.remotes[0]
|
|
Pierre-Yves Chibon |
ff9832 |
PagureRepo.push(ori_remote, refname)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Create a PR for these changes
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
930073 |
req = pagure.lib.query.new_pull_request(
|
|
Pierre-Yves Chibon |
ff9832 |
session=self.session,
|
|
Pierre-Yves Chibon |
ff9832 |
repo_from=fork,
|
|
Pierre-Yves Chibon |
ff9832 |
branch_from=branch_from,
|
|
Pierre-Yves Chibon |
ff9832 |
repo_to=project,
|
|
Pierre-Yves Chibon |
73d120 |
branch_to="master",
|
|
Pierre-Yves Chibon |
73d120 |
title="PR from the %s branch" % branch_from,
|
|
Pierre-Yves Chibon |
73d120 |
user="pingou",
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(req.id, 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(req.title, "PR from the %s branch" % branch_from)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
shutil.rmtree(newpath)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
def test_request_pull_reference(self):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Test if there is a reference created for a new PR. """
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(len(project.requests), 1)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", "test.git")
|
|
Pierre-Yves Chibon |
ff9832 |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
ff9832 |
list(repo.listall_references()),
|
|
Pierre-Yves Chibon |
73d120 |
["refs/heads/master", "refs/pull/1/head"],
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
def test_request_pull_fork_reference(self):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Test if there the references created on the fork. """
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test", user="foo"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(len(project.requests), 0)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
ff9832 |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
list(repo.listall_references()), ["refs/heads/feature"]
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
def test_accessing_pr_fork_deleted(self):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Test accessing the PR if the fork has been deleted. """
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Delete fork on disk
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test", user="foo"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
repo_path = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertTrue(os.path.exists(repo_path))
|
|
Pierre-Yves Chibon |
ff9832 |
shutil.rmtree(repo_path)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertFalse(os.path.exists(repo_path))
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Delete fork in the DB
|
|
Pierre-Yves Chibon |
ff9832 |
self.session.delete(project)
|
|
Pierre-Yves Chibon |
ff9832 |
self.session.commit()
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# View the pull-request
|
|
Pierre-Yves Chibon |
73d120 |
output2 = self.app.get("/test/pull-request/1")
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(output2.status_code, 200)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
5da9ba |
def test_accessing_pr_patch_fork_deleted(self):
|
|
Pierre-Yves Chibon |
5da9ba |
""" Test accessing the PR's patch if the fork has been deleted. """
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# Delete fork on disk
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test", user="foo"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
repo_path = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
5da9ba |
self.assertTrue(os.path.exists(repo_path))
|
|
Pierre-Yves Chibon |
5da9ba |
shutil.rmtree(repo_path)
|
|
Pierre-Yves Chibon |
5da9ba |
self.assertFalse(os.path.exists(repo_path))
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# Delete fork in the DB
|
|
Pierre-Yves Chibon |
5da9ba |
self.session.delete(project)
|
|
Pierre-Yves Chibon |
5da9ba |
self.session.commit()
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# View the pull-request
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/pull-request/1.patch")
|
|
Aurélien Bompard |
626417 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5da9ba |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"--- a/sources\n+++ b/sources\n@@ -1,2 +1,4 @@",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
ff9832 |
def test_accessing_pr_branch_deleted(self):
|
|
Pierre-Yves Chibon |
ff9832 |
""" Test accessing the PR if branch it originates from has been
|
|
Pierre-Yves Chibon |
ff9832 |
deleted. """
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test", user="foo"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Check the branches before
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
ff9832 |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
list(repo.listall_references()), ["refs/heads/feature"]
|
|
Pierre-Yves Chibon |
ff9832 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Delete branch of the fork
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
b130e5 |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
ff9832 |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/fork/foo/test/b/feature/delete", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# Check the branches after
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
ff9832 |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(list(repo.listall_references()), [])
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
ff9832 |
# View the pull-request
|
|
Pierre-Yves Chibon |
73d120 |
output2 = self.app.get("/test/pull-request/1")
|
|
Pierre-Yves Chibon |
ff9832 |
self.assertEqual(output2.status_code, 200)
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
5da9ba |
def test_accessing_pr_patch_branch_deleted(self):
|
|
Pierre-Yves Chibon |
5da9ba |
""" Test accessing the PR's patch if branch it originates from has
|
|
Pierre-Yves Chibon |
5da9ba |
been deleted. """
|
|
Pierre-Yves Chibon |
930073 |
project = pagure.lib.query.get_authorized_project(
|
|
Pierre-Yves Chibon |
73d120 |
self.session, "test", user="foo"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# Check the branches before
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
5da9ba |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
5da9ba |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
list(repo.listall_references()), ["refs/heads/feature"]
|
|
Pierre-Yves Chibon |
5da9ba |
)
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# Delete branch of the fork
|
|
Pierre-Yves Chibon |
73d120 |
user = tests.FakeUser(username="foo")
|
|
Pierre-Yves Chibon |
5da9ba |
with tests.user_set(self.app.application, user):
|
|
Pierre-Yves Chibon |
5da9ba |
output = self.app.post(
|
|
Pierre-Yves Chibon |
73d120 |
"/fork/foo/test/b/feature/delete", follow_redirects=True
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
5da9ba |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# Check the branches after
|
|
Pierre-Yves Chibon |
73d120 |
gitrepo = os.path.join(self.path, "repos", project.path)
|
|
Pierre-Yves Chibon |
5da9ba |
repo = pygit2.Repository(gitrepo)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(list(repo.listall_references()), [])
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
5da9ba |
# View the pull-request
|
|
Pierre-Yves Chibon |
73d120 |
output = self.app.get("/test/pull-request/1.patch")
|
|
Aurélien Bompard |
626417 |
self.assertEqual(output.status_code, 200)
|
|
Pierre-Yves Chibon |
5da9ba |
self.assertIn(
|
|
Pierre-Yves Chibon |
73d120 |
"--- a/sources\n+++ b/sources\n@@ -1,2 +1,4 @@",
|
|
Pierre-Yves Chibon |
73d120 |
output.get_data(as_text=True),
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
5da9ba |
|
|
Pierre-Yves Chibon |
ff9832 |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
ff9832 |
unittest.main(verbosity=2)
|