Ejemplo n.º 1
0
    def test_ssh_handler_writes_a_file(self):
        class StubbedSFTPClient(StubbedGetter):
            def get(self, remote_path, local_path):
                with open(local_path, "w") as writer:
                    with open(remote_path, "r") as reader:
                        writer.write(reader.read())

        expected_path = "/tmp/fake_file"
        remote_path = "sftp://localhost/%s" % test.do_test_file("config.gem")
        url = urlparse.urlparse(remote_path)

        sftp_handler = handlers.SFTPHandler(url, expected_path)
        guaranteed_file = sftp_handler.handle(getter=StubbedSFTPClient)
        self.assertTrue(os.path.isfile(guaranteed_file))
        os.unlink(guaranteed_file)
Ejemplo n.º 2
0
 def test_ssh_handler_raises_on_bad_netloc(self):
     url = urlparse.urlparse("sftp://doesntexist/path/to/file")
     sftp_handler = handlers.SFTPHandler(url, '')
     self.assertRaises(handlers.HandlerError, sftp_handler.handle)
Ejemplo n.º 3
0
 def test_ssh_handler_raises_on_bad_credentials(self):
     url = urlparse.urlparse(
         "sftp://*****:*****@localhost:22/path/to/file")
     sftp_handler = handlers.SFTPHandler(url, '')
     self.assertRaises(handlers.HandlerError, sftp_handler.handle)