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
6 changes: 1 addition & 5 deletions pytest_splunk_addon/standard_lib/addon_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
from .fields_tests import FieldTestTemplates
from .cim_tests import CIMTestTemplates, FieldTestHelper
from .index_tests import IndexTimeTestTemplate
from .requirement_tests import ReqsTestTemplates
import pytest


class Basic(
FieldTestTemplates, CIMTestTemplates, IndexTimeTestTemplate, ReqsTestTemplates
):
class Basic(FieldTestTemplates, CIMTestTemplates, IndexTimeTestTemplate):
"""
Base class for test cases. Inherit this class to include the test
cases for an Add-on. Only implement the common tests here, all the other
Expand All @@ -40,7 +37,6 @@ class Basic(
@pytest.mark.splunk_indextime
@pytest.mark.splunk_searchtime_cim
@pytest.mark.splunk_searchtime_fields
@pytest.mark.splunk_searchtime_requirements
def test_events_with_untokenised_values(
self, splunk_search_util, splunk_ingest_data, splunk_setup, record_property
):
Expand Down
65 changes: 65 additions & 0 deletions pytest_splunk_addon/standard_lib/addon_requirements_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2022 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.
#
"""
Base class for requirement test cases.
"""
from .requirement_tests import ReqsTestTemplates
from .cim_tests import FieldTestHelper
import pytest


class RequirementBasic(ReqsTestTemplates):
"""
Base class for requirement test cases.Only implement the common tests here.
"""

@pytest.mark.splunk_searchtime_requirements
def test_events_with_untokenised_values(
self, splunk_search_util, splunk_ingest_data, splunk_setup, record_property
):
"""
Test case to validate that all the events have been properly tokenised

Args:
splunk_search_util (SearchUtil): Object that helps to search on Splunk.
splunk_ingest_data (fixture): To ingest data into splunk.
record_property (fixture): Document facts of test cases.

"""
query = f"search index=* ##*## | stats count by source, sourcetype"
record_property("Query", query)
results = list(
splunk_search_util.getFieldValuesList(
query,
interval=0,
retries=0,
)
)
if results:
record_property("results", results)
result_str = FieldTestHelper.get_table_output(
headers=["Source", "Sourcetype"],
value_list=[
[
result.get("source"),
result.get("sourcetype"),
]
for result in results
],
)
assert False, (
f"For the query: '{query}'\n"
f"Some fields are not tokenized in the events of following source and sourcetype \n{result_str}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ def remove_empty_keys(self, event):

@pytest.mark.splunk_searchtime_requirements
def test_requirement_params(
self, splunk_searchtime_requirement_param, splunk_search_util
self,
splunk_searchtime_requirement_param,
splunk_search_util,
splunk_ingest_data,
):
model_datalist = splunk_searchtime_requirement_param["model_list"]
escaped_event = splunk_searchtime_requirement_param["escaped_event"]
Expand Down
2 changes: 0 additions & 2 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@
"*test_splunk_fiction_indextime.py::Test_App::test_tags*splunk_searchtime_fields_tags0* SKIPPED*",
"*test_splunk_fiction_indextime.py::Test_App::test_eventtype*splunk_searchtime_fields_eventtypes0* SKIPPED*",
"*test_splunk_fiction_indextime.py::Test_App::test_savedsearches*splunk_searchtime_fields_savedsearches0* SKIPPED*",
"*test_splunk_fiction_indextime.py::Test_App::test_requirement_params* SKIPPED*",
]
"""
Define the TA_fiction_indextime_broken add-on passed test case list.
Expand Down Expand Up @@ -739,7 +738,6 @@
"*test_splunk_fiction_indextime_broken.py::Test_App::test_tags*splunk_searchtime_fields_tags0* SKIPPED*",
"*test_splunk_fiction_indextime_broken.py::Test_App::test_eventtype*splunk_searchtime_fields_eventtypes0* SKIPPED*",
"*test_splunk_fiction_indextime_broken.py::Test_App::test_savedsearches*splunk_searchtime_fields_savedsearches0* SKIPPED*",
"*test_splunk_fiction_indextime_broken.py::Test_App::test_requirement_params* SKIPPED*",
]
"""
Define TA_requirement_tests passed test
Expand Down
16 changes: 8 additions & 8 deletions tests/test_splunk_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ def test_splunk_app_requirements(testdir):

testdir.makepyfile(
"""
from pytest_splunk_addon.standard_lib.addon_basic import Basic
class Test_App(Basic):
from pytest_splunk_addon.standard_lib.addon_requirements_basic import RequirementBasic
class Test_App(RequirementBasic):
def empty_method():
pass
"""
Expand Down Expand Up @@ -563,8 +563,8 @@ def test_splunk_app_requirements_modinput(testdir):

testdir.makepyfile(
"""
from pytest_splunk_addon.standard_lib.addon_basic import Basic
class Test_App(Basic):
from pytest_splunk_addon.standard_lib.addon_requirements_basic import RequirementBasic
class Test_App(RequirementBasic):
def empty_method():
pass
"""
Expand Down Expand Up @@ -611,8 +611,8 @@ def test_splunk_app_requirements_uf(testdir):

testdir.makepyfile(
"""
from pytest_splunk_addon.standard_lib.addon_basic import Basic
class Test_App(Basic):
from pytest_splunk_addon.standard_lib.addon_requirements_basic import RequirementBasic
class Test_App(RequirementBasic):
def empty_method():
pass
"""
Expand Down Expand Up @@ -654,8 +654,8 @@ def test_splunk_app_requirements_scripted(testdir):

testdir.makepyfile(
"""
from pytest_splunk_addon.standard_lib.addon_basic import Basic
class Test_App(Basic):
from pytest_splunk_addon.standard_lib.addon_requirements_basic import RequirementBasic
class Test_App(RequirementBasic):
def empty_method():
pass
"""
Expand Down