/usr/lib/python2.7/dist-packages/pygopherd/protocols/baseTest.py is in pygopherd 2.0.18.3+nmu4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | import unittest
import pygopherd.handlers.file
from pygopherd import testutil
from StringIO import StringIO
from pygopherd.protocols.base import BaseGopherProtocol
class BaseProtocolTestCase(unittest.TestCase):
def setUp(self):
self.config = testutil.getconfig()
self.rfile = StringIO("/testfile.txt\n")
self.wfile = StringIO()
self.logfile = testutil.getstringlogger()
self.logstr = "10.77.77.77 [BaseGopherProtocol/FileHandler]: /testfile.txt\n"
self.handler = testutil.gettestinghandler(self.rfile, self.wfile,
self.config)
self.server = self.handler.server
self.proto = BaseGopherProtocol("/testfile.txt\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
def testInitBasic(self):
proto = BaseGopherProtocol("/foo.txt\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
assert proto.rfile == self.rfile
assert proto.wfile == self.wfile
assert proto.config == self.config
assert proto.requesthandler == self.handler
assert proto.requestlist == ['/foo.txt']
assert proto.searchrequest == None
assert proto.handler == None
assert proto.selector == '/foo.txt'
def testInitEmpty(self):
proto = BaseGopherProtocol("\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
# It should be rewritten to /
assert proto.selector == '/'
assert proto.requestlist == ['']
def testInitMissingLeadingSlash(self):
proto = BaseGopherProtocol("foo.txt\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
assert proto.selector == '/foo.txt'
assert proto.requestlist == ['foo.txt']
def testInitAddedTrailingSlash(self):
proto = BaseGopherProtocol("/dir/\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
assert proto.selector == '/dir'
assert proto.requestlist == ['/dir/']
def testInitBothSlashProblems(self):
proto = BaseGopherProtocol("dir/\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
assert proto.selector == '/dir'
assert proto.requestlist == ['dir/']
def testInitSplit(self):
proto = BaseGopherProtocol("foo.txt\t+\n", self.server, self.handler,
self.rfile, self.wfile, self.config)
assert proto.selector == '/foo.txt'
assert proto.requestlist == ['foo.txt', '+']
def testcanhandlerequest(self):
assert not self.proto.canhandlerequest()
def testlog(self):
# This is a file handler, not a request handler!
handler = self.proto.gethandler()
self.proto.log(handler)
self.assertEquals(self.logfile.getvalue(), self.logstr)
def testhandle_file(self):
self.proto.handle()
self.assertEquals(self.logfile.getvalue(), self.logstr)
self.assertEquals(self.wfile.getvalue(), "Test\n")
def testhandle_notfound(self):
proto = BaseGopherProtocol("/NONEXISTANT.txt\n", self.server,
self.handler, self.rfile, self.wfile,
self.config)
proto.handle()
self.assertEquals(self.logfile.getvalue(),
"10.77.77.77 [BaseGopherProtocol/None] EXCEPTION FileNotFound: '/NONEXISTANT.txt' does not exist (no handler found)\n")
self.assertEquals(self.wfile.getvalue(), "3'/NONEXISTANT.txt' does not exist (no handler found)\t\terror.host\t1\r\n")
# We cannot test handle_dir here because we don't have enough info.
def testfilenotfound(self):
self.proto.filenotfound("FOO")
self.assertEquals(self.wfile.getvalue(),
"3FOO\t\terror.host\t1\r\n")
def testgethandler(self):
handler = self.proto.gethandler()
assert isinstance(handler, pygopherd.handlers.file.FileHandler)
# Make sure caching works.
assert handler == self.proto.gethandler()
## CANNOT TEST: writedir, renderabstract
def testrenderdirstart(self):
assert self.proto.renderdirstart('foo') == None
def testrenderdirend(self):
assert self.proto.renderdirend('foo') == None
def testrenderobjinfo(self):
assert self.proto.renderobjinfo('foo') == None
def testgroksabstract(self):
assert not self.proto.groksabstract()
|