def test_uriToPath(self): # uriToPath only supports our own URLs with certain schemes. uri = URI(config.codehosting.git_anon_root) uri.path = "/~foo/bar/baz" # Test valid schemes. for scheme in ("git", "git+ssh", "https", "ssh"): uri.scheme = scheme self.assertEqual("~foo/bar/baz", self.lookup.uriToPath(uri)) # Test an invalid scheme. uri.scheme = "ftp" self.assertIsNone(self.lookup.uriToPath(uri)) # Test valid scheme but invalid domain. uri.scheme = 'sftp' uri.host = 'example.com' self.assertIsNone(self.lookup.uriToPath(uri))
def test_uriToHostingPath(self): """Ensure uriToHostingPath works. Only codehosting-based using http, sftp or bzr+ssh URLs will be handled. If any other URL gets passed (including lp), the return value will be None. """ branch_set = getUtility(IBranchLookup) uri = URI(config.codehosting.supermirror_root) uri.path = '/~foo/bar/baz' # Test valid schemes uri.scheme = 'http' self.assertEqual('~foo/bar/baz', branch_set.uriToHostingPath(uri)) uri.scheme = 'sftp' self.assertEqual('~foo/bar/baz', branch_set.uriToHostingPath(uri)) uri.scheme = 'bzr+ssh' self.assertEqual('~foo/bar/baz', branch_set.uriToHostingPath(uri)) # Test invalid scheme uri.scheme = 'ftp' self.assertIs(None, branch_set.uriToHostingPath(uri)) # Test valid scheme, invalid domain uri.scheme = 'sftp' uri.host = 'example.com' self.assertIs(None, branch_set.uriToHostingPath(uri))