コード例 #1
0
    def test_css_same_name_different_path_include_boths(self):
        self._signal_has_been_called = False
        template = Template('''
            {% load medialint_tags %}
            {% cssjoin "/media/css/reset.css" %}
                <link rel="stylesheet" href="/media/css/fake_joined.css" />
                <link rel="stylesheet" href="/media/css2/fake_joined.css" />
            {% endcssjoin %}
        ''')
        view_1, args_1, kwargs_1 = resolve('/media/css/fake_joined.css')
        view_2, args_2, kwargs_2 = resolve('/media/css2/fake_joined.css')
        content_1 = view_1(request=HttpRequest(), *args_1, **kwargs_1)
        content_2 = view_2(request=HttpRequest(), *args_2, **kwargs_2)
        content_expected = "".join([content_1.content, content_2.content])
        
        def on_render(sender, **kw):
            self.assertEquals(
                 kw['joined_content'],
                 '.teste{border:solid 1px}.teste2{font:12px}'
             )
            self._signal_has_been_called = True

        
        css_joined.connect(on_render)
        c = RequestContext({})
        got = template.render(c).strip()
        expected = '''<link rel="stylesheet" href="/media/css/reset.css" />'''

        assert self._signal_has_been_called
        self.assertEquals(got, expected)
        css_joined.disconnect(on_render)
コード例 #2
0
    def test_send_signal_before_rendering(self):
        self._signal_has_been_called = False
        def on_render(sender, **kw):
            self.assertEquals(kw['css_name'], '/some/path/grid-stuff.css')
            self.assertEquals(
                kw['css_files'],
                ['/media/foo.css', '/media/css/bar.css']
            )
            self.assertEquals(
                kw['joined_content'],
                "#foo{color:red}#bar{color:blue;font:11px}"
            )
            self._signal_has_been_called = True

        t = Template('''{% load medialint_tags %}
            {% cssjoin "/some/path/grid-stuff.css" %}
                <link rel="stylesheet" href="/media/foo.css" />
                <link rel="stylesheet" href="/media/css/bar.css" />
            {% endcssjoin %}
        ''')
        c = RequestContext({})
        css_joined.connect(on_render)
        t.render(c)

        assert self._signal_has_been_called
        css_joined.disconnect(on_render)