Ejemplo n.º 1
0
 def setUp(self):
     """
     Set up the store, a temporary test dir and a theme for the tests.
     """
     self.store = Store()
     self.testDir = FilePath(self.mktemp())
     self.testDir.makedirs()
     self.theme = XHTMLDirectoryTheme('testtheme',
                                      directoryName=self.testDir.path)
Ejemplo n.º 2
0
 def setUp(self):
     """
     Set up the store, a temporary test dir and a theme for the tests.
     """
     self.store = Store()
     self.testDir = FilePath(self.mktemp())
     self.testDir.makedirs()
     self.theme = XHTMLDirectoryTheme(
         'testtheme',
         directoryName=self.testDir.path)
Ejemplo n.º 3
0
class XHTMLDirectoryThemeTests(TestCase):
    """
    Tests for L{XHTMLDirectoryTheme}.
    """
    def setUp(self):
        """
        Set up the store, a temporary test dir and a theme for the tests.
        """
        self.store = Store()
        self.testDir = FilePath(self.mktemp())
        self.testDir.makedirs()
        self.theme = XHTMLDirectoryTheme(
            'testtheme',
            directoryName=self.testDir.path)


    def test_directoryAttribute(self):
        """
        L{XHTMLDirectoryTheme} should have a directory attribute of type
        L{twisted.python.filepath.FilePath}.
        """
        self.assertEqual(self.theme.directory, self.testDir)
        self.assertEqual(self.theme.directory.path, self.theme.directoryName)


    def test_childFragmentsInGetDocFactory(self):
        """
        L{XHTMLDirectoryTheme.getDocFactory} should handle subdirectories
        sanely, without exposing parent directories.
        """
        fragmentName = 'dir/file'
        child = self.testDir.child('dir')
        child.makedirs()
        child.child('file.html').touch()
        resolvedTemplate = self.theme.getDocFactory(fragmentName)
        foundPath = FilePath(resolvedTemplate.template)
        expectedPath = FilePath(
            "%s/%s.html" % (self.theme.directoryName, fragmentName))
        self.assertEqual(foundPath, expectedPath)
        self.assertRaises(InsecurePath, self.theme.getDocFactory,
                          '../insecure/')


    def test_noStylesheetLocation(self):
        """
        L{XHTMLDirectoryTheme.head} returns C{None} if I{stylesheetLocation} is
        C{None}.
        """
        self.assertIdentical(self.theme.head(None, None), None)


    def test_stylesheetLocation(self):
        """
        L{XHTMLDirectoryTheme.head} returns a link tag which gives the location
        of the stylesheet given by I{stylesheetLocation} if there is one.
        """
        siteStore = Store(filesdir=self.mktemp())
        Mantissa().installSite(siteStore, u"example.com", u"", False)
        site = ISiteURLGenerator(siteStore)

        self.theme.stylesheetLocation = ['foo', 'bar']
        request = FakeRequest()
        link = self.theme.head(request, site)
        self.assertEqual(link.tagName, 'link')
        self.assertEqual(link.attributes['rel'], 'stylesheet')
        self.assertEqual(link.attributes['type'], 'text/css')
        self.assertEqual(
            site.rootURL(request).child('foo').child('bar'),
            link.attributes['href'])
Ejemplo n.º 4
0
class XHTMLDirectoryThemeTests(TestCase):
    """
    Tests for L{XHTMLDirectoryTheme}.
    """
    def setUp(self):
        """
        Set up the store, a temporary test dir and a theme for the tests.
        """
        self.store = Store()
        self.testDir = FilePath(self.mktemp())
        self.testDir.makedirs()
        self.theme = XHTMLDirectoryTheme('testtheme',
                                         directoryName=self.testDir.path)

    def test_directoryAttribute(self):
        """
        L{XHTMLDirectoryTheme} should have a directory attribute of type
        L{twisted.python.filepath.FilePath}.
        """
        self.assertEqual(self.theme.directory, self.testDir)
        self.assertEqual(self.theme.directory.path, self.theme.directoryName)

    def test_childFragmentsInGetDocFactory(self):
        """
        L{XHTMLDirectoryTheme.getDocFactory} should handle subdirectories
        sanely, without exposing parent directories.
        """
        fragmentName = 'dir/file'
        child = self.testDir.child('dir')
        child.makedirs()
        child.child('file.html').touch()
        resolvedTemplate = self.theme.getDocFactory(fragmentName)
        foundPath = FilePath(resolvedTemplate.template)
        expectedPath = FilePath("%s/%s.html" %
                                (self.theme.directoryName, fragmentName))
        self.assertEqual(foundPath, expectedPath)
        self.assertRaises(InsecurePath, self.theme.getDocFactory,
                          '../insecure/')

    def test_noStylesheetLocation(self):
        """
        L{XHTMLDirectoryTheme.head} returns C{None} if I{stylesheetLocation} is
        C{None}.
        """
        self.assertIdentical(self.theme.head(None, None), None)

    def test_stylesheetLocation(self):
        """
        L{XHTMLDirectoryTheme.head} returns a link tag which gives the location
        of the stylesheet given by I{stylesheetLocation} if there is one.
        """
        siteStore = Store(filesdir=self.mktemp())
        Mantissa().installSite(siteStore, u"example.com", u"", False)
        site = ISiteURLGenerator(siteStore)

        self.theme.stylesheetLocation = ['foo', 'bar']
        request = FakeRequest()
        link = self.theme.head(request, site)
        self.assertEqual(link.tagName, 'link')
        self.assertEqual(link.attributes['rel'], 'stylesheet')
        self.assertEqual(link.attributes['type'], 'text/css')
        self.assertEqual(
            site.rootURL(request).child('foo').child('bar'),
            link.attributes['href'])