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:
parent
a47c606b3e
commit
616a0b9a6c
@ -12,8 +12,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
import uuid
|
||||
|
||||
@ -67,13 +65,15 @@ class GithubRepoFixture(GithubLoginMixin, 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)
|
||||
|
||||
|
@ -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.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)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user