From e255397eb4dabf9c7ce8b38f18f894bd26e3c874 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 28 Apr 2020 15:45:51 -0700 Subject: [PATCH] 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 --- tests/fakegithub.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/fakegithub.py b/tests/fakegithub.py index bbcbb6aa22..558d23471a 100644 --- a/tests/fakegithub.py +++ b/tests/fakegithub.py @@ -555,8 +555,8 @@ class FakeResponse(object): class FakeGithubSession(object): - def __init__(self, data): - self._data = data + def __init__(self, client): + self.client = client self.headers = CaseInsensitiveDict() self._base_url = None self.schema = graphene.Schema(query=FakeGithubQuery) @@ -584,7 +584,7 @@ class FakeGithubSession(object): query = json.get('query') variables = json.get('variables') 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(None, 404) @@ -593,8 +593,7 @@ class FakeGithubSession(object): org, project, request = request.split('/', 2) project_name = '{}/{}'.format(org, project) - client = FakeGithubClient(self._data) - repo = client.repo_from_project(project_name) + repo = self.client.repo_from_project(project_name) return repo.get_url(request, params=params) @@ -618,7 +617,7 @@ class FakeGithubClient(object): def __init__(self, data, inst_id=None): self._data = data self._inst_id = inst_id - self.session = FakeGithubSession(data) + self.session = FakeGithubSession(self) def user(self, login): return FakeUser(login)