-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathtest_scheme.py
More file actions
134 lines (102 loc) · 4.73 KB
/
test_scheme.py
File metadata and controls
134 lines (102 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# -*- coding: utf-8 -*-
# Copyright © 2011-2024 Splunk, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"): you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import xml.etree.ElementTree as ET
from tests.unit.modularinput.modularinput_testlib import (
unittest,
xml_compare,
data_open,
)
from splunklib.modularinput.scheme import Scheme
from splunklib.modularinput.argument import Argument
class SchemeTest(unittest.TestCase):
def test_generate_xml_from_scheme_with_default_values(self):
"""Checks the Scheme generated by creating a Scheme object and setting no fields on it.
This test checks for sane defaults in the class."""
scheme = Scheme("abcd")
constructed = scheme.to_xml()
expected = ET.parse(data_open("data/scheme_with_defaults.xml")).getroot()
self.assertTrue(xml_compare(expected, constructed))
def test_generate_xml_from_scheme(self):
"""Checks that the XML generated by a Scheme object with all its fields set and
some arguments added matches what we expect."""
scheme = Scheme("abcd")
scheme.description = "쎼 and 쎶 and <&> für"
scheme.streaming_mode = Scheme.streaming_mode_simple
scheme.use_external_validation = "false"
scheme.use_single_instance = "true"
arg1 = Argument(name="arg1")
scheme.add_argument(arg1)
arg2 = Argument(
name="arg2",
description="쎼 and 쎶 and <&> für",
validation="is_pos_int('some_name')",
data_type=Argument.data_type_number,
required_on_edit=True,
required_on_create=True,
)
scheme.add_argument(arg2)
constructed = scheme.to_xml()
expected = ET.parse(data_open("data/scheme_without_defaults.xml")).getroot()
self.assertTrue(xml_compare(expected, constructed))
def test_generate_xml_from_scheme_with_arg_title(self):
"""Checks that the XML generated by a Scheme object with all its fields set and
some arguments added matches what we expect. Also sets the title on an argument."""
scheme = Scheme("abcd")
scheme.description = "쎼 and 쎶 and <&> für"
scheme.streaming_mode = Scheme.streaming_mode_simple
scheme.use_external_validation = "false"
scheme.use_single_instance = "true"
arg1 = Argument(name="arg1")
scheme.add_argument(arg1)
arg2 = Argument(
name="arg2",
description="쎼 and 쎶 and <&> für",
validation="is_pos_int('some_name')",
data_type=Argument.data_type_number,
required_on_edit=True,
required_on_create=True,
title="Argument for ``test_scheme``",
)
scheme.add_argument(arg2)
constructed = scheme.to_xml()
expected = ET.parse(
data_open("data/scheme_without_defaults_and_argument_title.xml")
).getroot()
self.assertEqual("Argument for ``test_scheme``", arg2.title)
self.assertTrue(xml_compare(expected, constructed))
def test_generate_xml_from_argument_with_default_values(self):
"""Checks that the XML produced from an Argument class that is initialized but has no additional manipulations
made to it is what we expect. This is mostly a check of the default values."""
argument = Argument("some_name")
root = ET.Element("")
constructed = argument.add_to_document(root)
expected = ET.parse(data_open("data/argument_with_defaults.xml")).getroot()
self.assertTrue(xml_compare(expected, constructed))
def test_generate_xml_from_argument(self):
"""Checks that the XML generated by an Argument class with all its possible values set is what we expect."""
argument = Argument(
name="some_name",
description="쎼 and 쎶 and <&> für",
validation="is_pos_int('some_name')",
data_type=Argument.data_type_boolean,
required_on_edit="true",
required_on_create="true",
)
root = ET.Element("")
constructed = argument.add_to_document(root)
expected = ET.parse(data_open("data/argument_without_defaults.xml")).getroot()
self.assertTrue(xml_compare(expected, constructed))
if __name__ == "__main__":
unittest.main()