Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / test / test_finger.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.protocols.finger}.
6 """
7
8 from twisted.trial import unittest
9 from twisted.protocols import finger
10 from twisted.test.proto_helpers import StringTransport
11
12
13 class FingerTestCase(unittest.TestCase):
14     """
15     Tests for L{finger.Finger}.
16     """
17     def setUp(self):
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")