Exemplo n.º 1
0
class TestDirHandler(unittest.TestCase):
    def setUp(self):
        self.config = testutil.get_config()
        self.vfs = VFS_Real(self.config)
        self.selector = "/"
        self.protocol = testutil.get_testing_protocol(self.selector,
                                                      config=self.config)
        self.stat_result = self.vfs.stat(self.selector)

        # Make sure there's no directory cache file from a previous test run
        cachefile = self.config.get("handlers.dir.DirHandler", "cachefile")
        try:
            os.remove(self.vfs.getfspath(self.selector) + "/" + cachefile)
        except OSError:
            pass

    def test_dir_handler(self):
        handler = DirHandler(self.selector, "", self.protocol, self.config,
                             self.stat_result, self.vfs)

        self.assertTrue(handler.canhandlerequest())
        self.assertTrue(handler.isdir())

        handler.prepare()
        self.assertFalse(handler.fromcache)

        entry = handler.getentry()
        self.assertEqual(entry.mimetype, "application/gopher-menu")
        self.assertEqual(entry.type, "1")

        entries = handler.getdirlist()
        self.assertTrue(entries)

        # Create a second handler to test that it will load from the cached
        # file that the first handler should have created
        handler = DirHandler(self.selector, "", self.protocol, self.config,
                             self.stat_result, self.vfs)

        handler.prepare()
        self.assertTrue(handler.fromcache)

        cached_entries = handler.getdirlist()
        for a, b in zip(entries, cached_entries):
            self.assertEqual(a.selector, b.selector)
Exemplo n.º 2
0
class TestUMNDirHandler(unittest.TestCase):
    def setUp(self):
        self.config = testutil.get_config()
        self.vfs = VFS_Real(self.config)
        self.selector = "/"
        self.protocol = testutil.get_testing_protocol(self.selector,
                                                      config=self.config)
        self.stat_result = self.vfs.stat(self.selector)

        # Make sure there's no directory cache file from a previous test run
        cachefile = self.config.get("handlers.dir.DirHandler", "cachefile")
        try:
            os.remove(self.vfs.getfspath(self.selector) + "/" + cachefile)
        except OSError:
            pass

    def test_dir_handler(self):
        handler = UMNDirHandler(self.selector, "", self.protocol, self.config,
                                self.stat_result, self.vfs)

        self.assertTrue(handler.canhandlerequest())
        self.assertTrue(handler.isdir())

        handler.prepare()
        self.assertFalse(handler.fromcache)

        entry = handler.getentry()
        self.assertEqual(entry.mimetype, "application/gopher-menu")
        self.assertEqual(entry.type, "1")

        entries = handler.getdirlist()
        self.assertTrue(entries)

        # First entry should be the special link file
        self.assertEqual(entries[0].name, "Cheese Ball Recipes")
        self.assertEqual(entries[0].host, "zippy.micro.umn.edu")
        self.assertEqual(entries[0].port, 150)

        # Second entry should be the special cap file
        self.assertEqual(entries[2].name, "New Long Cool Name")
        self.assertEqual(entries[2].selector, "/zzz.txt")