Пример #1
0
    def setUp(self):
        # initialize the flask app
        app = flask.Flask(__name__)
        app.config["TESTING"] = True
        compressor = Compressor(app)
        self.app = app
        self.compressor = compressor

        def processor1(content):
            return content.replace("html", " body ")

        def processor2(content):
            return content.replace(" body ", "p ")

        def processor3(content):
            return content.replace(":red}", ":blue}")

        self.compressor.register_processor(processor1)
        self.compressor.register_processor(processor2)
        self.compressor.register_processor(processor3)

        css_content = "html { background-color: red; } "
        self.asset1 = Asset(css_content, processors=["processor1", "processor2"])
        self.asset2 = Asset(css_content, processors=["processor2", "processor1"])
        self.bundle = Bundle("test_bundle", assets=[self.asset1, self.asset2], processors=["cssmin", "processor3"])
Пример #2
0
class MultipleProcessorsTestCase(unittest.TestCase):
    def setUp(self):
        # initialize the flask app
        app = flask.Flask(__name__)
        app.config["TESTING"] = True
        compressor = Compressor(app)
        self.app = app
        self.compressor = compressor

        def processor1(content):
            return content.replace("html", " body ")

        def processor2(content):
            return content.replace(" body ", "p ")

        def processor3(content):
            return content.replace(":red}", ":blue}")

        self.compressor.register_processor(processor1)
        self.compressor.register_processor(processor2)
        self.compressor.register_processor(processor3)

        css_content = "html { background-color: red; } "
        self.asset1 = Asset(css_content, processors=["processor1", "processor2"])
        self.asset2 = Asset(css_content, processors=["processor2", "processor1"])
        self.bundle = Bundle("test_bundle", assets=[self.asset1, self.asset2], processors=["cssmin", "processor3"])

    def test_asset_content(self):
        asset_content = "p  { background-color: red; } "
        with self.app.test_request_context():
            self.assertEqual(asset_content, self.asset1.content)

        asset_content = " body  { background-color: red; } "
        with self.app.test_request_context():
            self.assertEqual(asset_content, self.asset2.content)

    def test_bundle_content(self):
        bundle_content = "p{background-color:blue}body{background-color:blue}"
        with self.app.test_request_context():
            self.assertEqual(bundle_content, self.bundle.get_content())