Skip to content

Commit 0545eac

Browse files
author
Frederick Ross
committed
Made Stanza.submit accept only dicts, not strings.
Fixed conf.py the example to submit a dict instead of a string. Added armor to the test in test_examples that tests conf.py. Removed the unit test that was testing Stanza.submit with a string as an argument.
1 parent a77701d commit 0545eac

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

examples/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def create(self, opts):
4343
kvpair = argv[2].split("=")
4444
if len(kvpair) != 2:
4545
error("Creating a k/v pair requires key and value", 2)
46+
else:
47+
key, value = kvpair
4648

4749
if not cpres and not spres:
4850
error("Conf name and stanza name is required for create", 2)
@@ -58,7 +60,7 @@ def create(self, opts):
5860

5961
# create key/value pair under existing stanza
6062
stanza = conf[stan]
61-
stanza.submit(argv[2])
63+
stanza.submit({key: value})
6264

6365

6466
def delete(self, opts):

splunklib/client.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,22 +1668,12 @@ class Stanza(Entity):
16681668
def submit(self, stanza):
16691669
"""Sets the keys in *stanza* on this Stanza.
16701670
1671-
*stanza* will usually be a dictionary of key/value pairs, but can also
1672-
by a raw string to send as the POST body of the request (e.g.,
1673-
`"key=some+value&other+key=another+value"`). Sending raw strings should
1674-
be considered deprecated.
1675-
16761671
:param stanza: A dictionary of key/value pairs to set in this stanza.
16771672
:type stanza: ``dict``
16781673
:return: The :class:`Stanza` object this method is called on.
16791674
"""
1680-
if isinstance(stanza, str):
1681-
message = { 'method': "POST", 'body': stanza }
1682-
self.service.request(self.path, **message)
1683-
elif isinstance(stanza, dict):
1684-
body = _encode(**stanza)
1685-
self.service.post(self.path, body=body)
1686-
1675+
body = _encode(**stanza)
1676+
self.service.post(self.path, body=body)
16871677
return self
16881678

16891679
def __len__(self):

tests/test_conf.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ 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-
10295
count = len(conf)
10396
conf.delete(stanza_name)
10497
self.assertFalse(stanza_name in conf)

tests/test_examples.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,26 @@ def test_binding1(self):
8080
self.assertEquals(result, 0)
8181

8282
def test_conf(self):
83-
self.check_commands(
84-
"conf.py --help",
85-
"conf.py",
86-
"conf.py viewstates",
87-
'conf.py --app=search --owner=admin viewstates',
88-
"conf.py create server SDK-STANZA",
89-
"conf.py create server SDK-STANZA testkey=testvalue",
90-
"conf.py delete server SDK-STANZA")
83+
try:
84+
conf = self.service.confs['server']
85+
if 'SDK-STANZA' in conf:
86+
conf.delete("SDK-STANZA")
87+
except Exception, e:
88+
pass
89+
90+
try:
91+
self.check_commands(
92+
"conf.py --help",
93+
"conf.py",
94+
"conf.py viewstates",
95+
'conf.py --app=search --owner=admin viewstates',
96+
"conf.py create server SDK-STANZA",
97+
"conf.py create server SDK-STANZA testkey=testvalue",
98+
"conf.py delete server SDK-STANZA")
99+
finally:
100+
conf = self.service.confs['server']
101+
if 'SDK-STANZA' in conf:
102+
conf.delete('SDK-STANZA')
91103

92104
def test_event_types(self):
93105
self.check_commands(

0 commit comments

Comments
 (0)