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 committed by Darragh Bailey (electrofelix)
parent a47c606b3e
commit f62448af84
2 changed files with 14 additions and 18 deletions

View File

@ -28,20 +28,18 @@ except ImportError:
TEST_REPO_DESC = "########## Auto-generated test repository ##########" 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: if parse.urlparse(url).netloc == "github.com":
url = "https://github.com" return github.login(token=token)
else:
if parse.urlparse(url).netloc == "github.com": return github.enterprise_login(token=token, url=url)
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. Fixture to create a new repo in GitHub and remove once finished.
""" """
@ -58,8 +56,7 @@ class GithubRepoFixture(GithubLoginMixin, fixtures.Fixture):
self.repo = None self.repo = None
self.repo_name = None self.repo_name = None
# use GithubLoginMixin self.github = _login(token, url)
self.github = self.login(token, url)
# try an auth'ed request to make sure we have a valid token # try an auth'ed request to make sure we have a valid token
# note this requires the token to have read on user # note this requires the token to have read on user
@ -95,7 +92,7 @@ class GithubRepoFixture(GithubLoginMixin, fixtures.Fixture):
repo.delete() repo.delete()
class GithubForkedRepoFixture(GithubLoginMixin, fixtures.Fixture): class GithubForkedRepoFixture(fixtures.Fixture):
""" """
Fixture to create and delete a fork of the given repo in the Fixture to create and delete a fork of the given repo in the
default GitHub org of the token user default GitHub org of the token user
@ -108,8 +105,7 @@ class GithubForkedRepoFixture(GithubLoginMixin, fixtures.Fixture):
self.repo = None self.repo = None
# use GithubLoginMixin self.github = _login(token, url)
self.github = self.login(token, url)
# try an auth'ed request to make sure we have a valid token # try an auth'ed request to make sure we have a valid token
# note this requires the token to have read on user # 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): class TestGithubRepoFixture(testtools.TestCase):
@mock.patch('fixtures_git.github.GithubRepoFixture.login', @mock.patch('fixtures_git.github._login',
mock.Mock(return_value=mock.Mock())) mock.Mock(return_value=mock.Mock()))
def test_tempname_default(self): def test_tempname_default(self):
@ -37,7 +37,7 @@ class TestGithubRepoFixture(testtools.TestCase):
testtools.matchers.NotEquals('workflow-test-') testtools.matchers.NotEquals('workflow-test-')
) )
@mock.patch('fixtures_git.github.GithubRepoFixture.login', @mock.patch('fixtures_git.github._login',
mock.Mock(return_value=mock.Mock())) mock.Mock(return_value=mock.Mock()))
def test_tempname_custom(self): def test_tempname_custom(self):
@ -54,7 +54,7 @@ class TestGithubRepoFixture(testtools.TestCase):
testtools.matchers.EndsWith(template.split('XXXXXX')[1]) 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())) mock.Mock(return_value=mock.Mock()))
def test_tempname_no_suffix_in_template(self): def test_tempname_no_suffix_in_template(self):