class StaticFilesTest(SeecrTestCase):
    def setUp(self):
        SeecrTestCase.setUp(self)
        with open(join(self.tempdir, 'data.txt'), 'w') as f:
            f.write('DATA')
        self.sf = StaticFiles(libdir=self.tempdir, path='/jquery')

    def testPath(self):
        self.assertEqual('/jquery/', self.sf.path)

    def testData(self):
        headers, body = parseResponse(
            asString(self.sf.handleRequest(path='/jquery/data.txt')))
        self.assertEqual('200', headers['StatusCode'])
        self.assertEqual('text/plain', headers['Headers']['Content-Type'])
        self.assertEqual('DATA', body)

    def testDoesNotExist(self):
        headers, body = parseResponse(
            asString(self.sf.handleRequest(path='/jquery/no')))
        self.assertEqual('404', headers['StatusCode'])

    def testNotMyPath(self):
        self.assertEqual('', asString(self.sf.handleRequest(path='/other')))

    def testIndex(self):
        sf = StaticFiles(libdir=self.tempdir,
                         path='/path',
                         allowDirectoryListing=True)
        headers, body = parseResponse(asString(
            sf.handleRequest(path='/path/')))
        self.assertTrue('<a href="data.txt"' in body, body)
class StaticFilesTest(SeecrTestCase):
    def setUp(self):
        SeecrTestCase.setUp(self)
        with open(join(self.tempdir, 'data.txt'), 'w') as f:
            f.write('DATA')
        self.sf = StaticFiles(libdir=self.tempdir, path='/jquery')

    def testPath(self):
        self.assertEqual('/jquery/', self.sf.path)

    def testData(self):
        headers, body = parseResponse(asString(self.sf.handleRequest(path='/jquery/data.txt')))
        self.assertEqual('200', headers['StatusCode'])
        self.assertEqual('text/plain', headers['Headers']['Content-Type'])
        self.assertEqual('DATA', body)

    def testDoesNotExist(self):
        headers, body = parseResponse(asString(self.sf.handleRequest(path='/jquery/no')))
        self.assertEqual('404', headers['StatusCode'])

    def testNotMyPath(self):
        self.assertEqual('', asString(self.sf.handleRequest(path='/other')))

    def testIndex(self):
        sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True)
        headers, body = parseResponse(asString(sf.handleRequest(path='/path/')))
        self.assertTrue('<a href="data.txt"' in body, body)
Exemple #3
0
class StaticFilesTest(SeecrTestCase):
    def setUp(self):
        SeecrTestCase.setUp(self)
        with open(join(self.tempdir, 'data.txt'), 'w') as f:
            f.write('DATA')
        self.sf = StaticFiles(libdir=self.tempdir, path='/jquery')

    def testPath(self):
        self.assertEqual('/jquery/', self.sf.path)

    def testData(self):
        headers, body = parseResponse(asBytes(self.sf.handleRequest(path='/jquery/data.txt')))
        self.assertEqual('200', headers['StatusCode'])
        self.assertEqual('text/plain', headers['Headers']['Content-Type'])
        self.assertEqual(b'DATA', body)

    def testDoesNotExist(self):
        headers, body = parseResponse(asBytes(self.sf.handleRequest(path='/jquery/no')))
        self.assertEqual('404', headers['StatusCode'])

    def testNotMyPath(self):
        self.assertEqual(b'', asBytes(self.sf.handleRequest(path='/other')))

    def testIndex(self):
        sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True)
        headers, body = parseResponse(asBytes(sf.handleRequest(path='/path/')))
        self.assertTrue(b'<a href="data.txt"' in body, body)

    def testPrefix(self):
        fullLibDir = join(self.tempdir, 'library-3.4.5')
        makedirs(fullLibDir)
        self.assertEqual(fullLibDir, libdirForPrefix(self.tempdir, 'library-3'))
        self.assertEqual(fullLibDir, libdirForPrefix(self.tempdir, 'libra'))
        self.assertRaises(ValueError, lambda: libdirForPrefix(self.tempdir, 'doesnotexist'))
        makedirs(join(self.tempdir, 'prefix-same-1'))
        makedirs(join(self.tempdir, 'prefix-same-2'))
        self.assertRaises(ValueError, lambda: libdirForPrefix(self.tempdir, 'prefix-same-'))

    def testPrefixStaticFiles(self):
        fullLibDir = join(self.tempdir, 'library-3.4.5')
        makedirs(fullLibDir)
        with open(join(fullLibDir, 'data.txt'), 'w') as f:
            f.write('DATA')
        prefixDir = join(self.tempdir, 'librar*')

        sf = StaticFiles(libdir=prefixDir, path='/jquery')

        headers, body = parseResponse(asBytes(sf.handleRequest(path='/jquery/data.txt')))
        self.assertEqual('200', headers['StatusCode'])
        self.assertEqual('text/plain', headers['Headers']['Content-Type'])
        self.assertEqual(b'DATA', body)
 def testIndex(self):
     sf = StaticFiles(libdir=self.tempdir,
                      path='/path',
                      allowDirectoryListing=True)
     headers, body = parseResponse(asString(
         sf.handleRequest(path='/path/')))
     self.assertTrue('<a href="data.txt"' in body, body)
Exemple #5
0
    def testPrefixStaticFiles(self):
        fullLibDir = join(self.tempdir, 'library-3.4.5')
        makedirs(fullLibDir)
        with open(join(fullLibDir, 'data.txt'), 'w') as f:
            f.write('DATA')
        prefixDir = join(self.tempdir, 'librar*')

        sf = StaticFiles(libdir=prefixDir, path='/jquery')

        headers, body = parseResponse(asBytes(sf.handleRequest(path='/jquery/data.txt')))
        self.assertEqual('200', headers['StatusCode'])
        self.assertEqual('text/plain', headers['Headers']['Content-Type'])
        self.assertEqual(b'DATA', body)
 def testIndex(self):
     sf = StaticFiles(libdir=self.tempdir, path='/path', allowDirectoryListing=True)
     headers, body = parseResponse(asString(sf.handleRequest(path='/path/')))
     self.assertTrue('<a href="data.txt"' in body, body)