def test_dont_cdn_absolute_url_rewrite_when_off(self):
     '''No re-writing if CDN is off'''
     a_test_config = test_config.copy()
     a_test_config["USE_CDN"] = False
     pybald.configure(config_object=a_test_config)
     asset_url = AssetUrl(my_static_resource_explicit)
     self.assertEqual(str(asset_url), str(my_static_resource_explicit))
Exemple #2
0
def add_js(filename):
    '''Add a script tag to a template.

    This helper function is also config aware and will re-write asset urls
    based on CDN and other rules.'''
    return HTMLLiteral('''<script src="{0}"></script>'''.format(
        AssetUrl(compute_asset_tag(filename))))
 def test_dont_cdn_url_rewrite_for_unowned_link(self):
     '''Don't rewrite links on hosts we don't own'''
     request_config().protocol = "https"
     a_test_config = test_config.copy()
     a_test_config["USE_CDN"] = True
     pybald.configure(a_test_config)
     asset_url = AssetUrl(not_owned_static_resource)
     self.assertEqual(str(asset_url), str(not_owned_static_resource))
Exemple #4
0
def add_css(filename, media="screen"):
    '''Add a link/css tag to a template.

    This helper function is also config aware and will re-write asset urls
    based on CDN and other rules.'''
    return HTMLLiteral(
        '''<link type="text/css" href="{0}" media="{1}" rel="stylesheet">'''.
        format(AssetUrl(compute_asset_tag(filename)), str(media)))
 def test_default_protocol(self):
     '''Test that the CDN rewrite is smart enough to use the raw CDN if
     https and we don't have https certs for static hosts.'''
     a_test_config = test_config.copy()
     a_test_config["USE_CDN"] = True
     pybald.configure(config_object=a_test_config)
     asset_url = AssetUrl(my_static_resource)
     self.assertEqual(str(asset_url),
                      'https://awesomecdn.com/static_stuff.js')
 def test_cdn_absolute_url_rewrite_http(self):
     '''Test that an absolute link gets changed to a CDN link'''
     request_config().protocol = "http"
     a_test_config = test_config.copy()
     a_test_config["USE_CDN"] = True
     pybald.configure(config_object=a_test_config)
     asset_url = AssetUrl(my_static_resource_explicit)
     self.assertEqual(str(asset_url),
                      'http://s0.sample.com/static_stuff.js')