|
| 1 | +import io |
| 2 | +import json |
1 | 3 | import sys
|
2 | 4 |
|
| 5 | +from mock import Mock, patch |
| 6 | + |
| 7 | +from splunklib import six |
3 | 8 | from splunklib.client import Service
|
4 | 9 | from splunklib.modularinput import Script, EventWriter, Scheme, Argument, Event
|
5 |
| -import io |
6 | 10 |
|
7 | 11 | from splunklib.modularinput.utils import xml_compare
|
8 | 12 | from tests.modularinput.modularinput_testlib import data_open
|
@@ -184,9 +188,24 @@ def stream_events(self, inputs, ew):
|
184 | 188 | script = NewScript()
|
185 | 189 | input_configuration = data_open("data/conf_with_2_inputs.xml")
|
186 | 190 |
|
187 |
| - ew = EventWriter(sys.stdout, sys.stderr) |
| 191 | + event_writer = EventWriter(sys.stdout, sys.stderr) |
| 192 | + |
| 193 | + patched_telemetry_response = { |
| 194 | + 'status': 201, |
| 195 | + 'reason': 'Created', |
| 196 | + 'body.read.return_value': six.ensure_binary(json.dumps({ |
| 197 | + 'message': 'Data submitted successfully', |
| 198 | + 'metricValueID': '26844DB9-7806-40E0-96C0-1BD554930BA8' |
| 199 | + })), |
| 200 | + 'headers': [ |
| 201 | + ('content-type', 'application/json; charset=UTF-8') |
| 202 | + ] |
| 203 | + } |
| 204 | + |
| 205 | + with patch.object(Service, 'post') as patched_telemetry_post: |
| 206 | + patched_telemetry_post.return_value = Mock(**patched_telemetry_response) |
188 | 207 |
|
189 |
| - return_value = script.run_script([TEST_SCRIPT_PATH], ew, input_configuration) |
| 208 | + return_value = script.run_script([TEST_SCRIPT_PATH], event_writer, input_configuration) |
190 | 209 |
|
191 | 210 | output = capsys.readouterr()
|
192 | 211 | assert output.err == ""
|
|
0 commit comments