| 1 |
import tempfile |
| 2 |
import unittest |
| 3 |
|
| 4 |
from pygopherd import testutil |
| 5 |
from pygopherd.handlers.base import VFS_Real |
| 6 |
from pygopherd.handlers.scriptexec import ExecHandler |
| 7 |
|
| 8 |
|
| 9 |
class TestExecHandler(unittest.TestCase): |
| 10 |
def setUp(self): |
| 11 |
self.config = testutil.get_config() |
| 12 |
self.vfs = VFS_Real(self.config) |
| 13 |
|
| 14 |
|
| 15 |
self.selector = "/pygopherd/cgitest.sh?hello" |
| 16 |
self.protocol = testutil.get_testing_protocol(self.selector, config=self.config) |
| 17 |
self.stat_result = None |
| 18 |
|
| 19 |
def test_exec_handler(self): |
| 20 |
handler = ExecHandler( |
| 21 |
self.selector, "", self.protocol, self.config, self.stat_result, self.vfs |
| 22 |
) |
| 23 |
|
| 24 |
self.assertTrue(handler.isrequestforme()) |
| 25 |
|
| 26 |
entry = handler.getentry() |
| 27 |
self.assertEqual(entry.mimetype, "text/plain") |
| 28 |
self.assertEqual(entry.type, "0") |
| 29 |
self.assertEqual(entry.name, "cgitest.sh") |
| 30 |
self.assertEqual(entry.selector, "/pygopherd/cgitest.sh") |
| 31 |
|
| 32 |
|
| 33 |
with tempfile.TemporaryFile(mode="w+") as wfile: |
| 34 |
handler.write(wfile) |
| 35 |
wfile.seek(0) |
| 36 |
output = wfile.read() |
| 37 |
self.assertEqual(output, "hello from /pygopherd/cgitest.sh\n") |