Skip to content

Commit b8ad580

Browse files
author
David Noble
committed
Fixed final test failures :)
We've adapted to the fact that unittest2.TestCase does not implement assertIsNotNone. We've left it to another day to resolve this issue: unittest2.TestCase does not implement skipTest. We've left a to-do in code. A bug is forthcoming. This fix is verified on all three platforms, Python 2.6/2.7, and Splunk 6.2/6.3. Next up: Push to develop and publish to github.
1 parent 43eeb43 commit b8ad580

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tests/test_binding.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ def test_logout(self):
496496
response = self.context.get("/services")
497497
self.assertEqual(response.status, 200)
498498

499+
499500
class TestCookieAuthentication(unittest.TestCase):
500501
def setUp(self):
501502
self.opts = testlib.parse([], {}, ".splunkrc")
@@ -504,10 +505,17 @@ def setUp(self):
504505
# Skip these tests if running below Splunk 6.2, cookie-auth didn't exist before
505506
import splunklib.client as client
506507
service = client.Service(**self.opts.kwargs)
508+
# TODO: Workaround the fact that skipTest is not defined by unittest2.TestCase
507509
splver = service.splunk_version
508510
if splver[:2] < (6, 2):
509511
self.skipTest("Skipping cookie-auth tests, running in %d.%d.%d, this feature was added in 6.2+" % splver)
510512

513+
if getattr(unittest.TestCase, 'assertIsNotNone', None) is None:
514+
515+
def assertIsNotNone(self, obj, msg=None):
516+
if obj is None:
517+
raise self.failureException, (msg or '%r is not None' % obj)
518+
511519
def test_cookie_in_auth_headers(self):
512520
self.assertIsNotNone(self.context._auth_headers)
513521
self.assertNotEqual(self.context._auth_headers, [])

tests/test_service.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,24 @@ def _create_unauthenticated_service(self):
171171
'scheme': self.opts.kwargs['scheme']
172172
})
173173

174+
174175
class TestCookieAuthentication(unittest.TestCase):
175176
def setUp(self):
176177
self.opts = testlib.parse([], {}, ".splunkrc")
177178
self.service = client.Service(**self.opts.kwargs)
178179

179180
# Skip these tests if running below Splunk 6.2, cookie-auth didn't exist before
180181
splver = self.service.splunk_version
182+
# TODO: Workaround the fact that skipTest is not defined by unittest2.TestCase
181183
if splver[:2] < (6, 2):
182184
self.skipTest("Skipping cookie-auth tests, running in %d.%d.%d, this feature was added in 6.2+" % splver)
183185

186+
if getattr(unittest.TestCase, 'assertIsNotNone', None) is None:
187+
188+
def assertIsNotNone(self, obj, msg=None):
189+
if obj is None:
190+
raise self.failureException, (msg or '%r is not None' % obj)
191+
184192
def test_login_and_store_cookie(self):
185193
self.assertIsNotNone(self.service.get_cookies())
186194
self.assertEquals(len(self.service.get_cookies()), 0)
@@ -263,7 +271,7 @@ def test_login_with_multiple_cookies(self):
263271
service2.apps.get()
264272
self.fail()
265273
except AuthenticationError as ae:
266-
self.assertEqual(ae.message, "Request failed: Session is not logged in.")
274+
self.assertEqual(str(ae), "Request failed: Session is not logged in.")
267275

268276
# Add on valid cookies, and try to use all of them
269277
service2.get_cookies().update(self.service.get_cookies())

0 commit comments

Comments
 (0)