Skip to content

Commit

Permalink
fix: token replacement for other mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
dvarasani-crest committed Sep 11, 2024
1 parent a968cd1 commit 0e876f4
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions pytest_splunk_addon/sample_generation/sample_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ def get_token_extractions_count(self, token):
elif isinstance(extracted_field, list):
for each_filed in extracted_field:
tokens_in_extractions += len(re.findall(token, each_filed))

for extracted_field in self.requirement_test_data.get(
"other_fields", {}
).values():
if isinstance(extracted_field, str):
tokens_in_extractions += len(re.findall(token, extracted_field))
elif isinstance(extracted_field, list):
for each_filed in extracted_field:
tokens_in_extractions += len(re.findall(token, each_filed))
return 1 if tokens_in_extractions > 0 else 0

def replace_token(self, token, token_values):
Expand Down Expand Up @@ -367,18 +376,39 @@ def update_requirement_test_field(self, field, token, token_values):
if token in value:
if isinstance(token_values, list):
if len(token_values) == 1:
self.requirement_test_data["cim_fields"][
self.requirement_test_data["cim_fields"][cim_field] = (
value.replace(token, str(token_values[0].key))
)
else:
self.requirement_test_data["cim_fields"][cim_field] = [
value.replace(token, str(token_value.key))
for token_value in token_values
]
else:
self.requirement_test_data["cim_fields"][cim_field] = (
value.replace(token, str(token_values.key))
)

for cim_field, value in self.requirement_test_data.get(
"other_fields", {}
).items():
if token in value:
if isinstance(token_values, list):
if len(token_values) == 1:
self.requirement_test_data["other_fields"][
cim_field
] = value.replace(token, str(token_values[0].key))
else:
self.requirement_test_data["cim_fields"][cim_field] = [
self.requirement_test_data["other_fields"][
cim_field
] = [
value.replace(token, str(token_value.key))
for token_value in token_values
]
else:
self.requirement_test_data["cim_fields"][
cim_field
] = value.replace(token, str(token_values.key))
self.requirement_test_data["other_fields"][cim_field] = (
value.replace(token, str(token_values.key))
)

def get_key_fields(self):
"""
Expand Down

0 comments on commit 0e876f4

Please sign in to comment.