def test_put_use_sudo_temp_dir(self): """ put(use_sudo=True, temp_dir='/tmp/') works by uploading a file to /tmp/ and then moving it to a `remote_path` """ # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>) fake_run = Fake( '_run_command', callable=True, expect_call=True ).with_matching_args( 'mv "/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56" "/foobar.txt"', True, True, None, ) fake_put = Fake('put', callable=True, expect_call=True).with_args( fudge_arg.any_value(), '/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56') local_path = self.mkfile('foobar.txt', "baz") with hide('everything'): with patched_context('fabric.operations', '_run_command', fake_run): with patched_context(SFTPClient, 'put', fake_put): retval = put(local_path, "/", use_sudo=True, temp_dir='/tmp/') # check that the downloaded file has the same name as the one requested assert retval[0].endswith('foobar.txt')
def test_put_use_sudo_temp_dir(self): """ put(use_sudo=True, temp_dir='/tmp/') works by uploading a file to /tmp/ and then moving it to a `remote_path` """ # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>) fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args( 'mv "/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56" "/foobar.txt"', True, True, None, ) fake_put = Fake('put', callable=True, expect_call=True).with_args(fudge_arg.any_value(), '/tmp/7c91837ec0b3570264a325df6b7ef949ee22bc56') local_path = self.mkfile('foobar.txt', "baz") with hide('everything'): with patched_context('fabric.operations', '_run_command', fake_run): with patched_context(SFTPClient, 'put', fake_put): retval = put(local_path, "/", use_sudo=True, temp_dir='/tmp/') # check that the downloaded file has the same name as the one requested assert retval[0].endswith('foobar.txt')
def test_get_use_sudo_temp_dir(self): """ get(use_sudo=True, temp_dir="/tmp") works by copying to a /tmp/sha1_hash, downloading it and then removing it at the end """ # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>) name = "229a29e5693876645e39de0cb0532e43ad73311a" fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args( 'cp -p "/etc/apache2/apache2.conf" "/tmp/%s"' % name, True, True, None, ).next_call().with_matching_args( 'chown username "/tmp/%s"' % name, True, True, None, ).next_call().with_matching_args( 'chmod 400 "/tmp/%s"' % name, True, True, None, ).next_call().with_matching_args( 'rm -f "/tmp/%s"' % name, True, True, None, ) fake_get = Fake('get', callable=True, expect_call=True).with_args('/tmp/%s' % name, fudge_arg.any_value()) with hide('everything'): with patched_context('fabric.operations', '_run_command', fake_run): with patched_context(SFTPClient, 'get', fake_get): retval = get('/etc/apache2/apache2.conf', self.path(), use_sudo=True, temp_dir="/tmp") # check that the downloaded file has the same name as the one requested assert retval[0].endswith('apache2.conf')
def test_get_use_sudo_temp_dir(self): """ get(use_sudo=True, temp_dir="/tmp") works by copying to a /tmp/sha1_hash, downloading it and then removing it at the end """ # the sha1 hash is the unique filename of the file being downloaded. sha1(<filename>) name = "229a29e5693876645e39de0cb0532e43ad73311a" fake_run = Fake('_run_command', callable=True, expect_call=True).with_matching_args( 'cp -p "/etc/apache2/apache2.conf" "/tmp/%s"' % name, True, True, None, ).next_call().with_matching_args( 'chown username "/tmp/%s"' % name, True, True, None, ).next_call().with_matching_args( 'chmod 400 "/tmp/%s"' % name, True, True, None, ).next_call().with_matching_args( 'rm -f "/tmp/%s"' % name, True, True, None, ) fake_get = Fake('get', callable=True, expect_call=True).with_args( '/tmp/%s' % name, fudge_arg.any_value()) with hide('everything'): with patched_context('fabric.operations', '_run_command', fake_run): with patched_context(SFTPClient, 'get', fake_get): retval = get('/etc/apache2/apache2.conf', self.path(), use_sudo=True, temp_dir="/tmp") # check that the downloaded file has the same name as the one requested assert retval[0].endswith('apache2.conf')