~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to twisted/test/test_finger.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
1
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
2
2
# See LICENSE for details.
3
3
 
 
4
"""
 
5
Tests for L{twisted.protocols.finger}.
 
6
"""
4
7
 
5
8
from twisted.trial import unittest
6
9
from twisted.protocols import finger
7
 
from twisted.internet import reactor, protocol
8
 
from twisted.test import test_protocols
 
10
from twisted.test.proto_helpers import StringTransport
 
11
 
9
12
 
10
13
class FingerTestCase(unittest.TestCase):
11
 
 
 
14
    """
 
15
    Tests for L{finger.Finger}.
 
16
    """
12
17
    def setUp(self):
13
 
        self.t = test_protocols.StringIOWithoutClosing()
14
 
        self.p = finger.Finger()
15
 
        self.p.makeConnection(protocol.FileWrapper(self.t))
16
 
 
17
 
    def testSimple(self):
18
 
        self.p.dataReceived("moshez\r\n")
19
 
        self.failUnlessEqual(self.t.getvalue(),
20
 
                             "Login: moshez\nNo such user\n")
21
 
 
22
 
    def testSimpleW(self):
23
 
        self.p.dataReceived("/w moshez\r\n")
24
 
        self.failUnlessEqual(self.t.getvalue(),
25
 
                             "Login: moshez\nNo such user\n")
26
 
 
27
 
    def testForwarding(self):
28
 
        self.p.dataReceived("moshez@example.com\r\n")
29
 
        self.failUnlessEqual(self.t.getvalue(),
30
 
                             "Finger forwarding service denied\n")
31
 
 
32
 
    def testList(self):
33
 
        self.p.dataReceived("\r\n")
34
 
        self.failUnlessEqual(self.t.getvalue(),
35
 
                             "Finger online list denied\n")
 
18
        """
 
19
        Create and connect a L{finger.Finger} instance.
 
20
        """
 
21
        self.transport = StringTransport()
 
22
        self.protocol = finger.Finger()
 
23
        self.protocol.makeConnection(self.transport)
 
24
 
 
25
 
 
26
    def test_simple(self):
 
27
        """
 
28
        When L{finger.Finger} receives a CR LF terminated line, it responds
 
29
        with the default user status message - that no such user exists.
 
30
        """
 
31
        self.protocol.dataReceived("moshez\r\n")
 
32
        self.assertEqual(
 
33
            self.transport.value(),
 
34
            "Login: moshez\nNo such user\n")
 
35
 
 
36
 
 
37
    def test_simpleW(self):
 
38
        """
 
39
        The behavior for a query which begins with C{"/w"} is the same as the
 
40
        behavior for one which does not.  The user is reported as not existing.
 
41
        """
 
42
        self.protocol.dataReceived("/w moshez\r\n")
 
43
        self.assertEqual(
 
44
            self.transport.value(),
 
45
            "Login: moshez\nNo such user\n")
 
46
 
 
47
 
 
48
    def test_forwarding(self):
 
49
        """
 
50
        When L{finger.Finger} receives a request for a remote user, it responds
 
51
        with a message rejecting the request.
 
52
        """
 
53
        self.protocol.dataReceived("moshez@example.com\r\n")
 
54
        self.assertEqual(
 
55
            self.transport.value(),
 
56
            "Finger forwarding service denied\n")
 
57
 
 
58
 
 
59
    def test_list(self):
 
60
        """
 
61
        When L{finger.Finger} receives a blank line, it responds with a message
 
62
        rejecting the request for all online users.
 
63
        """
 
64
        self.protocol.dataReceived("\r\n")
 
65
        self.assertEqual(
 
66
            self.transport.value(),
 
67
            "Finger online list denied\n")