From 1593f2eb47f1b0993a63bb80baa0dc4923d09a4a Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 12 Dec 2018 15:25:53 +0000 Subject: [PATCH] Drop Mixin class in favour of function Change-Id: Id5622edb5d4209e81407786de5a9d7abe2b7b5e2 --- fixtures_git/github.py | 26 +++++++++++--------------- tests/unit/test_github.py | 6 +++--- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/fixtures_git/github.py b/fixtures_git/github.py index f1ddef3..ed3ca17 100644 --- a/fixtures_git/github.py +++ b/fixtures_git/github.py @@ -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 diff --git a/tests/unit/test_github.py b/tests/unit/test_github.py index b2f61e4..7a28369 100644 --- a/tests/unit/test_github.py +++ b/tests/unit/test_github.py @@ -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):