test for automations applied during url import

renamed TITLE_REPLACE to NAME_REPLACE
This commit is contained in:
smilerz
2023-09-01 07:37:36 -05:00
parent 2679a22464
commit 9b5e39415e
11 changed files with 99 additions and 31 deletions

View File

@ -20,7 +20,7 @@ class AutomationEngine:
Automation.INSTRUCTION_REPLACE: None,
Automation.FOOD_REPLACE: None,
Automation.UNIT_REPLACE: None,
Automation.TITLE_REPLACE: None,
Automation.NAME_REPLACE: None,
}
def __init__(self, request, use_cache=True, source=None):
@ -191,7 +191,7 @@ class AutomationEngine:
Automation.INSTRUCTION_REPLACE
Automation.FOOD_REPLACE
Automation.UNIT_REPLACE
Automation.TITLE_REPLACE
Automation.NAME_REPLACE
regex replacment utilized the following fields from the Automation model
:param 1: source that should apply the automation in regex format ('.*' for all)
@ -218,10 +218,10 @@ class AutomationEngine:
if self.regex_replace[automation_type]:
for rule in self.regex_replace[automation_type].values():
if re.match(rule[0], (self.source)[:512]):
string = re.sub(rule[1], rule[2], string)
string = re.sub(rule[1], rule[2], string, flags=re.IGNORECASE)
else:
for rule in Automation.objects.filter(space=self.request.space, disabled=False, type=automation_type).only(
'param_1', 'param_2', 'param_3').order_by('order').all()[:512]:
if re.match(rule.param_1, (self.source)[:512]):
string = re.sub(rule.param_2, rule.param_3, string)
string = re.sub(rule.param_2, rule.param_3, string, flags=re.IGNORECASE)
return string