Simplify FakeGithubClient and FakeGithubSession

These two fakes are related to each other. Before this change
FakeGithubClient would create a FakeGithubSession and FakeGithubSession
would create FakeGithubClients. THis recursion is confusing and
unnecessary.

Under normal operation the FakeGithubClient exists first so we pass it
into its FakeGithubSessions and the fake session is able to use this
client object rather than recursively creating a new client.

Change-Id: I9ff52061d62e844ca3f2185ea752ca39962b2a9f
This commit is contained in:
Clark Boylan 2020-04-28 15:45:51 -07:00
parent 6ef4f078aa
commit e255397eb4
1 changed files with 5 additions and 6 deletions

View File

@ -555,8 +555,8 @@ class FakeResponse(object):
class FakeGithubSession(object): class FakeGithubSession(object):
def __init__(self, data): def __init__(self, client):
self._data = data self.client = client
self.headers = CaseInsensitiveDict() self.headers = CaseInsensitiveDict()
self._base_url = None self._base_url = None
self.schema = graphene.Schema(query=FakeGithubQuery) self.schema = graphene.Schema(query=FakeGithubQuery)
@ -584,7 +584,7 @@ class FakeGithubSession(object):
query = json.get('query') query = json.get('query')
variables = json.get('variables') variables = json.get('variables')
result = self.schema.execute( result = self.schema.execute(
query, variables=variables, context=self._data) query, variables=variables, context=self.client._data)
return FakeResponse({'data': result.data}, 200) return FakeResponse({'data': result.data}, 200)
return FakeResponse(None, 404) return FakeResponse(None, 404)
@ -593,8 +593,7 @@ class FakeGithubSession(object):
org, project, request = request.split('/', 2) org, project, request = request.split('/', 2)
project_name = '{}/{}'.format(org, project) project_name = '{}/{}'.format(org, project)
client = FakeGithubClient(self._data) repo = self.client.repo_from_project(project_name)
repo = client.repo_from_project(project_name)
return repo.get_url(request, params=params) return repo.get_url(request, params=params)
@ -618,7 +617,7 @@ class FakeGithubClient(object):
def __init__(self, data, inst_id=None): def __init__(self, data, inst_id=None):
self._data = data self._data = data
self._inst_id = inst_id self._inst_id = inst_id
self.session = FakeGithubSession(data) self.session = FakeGithubSession(self)
def user(self, login): def user(self, login):
return FakeUser(login) return FakeUser(login)