Allow explicit control of repository name

If the user overrides the repo_name attributed, skip using the temporary
name generation.

Change-Id: Ia8c80ed139b5c5987886e2c7e00d63fd1d6aaf0f
This commit is contained in:
Darragh Bailey 2018-12-07 11:10:21 +00:00
parent 1593f2eb47
commit 701e2a1c36
2 changed files with 21 additions and 6 deletions

View File

@ -62,13 +62,15 @@ class GithubRepoFixture(fixtures.Fixture):
def _setUp(self):
# handle template_name missing 'XXXXX' result in it containing
# a single element so set suffix to '' in that case.
template_parts = iter(self.name_template.split('XXXXXX'))
prefix = next(template_parts)
suffix = next(template_parts, '')
# allow user to provide an exact name to use
if self.repo_name is None:
# handle template_name missing 'XXXXX' result in it containing
# a single element so set suffix to '' in that case.
template_parts = iter(self.name_template.split('XXXXXX'))
prefix = next(template_parts)
suffix = next(template_parts, '')
self.repo_name = ''.join([prefix, str(uuid.uuid4())[:8], suffix])
self.repo_name = ''.join([prefix, str(uuid.uuid4())[:8], suffix])
self.addCleanup(self._delete_repo)

View File

@ -75,3 +75,16 @@ class TestGithubRepoFixture(testtools.TestCase):
gh_repo.repo_name.split('-')[-1],
testtools.matchers.MatchesRegex('[a-f0-9]{8}')
)
@mock.patch('fixtures_git.github._login',
mock.Mock(return_value=mock.Mock()))
def test_tempname_exact_string(self):
name = 'my-custom-tmp'
gh_repo = gh_fixture.GithubRepoFixture('owner', 'token')
gh_repo.repo_name = name
gh_repo.setUp()
self.assertThat(
gh_repo.repo_name,
testtools.matchers.Equals(name)
)