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 15eb36a98c
commit 351d6c249e
2 changed files with 20 additions and 5 deletions

View File

@ -66,11 +66,13 @@ class GithubRepoFixture(GithubLoginMixin, fixtures.Fixture):
def _setUp(self):
template_parts = iter(self.name_template.split('XXXXXX'))
prefix = next(template_parts)
suffix = next(template_parts, '')
tfile = tempfile.NamedTemporaryFile(suffix=suffix, prefix=prefix)
self.repo_name = os.path.basename(tfile.name)
# allow user to provide an exact name to use
if self.repo_name is None:
template_parts = iter(self.name_template.split('XXXXXX'))
prefix = next(template_parts)
suffix = next(template_parts, '')
tfile = tempfile.NamedTemporaryFile(suffix=suffix, prefix=prefix)
self.repo_name = os.path.basename(tfile.name)
self.addCleanup(self._delete_repo)

View File

@ -71,3 +71,16 @@ class TestGithubRepoFixture(testtools.TestCase):
testtools.matchers.Not(
testtools.matchers.Equals(template.split('XXXXXX')[-1]))
)
@mock.patch('fixtures_git.github.GithubRepoFixture.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)
)