File: test_initialization.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 (57 lines) | stat: -rw-r--r-- 2,063 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
import mimetypes
import socketserver
import unittest

from pygopherd import fileext, initialization


class InitializationConfigTestCase(unittest.TestCase):
    def test_init_config(self):
        self.assertRaises(Exception, initialization.init_config, "/foo")
        # Load the standard config file.  It should be OK at least.
        config = initialization.init_config("conf/pygopherd.conf")
        assert not config.has_option(
            "pygopherd", "servername"
        ), "servername should be disabled by default"
        self.assertEqual(config.getint("pygopherd", "port"), 70, "Port should be 70")
        self.assertEqual(
            config.get("pygopherd", "servertype"),
            "ForkingTCPServer",
            "Servertype should be ForkingTCPServer",
        )
        assert config.getboolean(
            "pygopherd", "tracebacks"
        ), "Tracebacks should be enabled."


class InitializationGeneralTestCase(unittest.TestCase):
    def setUp(self):
        self.config = initialization.init_config("conf/pygopherd.conf")

    def test_init_logger(self):
        # FIXME Can't really test this.
        pass

    def test_init_mimetypes_except(self):
        self.config.set("pygopherd", "mimetypes", "/foo:/bar")
        self.assertRaises(Exception, initialization.init_mimetypes, self.config)

    def test_init_mimetypes(self):
        # Logger is required for this test.
        self.config.set("logger", "logmethod", "none")
        initialization.init_logger(self.config, "TESTING")
        initialization.init_mimetypes(self.config)
        self.assertEqual(mimetypes.types_map[".txt"], "text/plain")
        self.assertEqual(mimetypes.encodings_map[".bz2"], "bzip2")
        assert ".txt" in fileext.typemap["text/plain"]

    def test_get_server(self):
        self.config.set("pygopherd", "port", "22270")
        s = initialization.get_server(self.config)
        assert isinstance(s, socketserver.ForkingTCPServer)
        s.server_close()

    def test_init_security(self):
        # FIXME
        pass