Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ __stdout__
docs/_build
build/
proxypid
proxy.log
MANIFEST
coverage_report
test.log
tests/searchcommands_data/log/
tests/searchcommands_data/output/
Test Results*.html
tests/searchcommands/data/app/app.log
*.log
splunk_sdk.egg-info/
dist/
tests/searchcommands/apps/app_with_logging_configuration/*.log
*.observed
venv/
.venv/
.tox
test-reports/
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ services:
timeout: 5s
retries: 20
volumes:
- "./tests/searchcommands/test_apps/eventing_app:/opt/splunk/etc/apps/eventing_app"
- "./tests/searchcommands/test_apps/generating_app:/opt/splunk/etc/apps/generating_app"
- "./tests/searchcommands/test_apps/reporting_app:/opt/splunk/etc/apps/reporting_app"
- "./tests/searchcommands/test_apps/streaming_app:/opt/splunk/etc/apps/streaming_app"
- "./tests/system/test_apps/eventing_app:/opt/splunk/etc/apps/eventing_app"
- "./tests/system/test_apps/generating_app:/opt/splunk/etc/apps/generating_app"
- "./tests/system/test_apps/reporting_app:/opt/splunk/etc/apps/reporting_app"
- "./tests/system/test_apps/streaming_app:/opt/splunk/etc/apps/streaming_app"
- "./splunklib:/opt/splunk/etc/apps/eventing_app/lib/splunklib"
- "./splunklib:/opt/splunk/etc/apps/generating_app/lib/splunklib"
- "./splunklib:/opt/splunk/etc/apps/reporting_app/lib/splunklib"
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions tests/test_app.py → tests/integration/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.


import logging
from tests import testlib
from splunklib import client
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions tests/test_job.py → tests/integration/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# under the License.

from io import BytesIO
from pathlib import Path
from time import sleep

import io
Expand Down Expand Up @@ -442,7 +443,9 @@ def test_results_reader(self):
# Run jobs.export("search index=_internal | stats count",
# earliest_time="rt", latest_time="rt") and you get a
# streaming sequence of XML fragments containing results.
with io.open("data/results.xml", mode="br") as input:
test_dir = Path(__file__).parent
data_file = test_dir / "data" / "results.xml"
with io.open(str(data_file), mode="br") as input:
reader = results.ResultsReader(input)
self.assertFalse(reader.is_preview)
N_results = 0
Expand All @@ -464,7 +467,9 @@ def test_results_reader_with_streaming_results(self):
# Run jobs.export("search index=_internal | stats count",
# earliest_time="rt", latest_time="rt") and you get a
# streaming sequence of XML fragments containing results.
with io.open("data/streaming_results.xml", "br") as input:
test_dir = Path(__file__).parent
data_file = test_dir / "data" / "streaming_results.xml"
with io.open(str(data_file), "br") as input:
reader = results.ResultsReader(input)
N_results = 0
N_messages = 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion tests/test_logger.py → tests/integration/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from tests import testlib

from splunklib import client

LEVELS = ["INFO", "WARN", "ERROR", "DEBUG", "CRIT"]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class Tests(testlib.SDKTestCase):
def setUp(self):
# TODO: why not use super.setUp() ?
self.service = client.connect(**self.opts.kwargs)
self.storage_passwords = self.service.storage_passwords

Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions tests/test_all.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import pytest

from tests.modularinput.modularinput_testlib import xml_compare, data_open
from tests.unit.modularinput.modularinput_testlib import xml_compare, data_open
from splunklib.modularinput.event import Event, ET
from splunklib.modularinput.event_writer import EventWriter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from tests.modularinput.modularinput_testlib import unittest, data_open
from tests.unit.modularinput.modularinput_testlib import unittest, data_open
from splunklib.modularinput.input_definition import InputDefinition


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
# under the License.

import xml.etree.ElementTree as ET
from tests.modularinput.modularinput_testlib import unittest, xml_compare, data_open
from tests.unit.modularinput.modularinput_testlib import (
unittest,
xml_compare,
data_open,
)
from splunklib.modularinput.scheme import Scheme
from splunklib.modularinput.argument import Argument

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from splunklib.modularinput import Script, EventWriter, Scheme, Argument, Event

from splunklib.modularinput.utils import xml_compare
from tests.modularinput.modularinput_testlib import data_open
from tests.unit.modularinput.modularinput_testlib import data_open


TEST_SCRIPT_PATH = "__IGNORED_SCRIPT_PATH__"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# under the License.


from tests.modularinput.modularinput_testlib import unittest, data_open
from tests.unit.modularinput.modularinput_testlib import unittest, data_open
from splunklib.modularinput.validation_definition import ValidationDefinition


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from splunklib.searchcommands.decorators import Configuration
from splunklib.searchcommands.search_command import SearchCommand

from tests.searchcommands import rebase_environment, package_directory
from tests.unit.searchcommands import rebase_environment, package_directory


# portable log level names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from splunklib.searchcommands.internals import json_encode_string
from splunklib.searchcommands.search_command import SearchCommand

from tests.searchcommands import rebase_environment
from tests.unit.searchcommands import rebase_environment


@Configuration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,21 @@
from json.encoder import encode_basestring as encode_string
from unittest import main, TestCase

import csv
import codecs
import os
import re
import logging

from io import TextIOWrapper
from unittest.mock import MagicMock, patch

import pytest

import splunklib
from splunklib.searchcommands import Configuration, StreamingCommand
from splunklib.searchcommands.decorators import ConfigurationSetting, Option
from splunklib.searchcommands.internals import ObjectView
from splunklib.searchcommands.search_command import SearchCommand
from splunklib.client import Service
from splunklib.utils import ensure_binary

from io import StringIO, BytesIO
from io import BytesIO


def build_command_input(getinfo_metadata, execute_metadata, execute_body):
Expand Down
64 changes: 42 additions & 22 deletions tests/test_data.py → tests/unit/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from os import path
import xml.etree.ElementTree as et

from tests import testlib
import unittest

from splunklib import data


class DataTestCase(testlib.SDKTestCase):
class DataTestCase(unittest.TestCase):
def test_elems(self):
result = data.load("")
self.assertTrue(result is None)
Expand Down Expand Up @@ -143,28 +143,35 @@ def test_invalid(self):
self.assertRaises(KeyError, data.load, "<dict><key>a</key></dict>")

def test_dict(self):
result = data.load("""
result = data.load(
"""
<dict></dict>
""")
"""
)
self.assertEqual(result, {})

result = data.load("""
result = data.load(
"""
<dict>
<key name='n1'>v1</key>
<key name='n2'>v2</key>
</dict>""")
</dict>"""
)
self.assertEqual(result, {"n1": "v1", "n2": "v2"})

result = data.load("""
result = data.load(
"""
<content>
<dict>
<key name='n1'>v1</key>
<key name='n2'>v2</key>
</dict>
</content>""")
</content>"""
)
self.assertEqual(result, {"content": {"n1": "v1", "n2": "v2"}})

result = data.load("""
result = data.load(
"""
<content>
<dict>
<key name='n1'>
Expand All @@ -178,12 +185,14 @@ def test_dict(self):
</dict>
</key>
</dict>
</content>""")
</content>"""
)
self.assertEqual(
result, {"content": {"n1": {"n1n1": "n1v1"}, "n2": {"n2n1": "n2v1"}}}
)

result = data.load("""
result = data.load(
"""
<content>
<dict>
<key name='n1'>
Expand All @@ -192,28 +201,34 @@ def test_dict(self):
</list>
</key>
</dict>
</content>""")
</content>"""
)
self.assertEqual(result, {"content": {"n1": ["1", "2", "3", "4"]}})

def test_list(self):
result = data.load("""<list></list>""")
self.assertEqual(result, [])

result = data.load("""
result = data.load(
"""
<list>
<item>1</item><item>2</item><item>3</item><item>4</item>
</list>""")
</list>"""
)
self.assertEqual(result, ["1", "2", "3", "4"])

result = data.load("""
result = data.load(
"""
<content>
<list>
<item>1</item><item>2</item><item>3</item><item>4</item>
</list>
</content>""")
</content>"""
)
self.assertEqual(result, {"content": ["1", "2", "3", "4"]})

result = data.load("""
result = data.load(
"""
<content>
<list>
<item>
Expand All @@ -223,30 +238,35 @@ def test_list(self):
<list><item>3</item><item>4</item></list>
</item>
</list>
</content>""")
</content>"""
)
self.assertEqual(result, {"content": [["1", "2"], ["3", "4"]]})

result = data.load("""
result = data.load(
"""
<content>
<list>
<item><dict><key name='n1'>v1</key></dict></item>
<item><dict><key name='n2'>v2</key></dict></item>
<item><dict><key name='n3'>v3</key></dict></item>
<item><dict><key name='n4'>v4</key></dict></item>
</list>
</content>""")
</content>"""
)
self.assertEqual(
result,
{"content": [{"n1": "v1"}, {"n2": "v2"}, {"n3": "v3"}, {"n4": "v4"}]},
)

result = data.load("""
result = data.load(
"""
<ns1:dict xmlns:ns1="http://dev.splunk.com/ns/rest">
<ns1:key name="build">101089</ns1:key>
<ns1:key name="cpu_arch">i386</ns1:key>
<ns1:key name="isFree">0</ns1:key>
</ns1:dict>
""")
"""
)
self.assertEqual(result, {"build": "101089", "cpu_arch": "i386", "isFree": "0"})

def test_record(self):
Expand Down
Loading