示例#1
0
文件: tests.py 项目: APSL/Adjax
 def test_template_include_update(self):
     """ Check the correct information is sent to the browser when updating
         a template include. 
     """
     data = self.get_view('template_include_update')
     assert 'replace' in data, repr(data)
     key = ".%s" % get_template_include_key('basic/_included.html')
     assert key in data['replace'], repr(data['replace'])
     assert 'xyz123' in data['replace'][key]
     key = ".%s" % get_template_include_key('basic/_included.html', prefix="tree")
     assert key in data['replace'], repr(data['replace'])
     assert 'mno456' in data['replace'][key]
示例#2
0
 def test_template_include_update(self):
     """ Check the correct information is sent to the browser when updating
         a template include. 
     """
     data = self.get_view('template_include_update')
     assert 'replace' in data, repr(data)
     key = ".%s" % get_template_include_key('basic/_included.html')
     assert key in data['replace'], repr(data['replace'])
     assert 'xyz123' in data['replace'][key]
     key = ".%s" % get_template_include_key('basic/_included.html',
                                            prefix="tree")
     assert key in data['replace'], repr(data['replace'])
     assert 'mno456' in data['replace'][key]
示例#3
0
    def test_alternative_response(self):
        """ A quick check on the ability to use all functionality at once. """
        data = self.get_view('alternative_response')
        assert 'replace' in data, repr(data)
        assert 'hide' in data, repr(data)
        assert 'messages' in data, repr(data)
        assert 'update' in data, repr(data)
        assert 'forms' in data, repr(data)
        assert 'redirect' in data, repr(data)
        assert 'extra' in data, repr(data)

        # replace
        self.assert_value_in(data, 'Hello world', 'replace', '#abc')
        # hide
        self.assert_value_in(data, '#xyz', 'hide', 0)
        # messages
        for message in data['messages']:
            assert message['content'].startswith(
                u"This is your first "), message
            assert message['content'].endswith(message['tags']), message
        # update
        model = MyModel(name="Abc", color="blue")
        name_key = get_key(model, 'name')
        color_key = get_key(model, 'color')
        price_key = get_key(model, 'price')
        update_dict = data['update']
        assert price_key not in update_dict
        try:
            self.assertEqual(update_dict[name_key], "Abc")
            self.assertEqual(update_dict[color_key], "blue")
        except KeyError:
            self.fail(repr(update_dict))
        # forms
        assert 'id_withprefix-color' in data['forms'], repr(data)
        self.assertEqual(data['forms']['id_withprefix-color'][0],
                         u"This field is required.")
        # redirect
        self.assertEqual(data['redirect'], reverse('do_nothing'))
        # extra
        self.assertEqual(data['extra']['one'], 123)
        self.assertEqual(data['extra']['two'], 234)
        # template include
        key = ".%s" % get_template_include_key('basic/_included.html')
        assert key in data['replace'], repr(data['replace'])
        assert 'xyz123' in data['replace'][key]
        key = ".%s" % get_template_include_key('basic/_included.html',
                                               prefix="tree")
        assert key in data['replace'], repr(data['replace'])
        assert 'mno456' in data['replace'][key]
