예제 #1
0
 def __init__(self, items: Dict[str, Any], id: Optional[str] = None):
     super(AddHistoryEventAction, self).__init__(items, id)
     self.results = UnifiedTemplate(items.get("results"))
     self.event_type = UnifiedTemplate(items.get("event_type"))
     self.event_content = items.get("event_content")
     if self.event_content:
         for k, v in self.event_content.items():
             self.event_content[k] = UnifiedTemplate(v)
예제 #2
0
 def __init__(self,
              items: Optional[Dict[str, Any]],
              id: Optional[str] = None) -> None:
     super(AvailableInfoFiller, self).__init__(items, id)
     value = items['value']
     self.loader = items.get('loader')
     self.template: UnifiedTemplate = UnifiedTemplate(value)
 def test_bool_cast_true_lowercase(self):
     template = UnifiedTemplate({
         "type": UNIFIED_TEMPLATE_TYPE_NAME,
         "loader": "bool",
         "template": "true"
     })
     self.assertTrue(template.render({}))
 def test_bool_cast_false(self):
     template = UnifiedTemplate({
         "type": UNIFIED_TEMPLATE_TYPE_NAME,
         "loader": "bool",
         "template": "False"
     })
     self.assertFalse(template.render({}))
예제 #5
0
 def __init__(self, items: Dict[str, Any], id: Optional[str] = None):
     super(SetVariableAction, self).__init__(items, id)
     self.key: str = items["key"]
     self.loader = items.get('loader')
     self.ttl: int = items.get("ttl")
     value: str = items["value"]
     self.template: UnifiedTemplate = UnifiedTemplate(value)
 def test_type_cast_json(self):
     template = UnifiedTemplate({
         "type": UNIFIED_TEMPLATE_TYPE_NAME,
         "loader": "json",
         "template": "{{ input }}"
     })
     self.assertEqual([1, 2, 3], template.render({"input": [1, 2, 3]}))
 def test_type_cast_int(self):
     template = UnifiedTemplate({
         "type": UNIFIED_TEMPLATE_TYPE_NAME,
         "loader": "int",
         "template": "{{ input ** 2 }}"
     })
     self.assertEqual(49, template.render({"input": 7}))
예제 #8
0
 def _render_request_data(self, action_params):
     # копируем прежде чем рендерить шаблон хэдеров, чтобы не затереть его
     request_data = copy(self.request_data)
     request_data[self.EX_HEADERS_NAME] = {
         key: UnifiedTemplate(value).render(action_params)
         for key, value in request_data.get(self.EX_HEADERS_NAME).items()
     }
     return request_data
예제 #9
0
 def _get_template_tree(self, value):
     is_dict_unified_template = isinstance(value, dict) and value.get("type") == UNIFIED_TEMPLATE_TYPE_NAME
     if isinstance(value, str) or is_dict_unified_template:
         result = UnifiedTemplate(value)
     elif isinstance(value, dict):
         result = {}
         for inner_key, inner_value in value.items():
             result[inner_key] = self._get_template_tree(inner_value)
     elif isinstance(value, list):
         result = []
         for inner_value in value:
             result.append(self._get_template_tree(inner_value))
     else:
         result = value
     return result
 def test_support_templates(self):
     template = UnifiedTemplate({
         "type": UNIFIED_TEMPLATE_TYPE_NAME,
         "support_templates": {
             "name": "{{ personInfo.name|capitalize }}",
             "surname": "{{ personInfo.surname|capitalize }}"
         },
         "template": "{{ name }} {{ surname }}",
     })
     self.assertEqual(
         "Vasya Pupkin",
         template.render(
             {"personInfo": {
                 "name": "vasya",
                 "surname": "pupkin"
             }}))
 def get_text_by_key(self, bundle_name: str, reply_key="") -> str:
     result = ""
     bundle = self._bundles[bundle_name]
     if bundle:
         reply_list = None
         for suffix in self.__suffix:
             target_key = f"{reply_key}{suffix}"
             reply_list = bundle.get(target_key)
             if reply_list:
                 break
         if reply_list:
             params = self._user.parametrizer.collect(
             )  # TODO give run-time action parameters to collect call
             result_str = random.choice(reply_list)
             result = UnifiedTemplate(result_str).render(params)
         else:
             raise KeyError("Key not found")
     return result
 def test_ordinar_jinja_backward_compatibility(self):
     template = UnifiedTemplate("abc {{input}}")
     self.assertEqual("abc def", template.render({"input": "def"}))
예제 #13
0
 def __init__(self, items: Dict[str, Any], id: Optional[str] = None):
     super(RunScenarioAction, self).__init__(items, id)
     self.scenario: UnifiedTemplate = UnifiedTemplate(items["scenario"])
예제 #14
0
 def __init__(self, items: Dict[str, Any], id: Optional[str] = None):
     super(FillFieldAction, self).__init__(items, id)
     self.form = items["form"]
     self.field: str = items["field"]
     data_path = items["data_path"]
     self.template: UnifiedTemplate = UnifiedTemplate(data_path)
 def __init__(self,
              items: Dict[str, Any],
              id: Optional[str] = None) -> None:
     super(ArrayItemInTemplateRequirement, self).__init__(items, id)
     self._template = UnifiedTemplate(items["template"])
     self._items = set(items["items"])
 def __init__(self,
              items: Dict[str, Any],
              id: Optional[str] = None) -> None:
     super(RegexpInTemplateRequirement, self).__init__(items, id)
     self._template = UnifiedTemplate(items["template"])
     self._regexp = re.compile(items["regexp"], re.S | re.M)
 def test_args_format_input(self):
     template = UnifiedTemplate("timestamp: {{ts}}")
     self.assertEqual("timestamp: 123.45", template.render(ts=123.45))