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

Skip to content

Commit f4152cc

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

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

tests/unit/helper.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,32 @@ 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_builder(enterprise_url):
48+
"""Build a URL builder function."""
49+
def enterprise_build_url(self, *args, **kwargs):
50+
"""A function to proxy to the actual GitHubSession#build_url method."""
51+
# We want to assert what is happening with the actual calls to the
52+
# Internet. We can proxy this.
53+
return github3.session.GitHubSession().build_url(
54+
*args,
55+
base_url=enterprise_url,
56+
**kwargs
57+
)
58+
return enterprise_build_url
59+
4860

61+
class UnitHelper(unittest.TestCase):
4962
"""Base class for unittests."""
5063

5164
# Sub-classes must assign the class to this during definition
5265
described_class = None
5366
# Sub-classes must also assign a dictionary to this during definition
5467
example_data = {}
68+
enterprise_url = None
69+
70+
@staticmethod
71+
def get_build_url_proxy():
72+
return build_url
5573

5674
def create_mocked_session(self):
5775
"""Use mock to auto-spec a GitHubSession and return an instance."""
@@ -89,7 +107,10 @@ def create_instance_of_described_class(self):
89107
instance = self.described_class(self.example_data, session)
90108

91109
else:
92-
instance = self.described_class()
110+
if self.enterprise_url is None:
111+
instance = self.described_class()
112+
else:
113+
instance = self.described_class(self.enterprise_url)
93114
instance.session = self.session
94115

95116
return instance
@@ -158,7 +179,7 @@ def setUp(self):
158179
# we can assert things about the call that will be attempted to the
159180
# internet
160181
self.old_build_url = self.described_class._build_url
161-
self.described_class._build_url = build_url
182+
self.described_class._build_url = self.get_build_url_proxy()
162183
self.instance = self.create_instance_of_described_class()
163184
self.after_setup()
164185

@@ -239,42 +260,17 @@ def assert_requires_auth(self, func, *args, **kwargs):
239260

240261

241262
class UnitGitHubObjectHelper(UnitHelper):
242-
243263
"""Base class for GitHubObject unit tests."""
264+
# TODO(sigmavirus24): delete me
244265

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
266+
pass
254267

255268

256269
@pytest.mark.usefixtures('enterprise_url')
257270
class UnitGitHubEnterpriseHelper(UnitHelper):
258271

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()
272+
def get_build_url_proxy(self):
273+
return enterprise_build_url_builder(self.enterprise_url)
278274

279275

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

0 commit comments

Comments
 (0)
0