Skip to content

Commit 11543fe

Browse files
author
Shakeel Mohamed
committed
Add test for invalid search as json
1 parent e4aaca8 commit 11543fe

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/test_job.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
import splunklib.client as client
2626
import splunklib.results as results
2727

28-
from splunklib.binding import _log_duration
28+
from splunklib.binding import _log_duration, HTTPError
29+
30+
from xml.etree.ElementTree import ParseError
2931

3032

3133
class TestUtilities(testlib.SDKTestCase):
@@ -343,6 +345,20 @@ def test_touch(self):
343345
self.fail("Didn't wait long enough for TTL to change and make touch meaningful.")
344346
self.assertGreater(int(self.job['ttl']), old_ttl)
345347

348+
def test_search_invalid_query_as_json(self):
349+
args = {
350+
'output_mode': 'json',
351+
'exec_mode': 'normal'
352+
}
353+
try:
354+
self.service.jobs.create('invalid query', **args)
355+
except ParseError as pe:
356+
self.fail("Something went wrong with parsing the REST API response. %s" % pe.message)
357+
except HTTPError as he:
358+
self.assertEqual(he.status, 400)
359+
except Exception as e:
360+
self.fail("Got some unexpected error. %s" % e.message)
361+
346362

347363
class TestResultsReader(unittest.TestCase):
348364
def test_results_reader(self):

0 commit comments

Comments
 (0)