Пример #1
0
 def test_parse_tag_special_symbol_in_kwarg_value(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, u'tag_name kwarg1="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': (), 'kwargs': {'kwarg1': u'"será?"'}},
         args_kwargs_str
     )
Пример #2
0
 def test_parse_tag_with_equals_in_arg_value(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, 'tag_name "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': ('"a=1"',), 'kwargs': {}},
         args_kwargs_str
     )
Пример #3
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),
        )
Пример #4
0
 def test_parse_tag_with_equals_in_arg_value(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, 'tag_name "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': ('"a=1"', ), 'kwargs': {}}, args_kwargs_str)
Пример #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
     )
Пример #6
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),
        )
Пример #7
0
 def test_parse_tag_special_symbol_in_kwarg_value(self):
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK,
                            u'tag_name kwarg1="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': (),
         'kwargs': {
             'kwarg1': u'"será?"'
         }
     }, args_kwargs_str)
Пример #8
0
 def test_parse_tag_with_args(self):
     """
         Tests if the parser recognizes one tag and parses its args
     """
     parser = template.Parser([])
     token = template.Token(template.TOKEN_BLOCK, 'tag_name "arg1" "arg2"')
     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"', '"arg2"'),
         'kwargs': {}
     }, args_kwargs_str)