test_finger.py 2.0 KB

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