def test_relativeUnmodified(self): """ L{StylesheetRewritingRequestWrapper._replace} does not change URLs with relative paths. """ wrapper = website.StylesheetRewritingRequestWrapper(object(), [], None) self.assertEqual(wrapper._replace('relative/path'), 'relative/path')
def test_finish(self): """ L{StylesheetRewritingRequestWrapper.finish} causes all written bytes to be translated with C{_replace} written to the wrapped request. """ stylesheetFormat = """ .foo { background-image: url(%s) } """ originalStylesheet = stylesheetFormat % ("/Foo/bar", ) expectedStylesheet = stylesheetFormat % ("/bar/Foo/bar", ) request = FakeRequest() roots = {request: URL.fromString('/bar/')} wrapper = website.StylesheetRewritingRequestWrapper( request, [], roots.get) wrapper.write(originalStylesheet) wrapper.finish() # Parse and serialize both versions to normalize whitespace so we can # make a comparison. parser = CSSParser() self.assertEqual( parser.parseString(request.accumulator).cssText, parser.parseString(expectedStylesheet).cssText)
def test_absoluteURL(self): """ L{StylesheetRewritingRequestWrapper._replace} does not change absolute URLs. """ wrapper = website.StylesheetRewritingRequestWrapper(object(), [], None) self.assertEqual(wrapper._replace('http://example.com/foo'), 'http://example.com/foo')
def test_shortURL(self): """ L{StylesheetRewritingRequestWrapper._replace} changes URLs with only one segment so they are beneath the root URL. """ request = object() roots = {request: URL.fromString('/bar/')} wrapper = website.StylesheetRewritingRequestWrapper( request, [], roots.get) self.assertEqual(wrapper._replace('/'), '/bar/')
def test_replaceMantissa(self): """ L{StylesheetRewritingRequestWrapper._replace} changes URLs of the form I{/Mantissa/foo} to I{<rootURL>/static/mantissa-base/foo}. """ request = object() roots = {request: URL.fromString('/bar/')} wrapper = website.StylesheetRewritingRequestWrapper( request, [], roots.get) self.assertEqual(wrapper._replace('/Mantissa/foo.png'), '/bar/static/mantissa-base/foo.png')
def test_nonOfferingOnlyGivenPrefix(self): """ L{StylesheetRewritingRequestWrapper._replace} only changes URLs of the form I{/Something/foo} so they are beneath the root URL if C{Something} does not give the name of an installed offering. """ request = object() roots = {request: URL.fromString('/bar/')} wrapper = website.StylesheetRewritingRequestWrapper( request, ['Foo'], roots.get) self.assertEqual(wrapper._replace('/OfferingName/foo.png'), '/bar/OfferingName/foo.png')
def test_replaceOtherOffering(self): """ L{StylesheetRewritingRequestWrapper._replace} changes URLs of the form I{/Something/foo} to I{<rootURL>/static/Something/foo} if C{Something} gives the name of an installed offering with a static content path. """ request = object() roots = {request: URL.fromString('/bar/')} wrapper = website.StylesheetRewritingRequestWrapper( request, ['OfferingName'], roots.get) self.assertEqual(wrapper._replace('/OfferingName/foo.png'), '/bar/static/OfferingName/foo.png')