Drop Mixin class in favour of function

Change-Id: Id5622edb5d4209e81407786de5a9d7abe2b7b5e2
This commit is contained in:
Darragh Bailey 2018-12-12 15:25:53 +00:00
parent bd0d908b96
commit 1593f2eb47
2 changed files with 14 additions and 18 deletions

View File

@ -26,20 +26,18 @@ except ImportError:
TEST_REPO_DESC = "########## Auto-generated test repository ##########"
class GithubLoginMixin(object):
def _login(self, token, url=None):
def login(self, token, url=None):
if url is None:
url = "https://github.com"
if url is None:
url = "https://github.com"
if parse.urlparse(url).netloc == "github.com":
return github.login(token=token)
else:
return github.enterprise_login(token=token, url=url)
if parse.urlparse(url).netloc == "github.com":
return github.login(token=token)
else:
return github.enterprise_login(token=token, url=url)
class GithubRepoFixture(GithubLoginMixin, fixtures.Fixture):
class GithubRepoFixture(fixtures.Fixture):
"""
Fixture to create a new repo in GitHub and remove once finished.
"""
@ -56,8 +54,7 @@ class GithubRepoFixture(GithubLoginMixin, fixtures.Fixture):
self.repo = None
self.repo_name = None
# use GithubLoginMixin
self.github = self.login(token, url)
self.github = _login(token, url)
# try an auth'ed request to make sure we have a valid token
# note this requires the token to have read on user
@ -93,7 +90,7 @@ class GithubRepoFixture(GithubLoginMixin, fixtures.Fixture):
repo.delete()
class GithubForkedRepoFixture(GithubLoginMixin, fixtures.Fixture):
class GithubForkedRepoFixture(fixtures.Fixture):
"""
Fixture to create and delete a fork of the given repo in the
default GitHub org of the token user
@ -106,8 +103,7 @@ class GithubForkedRepoFixture(GithubLoginMixin, fixtures.Fixture):
self.repo = None
# use GithubLoginMixin
self.github = self.login(token, url)
self.github = _login(token, url)
# try an auth'ed request to make sure we have a valid token
# note this requires the token to have read on user

View File

@ -22,7 +22,7 @@ from fixtures_git import github as gh_fixture
class TestGithubRepoFixture(testtools.TestCase):
@mock.patch('fixtures_git.github.GithubRepoFixture.login',
@mock.patch('fixtures_git.github._login',
mock.Mock(return_value=mock.Mock()))
def test_tempname_default(self):
@ -37,7 +37,7 @@ class TestGithubRepoFixture(testtools.TestCase):
testtools.matchers.NotEquals('workflow-test-')
)
@mock.patch('fixtures_git.github.GithubRepoFixture.login',
@mock.patch('fixtures_git.github._login',
mock.Mock(return_value=mock.Mock()))
def test_tempname_custom(self):
@ -54,7 +54,7 @@ class TestGithubRepoFixture(testtools.TestCase):
testtools.matchers.EndsWith(template.split('XXXXXX')[1])
)
@mock.patch('fixtures_git.github.GithubRepoFixture.login',
@mock.patch('fixtures_git.github._login',
mock.Mock(return_value=mock.Mock()))
def test_tempname_no_suffix_in_template(self):