Improve test case test_unprotected_branches

We are missing facilities in the github fake to define the protected
branches of a repository. Add that and use it to improve the
test_unprotected_branches test case. This now additionally protects a
branch and triggers a reload to check if the branch is now loaded.

Change-Id: I183d4fbe2eddeb1c72fd696d797a75ae93293224
This commit is contained in:
Tobias Henkel 2018-06-19 11:14:45 +02:00
parent d1c65b28bf
commit 6c0b3a2f21
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
3 changed files with 26 additions and 3 deletions

View File

@ -27,8 +27,9 @@ class FakeUser(object):
class FakeBranch(object):
def __init__(self, branch='master'):
def __init__(self, branch='master', protected=False):
self.name = branch
self.protected = protected
class FakeStatus(object):
@ -78,9 +79,15 @@ class FakeRepository(object):
def branches(self, protected=False):
if protected:
# simulate there is no protected branch
return []
return [b for b in self._branches if b.protected]
return self._branches
def _set_branch_protection(self, branch_name, protected):
for branch in self._branches:
if branch.name == branch_name:
branch.protected = protected
return
def _build_url(self, *args, **kwargs):
path_args = ['repos', self.name]
path_args.extend(args)

View File

@ -1 +1,2 @@
This zuul.yaml is intentionally broken and should not be loaded on startup.
- job:
name: unused-job

View File

@ -829,6 +829,21 @@ class TestGithubUnprotectedBranches(ZuulTestCase):
# project2 should have no parsed branch
self.assertEqual(0, len(tpc2.parsed_branch_config.keys()))
# now enable branch protection and trigger reload
github = self.fake_github.getGithubClient()
repo = github.repo_from_project('org/project2')
repo._set_branch_protection('master', True)
self.sched.reconfigure(self.config)
self.waitUntilSettled()
tenant = self.sched.abide.tenants.get('tenant-one')
tpc1 = tenant.project_configs[project1.canonical_name]
tpc2 = tenant.project_configs[project2.canonical_name]
# project1 and project2 should have parsed master now
self.assertIn('master', tpc1.parsed_branch_config.keys())
self.assertIn('master', tpc2.parsed_branch_config.keys())
class TestGithubWebhook(ZuulTestCase):
config_file = 'zuul-github-driver.conf'