class BaseRegistryTestCase(unittest.TestCase):
    def __init__(self):
        unittest.TestCase.__init__(self)
        self.registry = BaseRegistryTool()

    # Make sure we don't generate an id that could screw up traversal to
    # the cached resource.
    def testGenerateId(self):
        self.failIf('++' in self.registry.generateId(
            Resource('++resource++foobar.css')))
        self.failIf('/' in self.registry.generateId(
            Resource('++resource++foo/bar.css')))
    
    #Resources with double //'s in them aren't traversable. The page templates
    # assume that no resource will have a '/' at the start or end, and won't
    # have a '//' anywhere inside. A single '/' inside is fine.
    def testTraversableResourceID(self):
        ids = {'/bar.res': False, #expected to fail
               'bar.res' : True,  #expected to pass
               'bar.//res' : False, #expected to fail
               'bar.res/' : False, #expected to fail
               'foo/bar.res' : True, #perfectly fine
               'http://example.com/example.res' : True, #This should work now
               }
        for id in ids:
            if ids[id]: #This shouldn't error
                Resource(id)
            else: #This should throw a ValueError
                self.failUnlessRaises(ValueError,Resource,id)
                self.assertRaises(ValueError,Resource,id)

    def runTest(self):
        self.testGenerateId()
        self.testTraversableResourceID()
class BaseRegistryTestCase(unittest.TestCase):
    def __init__(self):
        unittest.TestCase.__init__(self)
        self.registry = BaseRegistryTool()

    # Make sure we don't generate an id that could screw up traversal to
    # the cached resource.
    def testGenerateId(self):
        self.failIf('++' in self.registry.generateId(
            Resource('++resource++foobar.css')))
        self.failIf('/' in self.registry.generateId(
            Resource('++resource++foo/bar.css')))

    #Resources with double //'s in them aren't traversable. The page templates
    # assume that no resource will have a '/' at the start or end, and won't
    # have a '//' anywhere inside. A single '/' inside is fine.
    def testTraversableResourceID(self):
        ids = {
            '/bar.res': False,  #expected to fail
            'bar.res': True,  #expected to pass
            'bar.//res': False,  #expected to fail
            'bar.res/': False,  #expected to fail
            'foo/bar.res': True,  #perfectly fine
            'http://example.com/example.res': True,  #This should work now
        }
        for id in ids:
            if ids[id]:  #This shouldn't error
                Resource(id)
            else:  #This should throw a ValueError
                self.failUnlessRaises(ValueError, Resource, id)
                self.assertRaises(ValueError, Resource, id)

    def runTest(self):
        self.testGenerateId()
        self.testTraversableResourceID()
Example #3
0
class BaseRegistryTestCase(unittest.TestCase):
    def __init__(self):
        unittest.TestCase.__init__(self)
        self.registry = BaseRegistryTool()

    # Make sure we don't generate an id that could screw up traversal to
    # the cached resource.
    def testGenerateId(self):
        self.failIf("++" in self.registry.generateId("++resource++foobar.css"))
        self.failIf("/" in self.registry.generateId("++resource++foo/bar.css"))

    def runTest(self):
        self.testGenerateId()
Example #4
0
 def getResourceContent(self, item, context, original=False):
     output = BaseRegistryTool.getResourceContent(self, item, context, original)
     if not original:
         mapper = JavascriptKeywordMapper()
         regexp = re.compile(r"/\* sTART eNCODE \*/\s*(.*?)\s*/\* eND eNCODE \*/", re.DOTALL)
         matches = regexp.findall(output)
         if len(matches) > 0:
             mapper.analyse("\n".join(matches))
             decoder = mapper.getDecodeFunction(name='__dEcOdE')
             def repl(m):
                 return mapper.getDecoder(mapper.sub(m.group(1)),
                                          keyword_var="''",
                                          decode_func='__dEcOdE')
             #output = "\n__sTaRtTiMe = new Date()\n%s\n%s\nalert(new Date() - __sTaRtTiMe);" % (decoder,
             output = "\n%s\n%s\n" % (decoder,
                                      regexp.sub(repl, output))
     return output
 def getResourceContent(self, item, context, original=False, theme=None):
     output = BaseRegistryTool.getResourceContent(self, item, context, original, theme)
     if not original:
         mapper = JavascriptKeywordMapper()
         regexp = re.compile(r"/\* sTART eNCODE \*/\s*(.*?)\s*/\* eND eNCODE \*/", re.DOTALL)
         matches = regexp.findall(output)
         if len(matches) > 0:
             mapper.analyse("\n".join(matches))
             decoder = mapper.getDecodeFunction(name='__dEcOdE')
             def repl(m):
                 return mapper.getDecoder(mapper.sub(m.group(1)),
                                          keyword_var="''",
                                          decode_func='__dEcOdE')
             #output = "\n__sTaRtTiMe = new Date()\n%s\n%s\nalert(new Date() - __sTaRtTiMe);" % (decoder,
             output = "\n%s\n%s\n" % (decoder,
                                      regexp.sub(repl, output))
     return output
Example #6
0
 def __init__(self):
     unittest.TestCase.__init__(self)
     self.registry = BaseRegistryTool()
 def __init__(self):
     unittest.TestCase.__init__(self)
     self.registry = BaseRegistryTool()