8000 Fix our build_url patching in our unit test helpers · sigmavirus24/github3.py@ea08bdc · GitHub
[go: up one dir, main page]

Skip to content

Commit ea08bdc

Browse files
committed
Fix our build_url patching in our unit test helpers
1 parent eb7a44d commit ea08bdc

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

tests/unit/helper.py

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,29 @@ def build_url(self, *args, **kwargs):
4444
return github3.session.GitHubSession().build_url(*args, **kwargs)
4545

4646

47-
class UnitHelper(unittest.TestCase):
47+
def enterprise_build_url(self, *args, **kwargs)
48+
"""A function to proxy to the actual GitHubSession#build_url method."""
49+
# We want to assert what is happening with the actual calls to the
50+
# Internet. We can proxy this.
51+
return github3.session.GitHubSession().build_url(
52+
*args,
53+
base_url=self.enterprise_url,
54+
**kwargs
55+
)
56+
4857

58+
class UnitHelper(unittest.TestCase):
4959
"""Base class for unittests."""
5060

5161
# Sub-classes must assign the class to this during definition
5262
described_class = None
5363
# Sub-classes must also assign a dictionary to this during definition
5464
example_data = {}
5565

66+
@staticmethod
67+
def get_build_url_proxy():
68+
return build_url
69+
5670
def create_mocked_session(self):
5771
"""Use mock to auto-spec a GitHubSession and return an instance."""
5872
MockedSession = mock.create_autospec(github3.session.GitHubSession)
@@ -158,7 +172,7 @@ def setUp(self):
158172
# we can assert things about the call that will be attempted to the
159173
# internet
160174
self.old_build_url = self.described_class._build_url
161-
self.described_class._build_url = build_url
175+
self.described_class._build_url = self.get_build_url_proxy()
162176
self.instance = self.create_instance_of_described_class()
163177
self.after_setup()
164178

@@ -239,42 +253,18 @@ def assert_requires_auth(self, func, *args, **kwargs):
239253

240254

241255
class UnitGitHubObjectHelper(UnitHelper):
242-
243256
"""Base class for GitHubObject unit tests."""
257+
# TODO(sigmavirus24): delete me
244258

245-
def setUp(self):
246-
self.session = None
247-
self.instance = self.create_instance_of_described_class()
248-
# Proxy the build_url method to the class so it can build the URL and
249-
# we can assert things about the call that will be attempted to the
250-
# internet
251-
self.described_class._build_url = build_url
252-
self.after_setup()
253-
pass
259+
pass
254260

255261

256262
@pytest.mark.usefixtures('enterprise_url')
257263
class UnitGitHubEnterpriseHelper(UnitHelper):
258264

259-
def build_url(self, *args, **kwargs):
260-
"""A function to proxy to the actual GitHubSession#build_url method."""
261-
# We want to assert what is happening with the actual calls to the
262-
# Internet. We can proxy this.
263-
return github3.session.GitHubSession().build_url(
264-
*args,
265-
base_url=self.enterprise_url,
266-
**kwargs
267-
)
268-
269-
def setUp(self):
270-
self.session = self.create_session_mock()
271-
self.instance = github3.GitHubEnterprise(self.enterprise_url)
272-
self.instance.session = self.session
273-
# Proxy the build_url method to the class so it can build the URL and
274-
# we can assert things about the call that will be attempted to the
275-
# internet
276-
self.instance._build_url = self.build_url
277-
self.after_setup()
265+
@staticmethod
266+
def get_build_url_proxy():
267+
return enterprise_build_url
278268

279269

280270
is_py3 = (3, 0) <= sys.version_info < (4, 0)

0 commit comments

Comments
 (0)
0