Exemplo n.º 1
0
    def test_css_packages_with_pipeline_enabled(self):
        """Testing PipelineFormMedia.css_packages with PIPELINE_ENABLED=True"""
        class MyMedia(PipelineFormMedia):
            css_packages = {
                'all': ('styles1', 'styles2'),
                'print': ('print', ),
            }

            css = {'all': ('extra1.css', 'extra2.css')}

        media = Media(MyMedia)

        self.assertEqual(
            MyMedia.css, {
                'all': [
                    'extra1.css',
                    'extra2.css',
                    '/static/styles1.min.css',
                    '/static/styles2.min.css',
                ],
                'print': ['/static/print.min.css'],
            })
        self.assertEqual(MyMedia.css, media._css)
        self.assertEqual(list(media.render_css()), [
            '<link href="%s" type="text/css" media="all" '
            'rel="stylesheet" />' % path for path in (
                '/static/extra1.css',
                '/static/extra2.css',
                '/static/styles1.min.css',
                '/static/styles2.min.css',
            )
        ] + [
            '<link href="/static/print.min.css" type="text/css" '
            'media="print" rel="stylesheet" />'
        ])
Exemplo n.º 2
0
    def test_css_packages_with_pipeline_disabled(self):
        """Testing PipelineFormMedia.css_packages with PIPELINE_ENABLED=False"""
        class MyMedia(PipelineFormMedia):
            css_packages = {
                'all': ('styles1', 'styles2'),
                'print': ('print',),
            }

            css = {
                'all': ('extra1.css', 'extra2.css')
            }

        media = Media(MyMedia)

        self.assertEqual(
            MyMedia.css,
            {
                'all': [
                    'extra1.css',
                    'extra2.css',
                    'pipeline/css/first.css',
                    'pipeline/css/second.css',
                    'pipeline/css/unicode.css',
                ],
                'print': ['pipeline/css/urls.css'],
            })
        self.assertEqual(MyMedia.css, media._css)

        expected_regex = [
            '<link href="%s" type="text/css" media="all" '
            'rel="stylesheet"( /)?>' % path
            for path in (
                '/static/extra1.css',
                '/static/extra2.css',
                '/static/pipeline/css/first.css',
                '/static/pipeline/css/second.css',
                '/static/pipeline/css/unicode.css',
            )
        ] + [
            '<link href="/static/pipeline/css/urls.css" type="text/css" '
            'media="print" rel="stylesheet"( /)?>'
        ]
        for rendered_node, expected_node in zip(
            media.render_css(), expected_regex
        ):
            self.assertRegex(rendered_node, expected_node)
Exemplo n.º 3
0
    def test_css_packages_with_pipeline_disabled(self):
        """Testing PipelineFormMedia.css_packages with PIPELINE_ENABLED=False"""
        class MyMedia(PipelineFormMedia):
            css_packages = {
                'all': ('styles1', 'styles2'),
                'print': ('print',),
            }

            css = {
                'all': ('extra1.css', 'extra2.css')
            }

        media = Media(MyMedia)

        self.assertEqual(
            MyMedia.css,
            {
                'all': [
                    'extra1.css',
                    'extra2.css',
                    'pipeline/css/first.css',
                    'pipeline/css/second.css',
                    'pipeline/css/unicode.css',
                ],
                'print': ['pipeline/css/urls.css'],
            })
        self.assertEqual(MyMedia.css, media._css)
        self.assertEqual(
            list(media.render_css()),
            [
                '<link href="%s" type="text/css" media="all" '
                'rel="stylesheet" />' % path
                for path in (
                    '/static/extra1.css',
                    '/static/extra2.css',
                    '/static/pipeline/css/first.css',
                    '/static/pipeline/css/second.css',
                    '/static/pipeline/css/unicode.css',
                )
            ] + [
                '<link href="/static/pipeline/css/urls.css" type="text/css" '
                'media="print" rel="stylesheet" />'
            ])