示例#1
0
    def test_token_name_with_something(self):
        template = "Hello ##first-name## ##last name##, welcome to our ##club.name##"
        values = {'first-name': 'Bob', 'last name':'Anderson', 'club.name': 'NBA Club'}

        content = xrender(template, values)

        self.assertEqual("Hello Bob Anderson, welcome to our NBA Club", content)
示例#2
0
    def test_rend_a_template_with_single_sharp(self):
        template = "#"
        values = {}

        content = xrender(template, values)

        self.assertEqual("#", content)
示例#3
0
    def test_ignore_overmany_values_when_rendering_a_template(self):
        template = "Hello ##firstname##, welcome to our ##clubname##"
        values = {'firstname': 'Bob', 'lastname': 'Brown', 'clubname': 'NBA Club', 'age': 26}

        content = xrender(template, values)

        self.assertEqual("Hello Bob, welcome to our NBA Club", content)
示例#4
0
    def test_rend_a_template_with_even_sharps(self):
        template = "####"
        values = {}

        content = xrender(template, values)

        self.assertEqual("####", content)
示例#5
0
    def test_render_a_template_with_case_insensitive(self):
        template = "Hello ##firstname##, welcome to our ##clubname##"
        values = {'FirstName': 'Bob', 'ClubName': 'NBA Club'}

        content = xrender(template, values)

        self.assertEqual("Hello Bob, welcome to our NBA Club", content)
示例#6
0
    def test_render_a_template_and_retain_illegal_sharps(self):
        template = "Hello ##firstname##, ##welcome ####to our ##clubname#### ###"
        values = {'firstname': 'Bob', 'clubname': 'NBA Club'}

        content = xrender(template, values)

        self.assertEqual("Hello Bob, ##welcome ####to our NBA Club## ###", content)
示例#7
0
    def test_render_a_template_and_retain_undefined_token(self):
        template = "Hello ##firstname##, welcome to our ##clubname##"
        values = {'firstname': 'Bob'}

        content = xrender(template, values)

        self.assertEqual("Hello Bob, welcome to our ##clubname##", content)
示例#8
0
    def test_render_a_template_and_use_alt_value_as_default(self):
        template = "Hello ##firstname##, welcome to our ##clubname##"
        values = {'clubname': 'NBA Club'}

        content = xrender(template, values, alts={'firstname': 'Daniel', 'clubname': 'Football Club'})

        self.assertEqual("Hello Daniel, welcome to our NBA Club", content)
示例#9
0
    def test_should_render_string_by_simple_template(self):
        self.assertEquals(xrender('test ###name## Sucks!', {'name': 'Jinja'}),
                          'test #Jinja Sucks!'
        )
        self.assertEquals(xrender('test ####name## Sucks!', {'name': 'Jinja'}),
                          'test ##Jinja Sucks!'
        )
        self.assertEquals(xrender('test # ##name## Sucks!', {'name': 'Jinja'}),
                          'test # Jinja Sucks!'
        )
        self.assertEquals(xrender('test ## ##name## Sucks!', {'name': 'Jinja'}),
                          'test ## Jinja Sucks!'
        )

        self.assertEquals(xrender('test ## ##name## ##Sucks!', {'name': 'Jinja'}),
                          'test ## Jinja ##Sucks!'
        )
示例#10
0
    def test_customer_formatter(self):
        def my_formatter(obj):
            if isinstance(obj, datetime):
                return str(obj.year)
            return xstr(obj)

        template = "Hello your are born in ##birth-date##"
        values = {'birth-date':datetime.now()}

        content = xrender(template, values, formatter=my_formatter)

        self.assertEqual("Hello your are born in 2011", content)
示例#11
0
 def test_should_render_string_by_xrender(self):
     self.assertEquals(xrender(self.content, self.model),
                       self.expected
     )
示例#12
0
    def test_render_to_blank_when_no_altvalue_in_personalization_define_and_not_provide_values(self):
        template = "Your name is ##firstname##.##lastname##"
        values = {}
        content = xrender(template, values, alts={'firstname': None, 'lastname': ''})

        self.assertEqual("Your name is .", content)
示例#13
0
    def test_render_a_template_with_concatenated_tokes(self):
        template = "Your user ID is ##No_prefix####No##"
        values = {'No_prefix': 'NBA-', 'No': 1}
        content = xrender(template, values)

        self.assertEqual("Your user ID is NBA-1", content)
示例#14
0
 def test_rend_a_template_when_token_prefix_is_an_sharp(self):
     template = "###No##"
     values = {'No': 1}
     content = xrender(template, values)
     self.assertEqual("#1", content)
示例#15
0
    def test_render_a_template_by_given_values(self):
        template = "Hello ##firstname##, welcome to our ##clubname##"
        values = {'firstname': 'Bob', 'clubname': 'NBA Club'}
        content = xrender(template, values)

        self.assertEqual("Hello Bob, welcome to our NBA Club", content)