Ejemplo n.º 1
0
 def decorate(self, response: StoqResponse) -> Optional[DecoratorResponse]:
     if self.RAISE_EXCEPTION:
         raise Exception('Test exception please ignore')
     dr = DecoratorResponse({'simple_decoration': 123})
     if self.RETURN_ERRORS:
         dr.errors += ['Test error please ignore']
     return dr
Ejemplo n.º 2
0
 async def decorate(self,
                    response: StoqResponse) -> Optional[DecoratorResponse]:
     if self.RAISE_EXCEPTION:
         raise Exception('Test exception please ignore')
     dr = DecoratorResponse({'simple_decoration': 123})
     if self.RETURN_ERRORS:
         dr.errors.append(
             Error(plugin_name='simple_decorator',
                   error='Test error please ignore'))
     return dr
Ejemplo n.º 3
0
    def decorate(self, response: StoqResponse) -> DecoratorResponse:
        """
        Decorate results using a template

        """
        results = None
        try:
            dirname = os.path.dirname(self.template)
            basename = os.path.basename(self.template)
            env = Environment(
                loader=FileSystemLoader(dirname),
                trim_blocks=True,
                lstrip_blocks=True,
                autoescape=select_autoescape(default_for_string=True, default=True),
            )
            results = env.get_template(basename).render(response=response)
        except TemplateNotFound:
            raise StoqPluginException(f'Template path not found: {self.template}')

        return DecoratorResponse(results)
Ejemplo n.º 4
0
 def test_decoratorresponse_to_str(self):
     response = DecoratorResponse()
     response_str = str(response)
     response_dict = json.loads(response_str)
     self.assertIsInstance(response_str, str)
     self.assertIsInstance(response_dict, dict)