File: test_script_exec.py

package info (click to toggle)
pygopherd 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,928 kB
  • sloc: python: 6,534; makefile: 40; sh: 28
file content (37 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import tempfile
import unittest

from pygopherd import testutil
from pygopherd.handlers.base import VFS_Real
from pygopherd.handlers.scriptexec import ExecHandler


class TestExecHandler(unittest.TestCase):
    def setUp(self):
        self.config = testutil.get_config()
        self.vfs = VFS_Real(self.config)
        # The "hello" will be sent as an additional script argument. Multiple
        # query arguments can be provided using " " as the separator.
        self.selector = "/pygopherd/cgitest.sh?hello"
        self.protocol = testutil.get_testing_protocol(self.selector, config=self.config)
        self.stat_result = None

    def test_exec_handler(self):
        handler = ExecHandler(
            self.selector, "", self.protocol, self.config, self.stat_result, self.vfs
        )

        self.assertTrue(handler.isrequestforme())

        entry = handler.getentry()
        self.assertEqual(entry.mimetype, "text/plain")
        self.assertEqual(entry.type, "0")
        self.assertEqual(entry.name, "cgitest.sh")
        self.assertEqual(entry.selector, "/pygopherd/cgitest.sh")

        # The test script will print $REQUEST and exit
        with tempfile.TemporaryFile(mode="w+") as wfile:
            handler.write(wfile)
            wfile.seek(0)
            output = wfile.read()
            self.assertEqual(output, "hello from /pygopherd/cgitest.sh\n")