Skip to content

Commit 9cd7656

Browse files
committed
review remarks #2
1 parent 777b413 commit 9cd7656

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

tests/unit/test_eventtype_parser.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from unittest.mock import patch, PropertyMock
23
from pytest_splunk_addon.standard_lib.addon_parser.eventtype_parser import (
34
EventTypeParser,
45
)
@@ -35,8 +36,19 @@ def test_get_eventtypes_calls_app_get_config(parser_instance):
3536

3637
def test_no_eventtype_config_file(parser_instance):
3738
parser_instance.app.eventtypes_conf.side_effect = OSError
38-
output = [eventtype for eventtype in parser_instance.get_eventtypes() if eventtype]
39-
assert output == [], "eventtypes created when no config file exists"
39+
assert (
40+
parser_instance.eventtypes is None
41+
), "eventtypes created when no config file exists"
42+
43+
44+
def test_nothing_returned_when_no_tags_config_file(parser):
45+
with patch.object(
46+
EventTypeParser, "eventtypes", new_callable=PropertyMock
47+
) as eventtypes_mock:
48+
eventtypes_mock.return_value = None
49+
parser_instance = parser(EventTypeParser, "eventtypes_conf", {})
50+
output = [tag for tag in parser_instance.get_eventtypes() if tag]
51+
assert output == [], "eventtypes returned when no config file exists"
4052

4153

4254
@pytest.fixture(scope="module")

tests/unit/test_tags_parser.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
2+
from unittest.mock import patch, PropertyMock
23
from pytest_splunk_addon.standard_lib.addon_parser.tags_parser import (
34
TagsParser,
4-
unquote,
55
)
66

77

@@ -61,8 +61,15 @@ def test_get_tags_calls_app_get_config(parser_instance):
6161

6262
def test_no_tags_config_file(parser_instance):
6363
parser_instance.app.get_config.side_effect = OSError
64-
output = [tag for tag in parser_instance.get_tags() if tag]
65-
assert output == [], "tags created when no config file exists"
64+
assert parser_instance.tags is None, "tags created when no config file exists"
65+
66+
67+
def test_nothing_returned_when_no_tags_config_file(parser):
68+
with patch.object(TagsParser, "tags", new_callable=PropertyMock) as tags_mock:
69+
tags_mock.return_value = None
70+
parser_instance = parser(TagsParser, "get_config", {})
71+
output = [tag for tag in parser_instance.get_tags() if tag]
72+
assert output == [], "tags returned when no config file exists"
6673

6774

6875
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)