Ejemplo n.º 1
0
 def test_parse_tag_special_symbol_in_arg_value(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, u'tag_name "será?"')
     args_kwargs = EasyNode.parse_to_args_kwargs(parser, token)
     args_kwargs_str = {'args': tuple([x.token for x in args_kwargs['args']]),
                        'kwargs': dict((key, value.token) for key, value in args_kwargs['kwargs'].iteritems())}
     self.assertEquals(
         {'args': (u'"será?"',), 'kwargs': {}},
         args_kwargs_str
     )
Ejemplo n.º 2
0
 def test_parse_tag_with_variable_arg(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, 'tag_name argvariable')
     args_kwargs = EasyNode.parse_to_args_kwargs(parser, token)
     args_kwargs_str = {'args': tuple([x.token for x in args_kwargs['args']]),
                        'kwargs': dict((key, value.token) for key, value in args_kwargs['kwargs'].iteritems())}
     self.assertEquals(
         {'args': ('argvariable',), 'kwargs': {}},
         args_kwargs_str
     )
Ejemplo n.º 3
0
 def test_parse_tag_with_equals_in_kwarg_value(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, 'tag_name kwarg1="a=1"')
     args_kwargs = EasyNode.parse_to_args_kwargs(parser, token)
     args_kwargs_str = {'args': tuple([x.token for x in args_kwargs['args']]),
                        'kwargs': dict((key, value.token) for key, value in args_kwargs['kwargs'].iteritems())}
     self.assertEquals(
         {'args': (), 'kwargs': {'kwarg1': '"a=1"'}},
         args_kwargs_str
     )
Ejemplo n.º 4
0
    def test_node_applies_filters_to_variable_in_kwargs(self):
        parser = template.Parser([])
        context = Context({'variable': "string1 string2"})
        token = template.Token(template.TOKEN_BLOCK, 'tag_name arg1=variable|slugify|upper')
        args_kwargs = EasyNode.parse_to_args_kwargs(parser, token)

        node = MyEasyNode(args_kwargs)

        self.assertEquals(
            u'STRING1-STRING2',
            node.render(context),
        )
Ejemplo n.º 5
0
 def test_parse_tag_with_args_and_kwargs(self):
     """
         Tests if the parser recognizes one tag and parses its args and kwargs
     """
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, 'tag_name "arg1" kwarg1="1"')
     args_kwargs = EasyNode.parse_to_args_kwargs(parser, token)
     args_kwargs_str = {'args': tuple([x.token for x in args_kwargs['args']]),
                        'kwargs': dict((key, value.token) for key, value in args_kwargs['kwargs'].iteritems())}
     self.assertEquals(
         {'args': ('"arg1"',), 'kwargs': {'kwarg1': '"1"'}},
         args_kwargs_str
     )