diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index 8541fe79d..b0d37746e 100644 --- a/pytest_splunk_addon/standard_lib/addon_basic.py +++ b/pytest_splunk_addon/standard_lib/addon_basic.py @@ -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 @@ -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 ): diff --git a/pytest_splunk_addon/standard_lib/addon_requirements_basic.py b/pytest_splunk_addon/standard_lib/addon_requirements_basic.py new file mode 100644 index 000000000..d09e4af6c --- /dev/null +++ b/pytest_splunk_addon/standard_lib/addon_requirements_basic.py @@ -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}" + ) diff --git a/pytest_splunk_addon/standard_lib/requirement_tests/test_templates.py b/pytest_splunk_addon/standard_lib/requirement_tests/test_templates.py index 9b83c5b85..f9e9f5710 100644 --- a/pytest_splunk_addon/standard_lib/requirement_tests/test_templates.py +++ b/pytest_splunk_addon/standard_lib/requirement_tests/test_templates.py @@ -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"] diff --git a/tests/constants.py b/tests/constants.py index f144fe4ef..48ae87634 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -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. @@ -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 diff --git a/tests/test_splunk_addon.py b/tests/test_splunk_addon.py index ac24283c1..3578106e8 100644 --- a/tests/test_splunk_addon.py +++ b/tests/test_splunk_addon.py @@ -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 """ @@ -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 """ @@ -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 """ @@ -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 """