Fix github branch protection while already unprotected

It was causing the branch to be protected, tests were failing

Change-Id: Idb7b3957159684787fe272181eee92af1abe0da1
This commit is contained in:
Guillaume Chauvel 2020-07-09 18:38:41 +02:00
parent 3cae84145a
commit 39425550ff
2 changed files with 6 additions and 2 deletions

View File

@ -220,8 +220,9 @@ class FakeRepository(object):
def _set_branch_protection(self, branch_name, protected=True,
contexts=None):
if not protected and branch_name in self._branch_protection_rules:
del self._branch_protection_rules[branch_name]
if not protected:
if branch_name in self._branch_protection_rules:
del self._branch_protection_rules[branch_name]
return
rule = self._branch_protection_rules[branch_name]

View File

@ -1011,6 +1011,7 @@ class TestGithubDriver(ZuulTestCase):
github = self.fake_github.getGithubClient()
repo = github.repo_from_project(project)
repo._create_branch(branch)
repo._set_branch_protection(branch, False)
self.fake_github.emitEvent(
self.fake_github.getPushEvent(
@ -1113,6 +1114,7 @@ class TestGithubDriver(ZuulTestCase):
github = self.fake_github.getGithubClient()
repo = github.repo_from_project(project)
repo._create_branch(branch)
repo._set_branch_protection(branch, False)
A = self.fake_github.openFakePullRequest(project, branch, 'A')
old_sha = A.head_sha
@ -1569,6 +1571,7 @@ class TestGithubUnprotectedBranches(ZuulTestCase):
github = self.fake_github.getGithubClient()
repo = github.repo_from_project(project)
repo._create_branch(branch)
repo._set_branch_protection(branch, False)
self.fake_github.emitEvent(
self.fake_github.getPushEvent(