Example #1
0
 def test_encoding_fail(self):
     from staticcomp.compressor import JsPayload
     payload = JsPayload(['js/a123.js', 'js/bcccc.js', 'js/foo/bar.js'], 'base')
     try:
         payload.encode()
     except OSError:
         # this is expected as these files shouldn't exist
         pass
     else:
         self.fail("The JsPayload encoder should have failed.")
Example #2
0
 def test_code_random_js(self):
     import os
     js_files = set()
     min_re = re.compile(r'\.min\.')
     media_root = os.path.normpath(settings.MEDIA_ROOT)
     is_js = lambda f: bool(os.path.splitext(f)[-1] == '.js' and not min_re.search(f))
     def w(fileset, dirname, names):
         if len(fileset) < 3:
             js_files = filter(is_js, names)
             if js_files:
                 map(fileset.add, [ os.path.join(dirname, f)[len(media_root)+1:] for f in js_files])
             
     os.path.walk(settings.MEDIA_ROOT, w, js_files)
     if js_files:
         # encoding random set of js two files
         from staticcomp.compressor import JsPayload
         payload = JsPayload(list(js_files), 'random')
         b64, hash = payload.encode()
Example #3
0
 def inner(request, group, b64_js, hash, *args, **kwargs):
     status_code = 200
     try:
         payload = JsPayload.decode(group=group, b64_code=b64_js, hash=hash)
         js_data = f(request, payload, *args, **kwargs)
     except:
         if not settings.DEBUG:
             from StringIO import StringIO
             import traceback
             buf = StringIO()
             traceback.print_exc(file=buf)
             # write out error to database for non-debug requests
             StaticCompError.log_error(request, buf.getvalue())                
             js_data = "/* Invalid Request */"
             status_code = 500
         else:
             raise
     return HttpResponse(js_data, mimetype="application/javascript", status=status_code)
Example #4
0
 def test_url_encoding(self):
     from staticcomp.compressor import JsPayload
     sig = JsPayload.signature(self.fake_files, self.fake_group, self.mod_time)
     b64_url = JsPayload.url_encode(self.fake_files, self.mod_time)
     self.assertEquals(b64_url, 'anMvYS5qcyxqcy9iLmpzLDEyOTY5NDk3MjU=')
Example #5
0
 def test_signature(self):
     from staticcomp.compressor import JsPayload
     sig = JsPayload.signature(self.fake_files, self.fake_group, self.mod_time)
     self.assertEqual(sig, 'fceba194a9faf706f8abe35ba5a10d746be0244e09681da0abcb5407e1ca44e9')