Skip to content

Commit 76eee05

Browse files
author
Shakeel Mohamed
committed
Fix modinput but w/ argument titles not being written
1 parent f0f2b0d commit 76eee05

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

splunklib/modularinput/argument.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def add_to_document(self, parent):
8080
arg = ET.SubElement(parent, "arg")
8181
arg.set("name", self.name)
8282

83+
if self.title is not None:
84+
ET.SubElement(arg, "title").text = self.title
85+
8386
if self.description is not None:
8487
ET.SubElement(arg, "description").text = self.description
8588

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<scheme>
3+
<title>abcd</title>
4+
<description>쎼 and 쎶 and &lt;&amp;&gt; für</description>
5+
<use_external_validation>false</use_external_validation>
6+
<use_single_instance>true</use_single_instance>
7+
<streaming_mode>simple</streaming_mode>
8+
<endpoint>
9+
<args>
10+
<arg name="arg1">
11+
<data_type>string</data_type>
12+
<required_on_edit>false</required_on_edit>
13+
<required_on_create>false</required_on_create>
14+
</arg>
15+
<arg name="arg2">
16+
<title>Argument for ``test_scheme``</title>
17+
<description>쎼 and 쎶 and &lt;&amp;&gt; für</description>
18+
<validation>is_pos_int('some_name')</validation>
19+
<data_type>number</data_type>
20+
<required_on_edit>true</required_on_edit>
21+
<required_on_create>true</required_on_create>
22+
</arg>
23+
</args>
24+
</endpoint>
25+
</scheme>

tests/modularinput/test_scheme.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ def test_generate_xml_from_scheme(self):
4747
arg1 = Argument(name="arg1")
4848
scheme.add_argument(arg1)
4949

50+
arg2 = Argument(
51+
name="arg2",
52+
description=u"쎼 and 쎶 and <&> für",
53+
validation="is_pos_int('some_name')",
54+
data_type=Argument.data_type_number,
55+
required_on_edit=True,
56+
required_on_create=True
57+
)
58+
scheme.add_argument(arg2)
59+
60+
constructed = scheme.to_xml()
61+
62+
expected = ET.parse(data_open("data/scheme_without_defaults.xml")).getroot()
63+
64+
self.assertTrue(xml_compare(expected, constructed))
65+
66+
def test_generate_xml_from_scheme_with_arg_title(self):
67+
"""Checks that the XML generated by a Scheme object with all its fields set and
68+
some arguments added matches what we expect. Also sets the title on an argument."""
69+
70+
scheme = Scheme("abcd")
71+
scheme.description = u"쎼 and 쎶 and <&> für"
72+
scheme.streaming_mode = Scheme.streaming_mode_simple
73+
scheme.use_external_validation = "false"
74+
scheme.use_single_instance = "true"
75+
76+
arg1 = Argument(name="arg1")
77+
scheme.add_argument(arg1)
78+
5079
arg2 = Argument(
5180
name="arg2",
5281
description=u"쎼 and 쎶 and <&> für",
@@ -60,7 +89,7 @@ def test_generate_xml_from_scheme(self):
6089

6190
constructed = scheme.to_xml()
6291

63-
expected = ET.parse(data_open("data/scheme_without_defaults.xml")).getroot()
92+
expected = ET.parse(data_open("data/scheme_without_defaults_and_argument_title.xml")).getroot()
6493
self.assertEqual("Argument for ``test_scheme``", arg2.title)
6594

6695
self.assertTrue(xml_compare(expected, constructed))

0 commit comments

Comments
 (0)