Skip to content

Commit 484edf8

Browse files
author
Frederick Ross
committed
Update docstring and add tests for passing raw strings to Stanza.submit.
Also fixed unit test import in test_job.py.
1 parent 0b03b3e commit 484edf8

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎splunklib/client.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,9 +1688,15 @@ def _entity_path(self, state):
16881688

16891689
class Stanza(Entity):
16901690
"""This class contains a single configuration stanza."""
1691+
16911692
def submit(self, stanza):
16921693
"""Sets the keys in *stanza* this Stanza.
16931694
1695+
*stanza* will usually be a dictionary of key/value pairs, but can also
1696+
by a raw string to send as the POST body of the request (e.g.,
1697+
`"key=some+value&other+key=another+value"`). Sending raw strings should
1698+
be considered deprecated.
1699+
16941700
:param stanza: A dictionary of key/value pairs to set in this stanza.
16951701
:type stanza: ``dict``
16961702
:return: The :class:`Stanza` object this method is called on.

‎tests/test_conf.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ def test_confs(self):
9292
self.assertTrue(key in stanza)
9393
self.assertEqual(value, stanza[key])
9494

95+
key2 = testlib.tmpname()
96+
val2 = testlib.tmpname()
97+
stanza.submit("%s=%s&%s=%s" % (key2, val2, key2, val2))
98+
stanza.refresh()
99+
self.assertTrue(key2 in stanza)
100+
self.assertEqual(val2, stanza[key2])
101+
95102
count = len(conf)
96103
conf.delete(stanza_name)
97104
self.assertFalse(stanza_name in conf)

‎tests/test_job.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import testlib
1818
import logging
1919

20-
import unittest2 as unittest
20+
try:
21+
import unittest2 as unittest
22+
except ImportError:
23+
import unittest
2124

2225
import splunklib.client as client
2326
import splunklib.results as results
@@ -298,8 +301,4 @@ def test_concatenated_stream(self):
298301
self.assertEqual(s.read(), 'mergency broadcast system.')
299302

300303
if __name__ == "__main__":
301-
try:
302-
import unittest2 as unittest
303-
except ImportError:
304-
import unittest
305304
unittest.main()

0 commit comments

Comments
 (0)