Skip to content

Commit 0ff7be2

Browse files
chore: minor adjusstments and ut fixes
1 parent bf02466 commit 0ff7be2

File tree

8 files changed

+19
-24
lines changed

8 files changed

+19
-24
lines changed

pytest_splunk_addon/fields_tests/test_generator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ def generate_requirements_tests(self):
270270
}
271271

272272
if event.metadata.get("ingest_with_uuid"):
273-
unique_identifier = getattr(event, "unique_identifier", None)
274-
if unique_identifier is not None:
275-
sample_event["unique_identifier"] = unique_identifier
273+
sample_event["unique_identifier"] = event.unique_identifier
276274

277275
yield pytest.param(
278276
sample_event,

pytest_splunk_addon/fields_tests/test_templates.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ def test_requirements_fields(
166166
"unique_identifier"
167167
)
168168
escaped_event = splunk_searchtime_fields_requirements.get("escaped_event")
169-
event_identifier = (
170-
unique_identifier if unique_identifier is not None else escaped_event
171-
)
169+
event_identifier = unique_identifier or escaped_event
172170

173171
record_property("Event_with", event_identifier)
174172
record_property("fields", splunk_searchtime_fields_requirements["fields"])
@@ -190,9 +188,9 @@ def test_requirements_fields(
190188
if param_value is not None:
191189
basic_search += f" {param}={param_value}"
192190

193-
if unique_identifier is not None:
191+
if unique_identifier:
194192
selector = f'unique_identifier="{unique_identifier}"'
195-
elif escaped_event is not None:
193+
elif escaped_event:
196194
selector = escaped_event
197195
else:
198196
selector = ""

pytest_splunk_addon/sample_generation/sample_stanza.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def tokenize(self, conf_name):
104104
if each_rule:
105105
raw_event[event_counter] = each_rule.apply(raw_event[event_counter])
106106
for event in raw_event[event_counter]:
107-
# Assign UUID per finalized event to ensure uniqueness across variants
108107
if event.metadata.get("ingest_with_uuid"):
109108
event.unique_identifier = str(uuid.uuid4())
110109

pytest_splunk_addon/sample_generation/sample_xdist_generator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class SampleXdistGenerator:
3333
process_count (num): generate {no} process for execution
3434
"""
3535

36-
def __init__(self, addon_path, ingest_with_uuid: bool, config_path=None, process_count=4):
36+
def __init__(
37+
self, addon_path, ingest_with_uuid: bool, config_path=None, process_count=4
38+
):
3739
self.addon_path = addon_path
3840
self.process_count = process_count
3941
self.config_path = config_path

tests/unit/tests_standard_lib/test_event_ingestors/test_ingestor_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_events_can_be_ingested(
124124
get_ingestor_mock, sample_mock, file_monitor_events, modinput_events
125125
):
126126
event_ingestors.ingestor_helper.IngestorHelper.ingest_events(
127-
ingest_meta_data={"ingest_with_uuid": "false"},
127+
ingest_meta_data={"ingest_with_uuid": False},
128128
addon_path="fake_path",
129129
config_path="tests/unit/event_ingestors",
130130
thread_count=20,
@@ -133,8 +133,8 @@ def test_events_can_be_ingested(
133133
assert get_ingestor_mock.call_count == 2
134134
get_ingestor_mock.assert_has_calls(
135135
[
136-
call("file_monitor", {"ingest_with_uuid": "false"}),
137-
call("modinput", {"ingest_with_uuid": "false"}),
136+
call("file_monitor", {"ingest_with_uuid": False}),
137+
call("modinput", {"ingest_with_uuid": False}),
138138
],
139139
any_order=True,
140140
)

tests/unit/tests_standard_lib/tests_sample_generation/test_sample_stanza.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_params_for_get_raw_sample():
3030
{
3131
"input_type": input_type,
3232
"host": "path_to.file_1",
33-
"ingest_with_uuid": "false",
33+
"ingest_with_uuid": False,
3434
},
3535
"path_to.file",
3636
],
@@ -54,7 +54,7 @@ def get_params_for_get_raw_sample():
5454
{
5555
"input_type": input_type,
5656
"host": "path_to.file",
57-
"ingest_with_uuid": "false",
57+
"ingest_with_uuid": False,
5858
},
5959
"path_to.file",
6060
],
@@ -74,7 +74,7 @@ def func(
7474
"pytest_splunk_addon.sample_generation.sample_stanza.Rule",
7575
MagicMock(return_value=rule_mock_value),
7676
):
77-
ss = SampleStanza(SAMPLE_PATH, psa_data_params, "false")
77+
ss = SampleStanza(SAMPLE_PATH, psa_data_params, False)
7878
return ss
7979

8080
return func
@@ -194,7 +194,7 @@ def test_parse_meta(
194194
"expected_event_count": "hh",
195195
"count": "ll",
196196
"index": 1,
197-
"ingest_with_uuid": "false",
197+
"ingest_with_uuid": False,
198198
"input_type": input_type,
199199
"tokens": {
200200
"token_1": {"replacementType": "all"},
@@ -208,7 +208,7 @@ def test_parse_meta(
208208
"host": host,
209209
"host_type": "plugin",
210210
"index": 1,
211-
"ingest_with_uuid": "false",
211+
"ingest_with_uuid": False,
212212
"input_type": input_type_expected,
213213
"sample_count": "1",
214214
"timestamp_type": "plugin",
@@ -223,7 +223,7 @@ def test_get_eventmetadata(self, sample_stanza):
223223
assert ss.get_eventmetadata() == {
224224
"host": "path_to.file_1",
225225
"input_type": "default",
226-
"ingest_with_uuid": "false",
226+
"ingest_with_uuid": False,
227227
}
228228
assert ss.host_count == 1
229229

@@ -257,7 +257,7 @@ def test_break_events(self, sample_stanza, sample_raw, expected):
257257
"breaker": "aa",
258258
"host": "path_to.file_1",
259259
"input_type": "default",
260-
"ingest_with_uuid": "false",
260+
"ingest_with_uuid": False,
261261
},
262262
"path_to.file",
263263
],

tests/unit/tests_standard_lib/tests_sample_generation/test_uuid_e2e_flow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,7 @@ def test_uuid_not_stored_when_disabled(self):
526526
"os.getcwd", return_value="/fake/path"
527527
), patch("os.makedirs"), patch("builtins.open", mock_open()) as open_mock:
528528

529-
xdist_generator = SampleXdistGenerator(
530-
"/fake/addon", False, "/fake/config"
531-
)
529+
xdist_generator = SampleXdistGenerator("/fake/addon", False, "/fake/config")
532530
xdist_generator.store_events(events)
533531

534532
# Get the written JSON

tests/unit/tests_standard_lib/tests_sample_generation/test_uuid_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_uuid_generated_when_flag_enabled(self):
4040
), "unique_identifier should be a string"
4141

4242
def test_uuid_not_generated_when_flag_disabled(self):
43-
"""Verify UUID is NOT generated when ingest_with_uuid is 'false'"""
43+
"""Verify UUID is NOT generated when ingest_with_uuid is False"""
4444
metadata = {"ingest_with_uuid": False, "index": "main"}
4545
event = SampleEvent(
4646
event_string="test event", metadata=metadata, sample_name="test.sample"

0 commit comments

Comments
 (0)