| 1 | import io |
| 2 | import unittest |
| 3 | |
| 4 | from pygopherd import testutil |
| 5 | from pygopherd.handlers.base import VFS_Real |
| 6 | from pygopherd.handlers.pyg import PYGHandler |
| 7 | |
| 8 | |
| 9 | class TestPYGHandler(unittest.TestCase): |
| 10 | def setUp(self): |
| 11 | self.config = testutil.get_config() |
| 12 | self.vfs = VFS_Real(self.config) |
| 13 | self.selector = "/testfile.pyg" |
| 14 | self.protocol = testutil.get_testing_protocol(self.selector, config=self.config) |
| 15 | self.stat_result = self.vfs.stat("/testfile.pyg") |
| 16 | |
| 17 | def test_pyg_handler(self): |
| 18 | handler = PYGHandler( |
| 19 | self.selector, "", self.protocol, self.config, self.stat_result, self.vfs |
| 20 | ) |
| 21 | |
| 22 | self.assertTrue(handler.canhandlerequest()) |
| 23 | self.assertFalse(handler.isdir()) |
| 24 | |
| 25 | entry = handler.getentry() |
| 26 | self.assertEqual(entry.selector, "/testfile.pyg") |
| 27 | |
| 28 | wfile = io.BytesIO() |
| 29 | handler.write(wfile) |
| 30 | self.assertEqual(wfile.getvalue(), b"hello world!") |