@@ -44,14 +44,32 @@ def build_url(self, *args, **kwargs):
44
44
return github3 .session .GitHubSession ().build_url (* args , ** kwargs )
45
45
46
46
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
48
59
60
+
61
+ class UnitHelper (unittest .TestCase ):
49
62
"""Base class for unittests."""
50
63
51
64
# Sub-classes must assign the class to this during definition
52
65
described_class = None
53
66
# Sub-classes must also assign a dictionary to this during definition
54
67
example_data = {}
68
+ enterprise_url = None
69
+
70
+ @staticmethod
71
+ def get_build_url_proxy ():
72
+ return build_url
55
73
56
74
def create_mocked_session (self ):
57
75
"""Use mock to auto-spec a GitHubSession and return an instance."""
@@ -89,7 +107,10 @@ def create_instance_of_described_class(self):
89
107
instance = self .described_class (self .example_data , session )
90
108
91
109
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 )
93
114
instance .session = self .session
94
115
95
116
return instance
@@ -154,13 +175,18 @@ def put_called_with(self, *args, **kwargs):
154
175
def setUp (self ):
155
176
"""Use to set up attributes on self before each test."""
156
177
self .session = self .create_session_mock ()
157
- self .instance = self .create_instance_of_described_class ()
158
178
# Proxy the build_url method to the class so it can build the URL and
159
179
# we can assert things about the call that will be attempted to the
160
180
# internet
161
- self .described_class ._build_url = build_url
181
+ self .old_build_url = self .described_class ._build_url
182
+ self .described_class ._build_url = self .get_build_url_proxy ()
183
+ self .instance = self .create_instance_of_described_class ()
162
184
self .after_setup ()
163
185
186
+ def tearDown (self ):
187
+ """Reset attributes on items under test."""
188
+ self .described_class ._build_url = self .old_build_url
189
+
164
190
def after_setup (self ):
165
191
"""No-op method to avoid people having to override setUp."""
166
192
pass
@@ -234,42 +260,17 @@ def assert_requires_auth(self, func, *args, **kwargs):
234
260
235
261
236
262
class UnitGitHubObjectHelper (UnitHelper ):
237
-
238
263
"""Base class for GitHubObject unit tests."""
264
+ # TODO(sigmavirus24): delete me
239
265
240
- def setUp (self ):
241
- self .session = None
242
- self .instance = self .create_instance_of_described_class ()
243
- # Proxy the build_url method to the class so it can build the URL and
244
- # we can assert things about the call that will be attempted to the
245
- # internet
246
- self .described_class ._build_url = build_url
247
- self .after_setup ()
248
- pass
266
+ pass
249
267
250
268
251
269
@pytest .mark .usefixtures ('enterprise_url' )
252
270
class UnitGitHubEnterpriseHelper (UnitHelper ):
253
271
254
- def build_url (self , * args , ** kwargs ):
255
- """A function to proxy to the actual GitHubSession#build_url method."""
256
- # We want to assert what is happening with the actual calls to the
257
- # Internet. We can proxy this.
258
- return github3 .session .GitHubSession ().build_url (
259
- * args ,
260
- base_url = self .enterprise_url ,
261
- ** kwargs
262
- )
263
-
264
- def setUp (self ):
265
- self .session = self .create_session_mock ()
266
- self .instance = github3 .GitHubEnterprise (self .enterprise_url )
267
- self .instance .session = self .session
268
- # Proxy the build_url method to the class so it can build the URL and
269
- # we can assert things about the call that will be attempted to the
270
- # internet
271
- self .instance ._build_url = self .build_url
272
- self .after_setup ()
272
+ def get_build_url_proxy (self ):
273
+ return enterprise_build_url_builder (self .enterprise_url )
273
274
274
275
275
276
is_py3 = (3 , 0 ) <= sys .version_info < (4 , 0 )
0 commit comments