def testFromString(self): for url, expected in urls: result = Url.from_string(url) error = 'URL: ' + url + '\n' error += 'Result: ' + str(result) + '\n' error += 'Expected: ' + expected self.assert_(isinstance(result, Url)) self.assert_(str(result) == expected, error)
def testToString(self): for url, expected in urls: result = Url.from_string(url) error = 'URL: ' + url + '\n' error += 'Result: ' + str(result) + '\n' error += 'Expected: ' + expected self.assertIsInstance(result, Url, error) self.assertEqual(result.to_string(), expected, error)
def testFromString(self): for url, expected in urls: result = Url.from_string(url) error = 'URL: ' + url + '\n' error += 'Result: ' + str(result) + '\n' error += 'Expected: ' + expected self.assertIsInstance(result, Url) self.assertTrue(str(result) == expected, error)
def testConstructor(self): host = Host('localhost') self.assertEqual(host.get_protocol(), 'telnet') host = Host('localhost', default_protocol = 'foo') self.assertEqual(host.get_protocol(), 'foo') for url, result in urls: host = Host(url) uri = Url.from_string(url) self.assertEqual(host.get_name(), uri.hostname) self.assertEqual(host.get_address(), uri.hostname) self.assertEqual(host.get_uri(), str(uri))
def testConstructor(self): host = Host('localhost') self.assertEqual(host.get_protocol(), 'telnet') host = Host('localhost', default_protocol='foo') self.assertEqual(host.get_protocol(), 'foo') for url, result in urls: host = Host(url) uri = Url.from_string(url) self.assertEqual(host.get_name(), uri.hostname) self.assertEqual(host.get_address(), uri.hostname) self.assertEqual(host.get_uri(), str(uri))
def set_uri(self, uri): """ Defines the protocol, hostname/address, TCP port number, username, and password from the given URL. The hostname may be URL formatted, so the following formats are all valid: - myhostname - myhostname.domain - ssh:hostname - ssh:hostname.domain - ssh://hostname - ssh://user@hostname - ssh://user:password@hostname - ssh://user:password@hostname:21 For a list of supported protocols please see set_protocol(). @type uri: string @param uri: An URL formatted hostname. """ try: uri = Url.from_string(uri, self.protocol) except ValueError: raise ValueError('Hostname parse error: ' + repr(uri)) hostname = uri.hostname or '' name = uri.path and hostname + uri.path or hostname self.set_protocol(uri.protocol) self.set_tcp_port(uri.port) self.set_name(name) self.set_address(name) if uri.username is not None \ or uri.password1 is not None \ or uri.password2: account = Account(uri.username, uri.password1, uri.password2) self.set_account(account) for key, val in uri.vars.iteritems(): self.set(key, val)
def testGetUri(self): for url, result in urls: host = Host(url) uri = Url.from_string(url) self.assertEqual(host.get_uri().split('&').sort(), str(uri).split('&').sort())
def testSetUri(self): for url, result in urls: self.host.set_uri(url) uri = Url.from_string(url) self.assertEqual(self.host.get_name(), uri.hostname) self.assertEqual(self.host.get_address(), uri.hostname)
def testGetUri(self): for url, result in urls: host = Host(url) uri = Url.from_string(url) self.assertEqual(host.get_uri(), str(uri))