@@ -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
59
+
48
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
@@ -158,7 +179,7 @@ def setUp(self):
158
179
# we can assert things about the call that will be attempted to the
159
180
# internet
160
181
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 ()
162
183
self .instance = self .create_instance_of_described_class ()
163
184
self .after_setup ()
164
185
@@ -239,42 +260,17 @@ def assert_requires_auth(self, func, *args, **kwargs):
239
260
240
261
241
262
class UnitGitHubObjectHelper (UnitHelper ):
242
-
243
263
"""Base class for GitHubObject unit tests."""
264
+ # TODO(sigmavirus24): delete me
244
265
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
254
267
255
268
256
269
@pytest .mark .usefixtures ('enterprise_url' )
257
270
class UnitGitHubEnterpriseHelper (UnitHelper ):
258
271
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 )
278
274
279
275
280
276
is_py3 = (3 , 0 ) <= sys .version_info < (4 , 0 )
0 commit comments