Url parameter is only valid for enterprise login method

Call the appropriate login method using a simple mixin object.

Change-Id: I16029a64c21d811b2af56d55ce497a62fe9e9a1a
This commit is contained in:
Darragh Bailey 2018-12-07 11:03:53 +00:00
parent a768b72ba1
commit 45287200c5
1 changed files with 23 additions and 17 deletions

View File

@ -27,29 +27,38 @@ except ImportError:
TEST_REPO_DESC = "########## Auto-generated test repository ##########" TEST_REPO_DESC = "########## Auto-generated test repository ##########"
class GithubRepoFixture(fixtures.Fixture): class GithubLoginMixin(object):
def login(self, token, url=None):
if url is None:
url = "https://github.com"
if parse.urlparse(url).netloc == "github.com":
self.github = github.login(token=token)
else:
self.github = github.enterprise_login(token=token, url=url)
class GithubRepoFixture(GithubLoginMixin, 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.
""" """
default_repo_name_template = 'workflow-test-XXXXXX' default_repo_name_template = 'workflow-test-XXXXXX'
def __init__(self, owner, token, url="https://github.com", def __init__(self, owner, token, url=None, name_template=None):
name_template=None):
super(GithubRepoFixture, self).__init__() super(GithubRepoFixture, self).__init__()
self.owner = owner self.owner = owner
self.token = token
self.name_template = name_template or self.default_repo_name_template self.name_template = name_template or self.default_repo_name_template
self.repo = None self.repo = None
self.repo_name = None self.repo_name = None
if parse.urlparse(url).netloc == "github.com":
github_login = github.login # use GithubLoginMixin
else: self.login(token, url)
github_login = github.enterprise_login
self.github = github_login(token=token, url=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
@ -85,24 +94,21 @@ class GithubRepoFixture(fixtures.Fixture):
repo.delete() repo.delete()
class GithubForkedRepoFixture(fixtures.Fixture): class GithubForkedRepoFixture(GithubLoginMixin, 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
""" """
def __init__(self, src_repo, token, url="https://github.com"): def __init__(self, src_repo, token, url=None):
super(GithubForkedRepoFixture, self).__init__() super(GithubForkedRepoFixture, self).__init__()
self.src_repo = src_repo self.src_repo = src_repo
self.token = token
self.repo = None self.repo = None
if parse.urlparse(url).netloc == "github.com":
github_login = github.login # use GithubLoginMixin
else: self.login(token, url)
github_login = github.enterprise_login
self.github = github_login(token=token, url=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