示例#4
0
文件: tests.py 项目: APSL/Adjax
    def test_alternative_response(self):
        """ A quick check on the ability to use all functionality at once. """
        data = self.get_view('alternative_response')
        assert 'replace' in data, repr(data)
        assert 'hide' in data, repr(data)
        assert 'messages' in data, repr(data)
        assert 'update' in data, repr(data)
        assert 'forms' in data, repr(data)
        assert 'redirect' in data, repr(data)
        assert 'extra' in data, repr(data)

        # replace
        self.assert_value_in(data, 'Hello world', 'replace', '#abc')
        # hide
        self.assert_value_in(data, '#xyz', 'hide', 0)
        # messages
        for message in data['messages']:
            assert message['content'].startswith(u"This is your first "), message
            assert message['content'].endswith(message['tags']), message
        # update
        model = MyModel(name="Abc", color="blue")
        name_key = get_key(model, 'name')
        color_key = get_key(model, 'color')
        price_key = get_key(model, 'price')
        update_dict = data['update']
        assert price_key not in update_dict
        try:
            self.assertEqual(update_dict[name_key], "Abc")
            self.assertEqual(update_dict[color_key], "blue")
        except KeyError:
            self.fail(repr(update_dict))
        # forms
        assert 'id_withprefix-color' in data['forms'], repr(data)
        self.assertEqual(data['forms']['id_withprefix-color'][0], u"This field is required.")
        # redirect
        self.assertEqual(data['redirect'], reverse('do_nothing'))
        # extra
        self.assertEqual(data['extra']['one'], 123)
        self.assertEqual(data['extra']['two'], 234)
        # template include
        key = ".%s" % get_template_include_key('basic/_included.html')
        assert key in data['replace'], repr(data['replace'])
        assert 'xyz123' in data['replace'][key]
        key = ".%s" % get_template_include_key('basic/_included.html', prefix="tree")
        assert key in data['replace'], repr(data['replace'])
        assert 'mno456' in data['replace'][key]
示例#5
0
文件: tests.py 项目: APSL/Adjax
 def test_template_include_tag_1(self):
     """ Checks that the template include tag correctly includes the given
         templates.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html')
     self.assertContains(response, "13579")
     self.assertContains(response, '<div class="%s"' % key)
示例#6
0
 def test_template_include_tag_1(self):
     """ Checks that the template include tag correctly includes the given
         templates.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html')
     self.assertContains(response, "13579")
     self.assertContains(response, '<div class="%s"' % key)
示例#7
0
文件: ajax.py 项目: APSL/Adjax
 def render(self, context):
     template_name = self.template_name.resolve(context)
     wrapper = self.wrapper.resolve(context)
     prefix = self.prefix and self.prefix.resolve(context) or None
     key = get_template_include_key(template_name, prefix)
     if self.key_only:
         return key
     try:
         content = get_template(template_name).render(context)
         return '<%s class="%s">%s</%s>' % (wrapper, key, content, wrapper)
     except template.TemplateSyntaxError, e:
         if settings.TEMPLATE_DEBUG:
             raise
         return ''
示例#8
0
 def render(self, context):
     template_name = self.template_name.resolve(context)
     wrapper = self.wrapper.resolve(context)
     prefix = self.prefix and self.prefix.resolve(context) or None
     key = get_template_include_key(template_name, prefix)
     if self.key_only:
         return key
     try:
         content = get_template(template_name).render(context)
         return '<%s class="%s">%s</%s>' % (wrapper, key, content, wrapper)
     except template.TemplateSyntaxError, e:
         if settings.TEMPLATE_DEBUG:
             raise
         return ''
示例#9
0
文件: tests.py 项目: APSL/Adjax
 def test_template_include_key_tag(self):
     """ Checks that the template include key tag works correctly.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html', prefix="tree")
     self.assertContains(response, 'Key is "%s".' % key)
示例#10
0
文件: tests.py 项目: APSL/Adjax
 def test_template_include_tag_3(self):
     """ Checks that the template include tag can have a prefix.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html', prefix="tree")
     self.assertContains(response, '<div class="%s"' % key)
示例#11
0
文件: tests.py 项目: APSL/Adjax
 def test_template_include_tag_2(self):
     """ Checks that the template include tag can use a given element type.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html')
     self.assertContains(response, '<p class="%s"' % key)
示例#12
0
 def test_template_include_key_tag(self):
     """ Checks that the template include key tag works correctly.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html', prefix="tree")
     self.assertContains(response, 'Key is "%s".' % key)
示例#13
0
 def test_template_include_tag_3(self):
     """ Checks that the template include tag can have a prefix.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html', prefix="tree")
     self.assertContains(response, '<div class="%s"' % key)
示例#14
0
 def test_template_include_tag_2(self):
     """ Checks that the template include tag can use a given element type.
     """
     response = self.client.get(reverse('template_include_tag'))
     key = get_template_include_key('basic/_included.html')
     self.assertContains(response, '<p class="%s"' % key)