From 351d6c249e83e6881db9ad56ce2008c027fba4bf Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Fri, 7 Dec 2018 11:10:21 +0000 Subject: [PATCH] Allow explicit control of repository name If the user overrides the repo_name attributed, skip using the temporary name generation. Change-Id: Ia8c80ed139b5c5987886e2c7e00d63fd1d6aaf0f --- fixtures_git/github.py | 12 +++++++----- tests/unit/test_github.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/fixtures_git/github.py b/fixtures_git/github.py index e699ceb..8e6bd4b 100644 --- a/fixtures_git/github.py +++ b/fixtures_git/github.py @@ -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) diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py index e313899..1e0af7e 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -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) + )