test_address.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{SSHTransportAddrress} in ssh/address.py
  5. """
  6. from __future__ import division, absolute_import
  7. from twisted.trial import unittest
  8. from twisted.internet.address import IPv4Address
  9. from twisted.internet.test.test_address import AddressTestCaseMixin
  10. from twisted.conch.ssh.address import SSHTransportAddress
  11. class SSHTransportAddressTests(unittest.TestCase, AddressTestCaseMixin):
  12. """
  13. L{twisted.conch.ssh.address.SSHTransportAddress} is what Conch transports
  14. use to represent the other side of the SSH connection. This tests the
  15. basic functionality of that class (string representation, comparison, &c).
  16. """
  17. def _stringRepresentation(self, stringFunction):
  18. """
  19. The string representation of C{SSHTransportAddress} should be
  20. "SSHTransportAddress(<stringFunction on address>)".
  21. """
  22. addr = self.buildAddress()
  23. stringValue = stringFunction(addr)
  24. addressValue = stringFunction(addr.address)
  25. self.assertEqual(stringValue,
  26. "SSHTransportAddress(%s)" % addressValue)
  27. def buildAddress(self):
  28. """
  29. Create an arbitrary new C{SSHTransportAddress}. A new instance is
  30. created for each call, but always for the same address.
  31. """
  32. return SSHTransportAddress(IPv4Address("TCP", "127.0.0.1", 22))
  33. def buildDifferentAddress(self):
  34. """
  35. Like C{buildAddress}, but with a different fixed address.
  36. """
  37. return SSHTransportAddress(IPv4Address("TCP", "127.0.0.2", 22))