예제 #1
0
 def test_get_single_file_absolutely(self):
     """
     get() a single file, using absolute file path
     """
     target = '/etc/apache2/apache2.conf'
     with hide('everything'):
         get(target, self.tmpdir)
     eq_contents(self.path(os.path.basename(target)), FILES[target])
예제 #2
0
 def test_get_single_file_in_folder(self):
     """
     get() a folder containing one file
     """
     remote = 'folder/file3.txt'
     with hide('everything'):
         get('folder', self.tmpdir)
     eq_contents(self.path(remote), FILES[remote])
예제 #3
0
 def test_get_single_file_in_folder(self):
     """
     get() a folder containing one file
     """
     remote = 'folder/file3.txt'
     with hide('everything'):
         get('folder', self.tmpdir)
     eq_contents(self.path(remote), FILES[remote])
예제 #4
0
 def test_get_single_file_absolutely(self):
     """
     get() a single file, using absolute file path
     """
     target = '/etc/apache2/apache2.conf'
     with hide('everything'):
         get(target, self.tmpdir)
     eq_contents(self.path(os.path.basename(target)), FILES[target])
예제 #5
0
 def test_get_tree(self):
     """
     Download entire tree
     """
     with hide('everything'):
         get('tree', self.tmpdir)
     leaves = filter(lambda x: x[0].startswith('/tree'), FILES.items())
     for path, contents in leaves:
         eq_contents(self.path(path[1:]), contents)
예제 #6
0
 def test_get_file_with_nonexistent_target(self):
     """
     Missing target path on single file download => effectively a rename
     """
     local = self.path('otherfile.txt')
     target = 'file.txt'
     with hide('everything'):
         get(target, local)
     eq_contents(local, FILES[target])
예제 #7
0
 def test_get_tree(self):
     """
     Download entire tree
     """
     with hide('everything'):
         get('tree', self.tmpdir)
     leaves = [x for x in list(FILES.items()) if x[0].startswith('/tree')]
     for path, contents in leaves:
         eq_contents(self.path(path[1:]), contents)
예제 #8
0
 def test_get_tree(self):
     """
     Download entire tree
     """
     with hide('everything'):
         get('tree', self.tmpdir)
     leaves = filter(lambda x: x[0].startswith('/tree'), FILES.items())
     for path, contents in leaves:
         eq_contents(self.path(path[1:]), contents)
예제 #9
0
 def test_get_sibling_globs(self):
     """
     get() with globbed files, but no directories
     """
     remotes = ['file.txt', 'file2.txt']
     with hide('everything'):
         get('file*.txt', self.tmpdir)
     for remote in remotes:
         eq_contents(self.path(remote), FILES[remote])
예제 #10
0
 def test_get_single_file(self):
     """
     get() with a single non-globbed filename
     """
     remote = 'file.txt'
     local = self.path(remote)
     with hide('everything'):
         get(remote, local)
     eq_contents(local, FILES[remote])
예제 #11
0
 def test_get_file_with_nonexistent_target(self):
     """
     Missing target path on single file download => effectively a rename
     """
     local = self.path('otherfile.txt')
     target = 'file.txt'
     with hide('everything'):
         get(target, local)
     eq_contents(local, FILES[target])
예제 #12
0
 def test_get_tree(self):
     """
     Download entire tree
     """
     with hide('everything'):
         get('tree', self.tmpdir)
     leaves = [x for x in list(FILES.items()) if x[0].startswith('/tree')]
     for path, contents in leaves:
         eq_contents(self.path(path[1:]), contents)
예제 #13
0
 def test_get_single_file(self):
     """
     get() with a single non-globbed filename
     """
     remote = 'file.txt'
     local = self.path(remote)
     with hide('everything'):
         get(remote, local)
     eq_contents(local, FILES[remote])
예제 #14
0
 def test_get_sibling_globs(self):
     """
     get() with globbed files, but no directories
     """
     remotes = ['file.txt', 'file2.txt']
     with hide('everything'):
         get('file*.txt', self.tmpdir)
     for remote in remotes:
         eq_contents(self.path(remote), FILES[remote])
예제 #15
0
 def test_put_sends_correct_file_with_globbing_off(self):
     """
     put() should send a file with a glob pattern in the path, when globbing disabled.
     """
     text = "globbed!"
     local = self.mkfile('foo[bar].txt', text)
     local2 = self.path('foo2.txt')
     with hide('everything'):
         put(local, '/', use_glob=False)
         get('/foo[bar].txt', local2)
     eq_contents(local2, text)
예제 #16
0
    def test_get_file_to_directory(self):
        """
        Directory as target path should result in joined pathname

        (Yes, this is duplicated in most of the other tests -- but good to have
        a default in case those tests change how they work later!)
        """
        target = 'file.txt'
        with hide('everything'):
            get(target, self.tmpdir)
        eq_contents(self.path(target), FILES[target])
예제 #17
0
 def test_put_file_to_existing_directory(self):
     """
     put() a single file into an existing remote directory
     """
     text = "foo!"
     local = self.mkfile('foo.txt', text)
     local2 = self.path('foo2.txt')
     with hide('everything'):
         put(local, '/')
         get('/foo.txt', local2)
     eq_contents(local2, text)
예제 #18
0
 def test_put_sends_correct_file_with_globbing_off(self):
     """
     put() should send a file with a glob pattern in the path, when globbing disabled.
     """
     text = "globbed!"
     local = self.mkfile('foo[bar].txt', text)
     local2 = self.path('foo2.txt')
     with hide('everything'):
         put(local, '/', use_glob=False)
         get('/foo[bar].txt', local2)
     eq_contents(local2, text)
예제 #19
0
 def test_put_file_to_existing_directory(self):
     """
     put() a single file into an existing remote directory
     """
     text = "foo!"
     local = self.mkfile('foo.txt', text)
     local2 = self.path('foo2.txt')
     with hide('everything'):
         put(local, '/')
         get('/foo.txt', local2)
     eq_contents(local2, text)
예제 #20
0
    def test_get_file_to_directory(self):
        """
        Directory as target path should result in joined pathname

        (Yes, this is duplicated in most of the other tests -- but good to have
        a default in case those tests change how they work later!)
        """
        target = 'file.txt'
        with hide('everything'):
            get(target, self.tmpdir)
        eq_contents(self.path(target), FILES[target])
예제 #21
0
 def test_upload_template_handles_file_destination(self):
     """
     upload_template() should work OK with file and directory destinations
     """
     template = self.mkfile("template.txt", "%(varname)s")
     local = self.path("result.txt")
     remote = "/configfile.txt"
     var = "foobar"
     with hide("everything"):
         upload_template(template, remote, {"varname": var})
         get(remote, local)
     eq_contents(local, var)
예제 #22
0
 def test_upload_template_handles_file_destination(self):
     """
     upload_template() should work OK with file and directory destinations
     """
     template = self.mkfile('template.txt', '%(varname)s')
     local = self.path('result.txt')
     remote = '/configfile.txt'
     var = 'foobar'
     with hide('everything'):
         upload_template(template, remote, {'varname': var})
         get(remote, local)
     eq_contents(local, var)
예제 #23
0
 def test_get_file_with_existing_file_target(self):
     """
     Clobbering existing local file should overwrite, with warning
     """
     local = self.path('target.txt')
     target = 'file.txt'
     with open(local, 'w') as fd:
         fd.write("foo")
     with hide('stdout', 'running'):
         get(target, local)
     assert "%s already exists" % local in sys.stderr.getvalue()
     eq_contents(local, FILES[target])
예제 #24
0
 def test_upload_template_handles_file_destination(self):
     """
     upload_template() should work OK with file and directory destinations
     """
     template = self.mkfile('template.txt', '%(varname)s')
     local = self.path('result.txt')
     remote = '/configfile.txt'
     var = 'foobar'
     with hide('everything'):
         upload_template(template, remote, {'varname': var})
         get(remote, local)
     eq_contents(local, var)
예제 #25
0
 def test_get_file_with_existing_file_target(self):
     """
     Clobbering existing local file should overwrite, with warning
     """
     local = self.path('target.txt')
     target = 'file.txt'
     with open(local, 'w') as fd:
         fd.write("foo")
     with hide('stdout', 'running'):
         get(target, local)
     assert "%s already exists" % local in sys.stderr.getvalue()
     eq_contents(local, FILES[target])
예제 #26
0
 def test_upload_template_handles_template_dir(self):
     """
     upload_template() should work OK with template dir
     """
     template = self.mkfile("template.txt", "%(varname)s")
     template_dir = os.path.dirname(template)
     local = self.path("result.txt")
     remote = "/configfile.txt"
     var = "foobar"
     with hide("everything"):
         upload_template("template.txt", remote, {"varname": var}, template_dir=template_dir)
         get(remote, local)
     eq_contents(local, var)
예제 #27
0
 def test_put_should_accept_file_like_objects(self):
     """
     put()'s local_path arg should take file-like objects too
     """
     local = self.path('whatever')
     fake_file = StringIO()
     fake_file.write("testing file-like objects in put()")
     pointer = fake_file.tell()
     target = '/new_file.txt'
     with hide('everything'):
         put(fake_file, target)
         get(target, local)
     eq_contents(local, fake_file.getvalue())
     # Sanity test of file pointer
     eq_(pointer, fake_file.tell())
예제 #28
0
 def test_upload_template_handles_jinja_template(self):
     """
     upload_template() should work OK with Jinja2 template
     """
     template = self.mkfile('template_jinja2.txt', '{{ first_name }}')
     template_name = os.path.basename(template)
     template_dir = os.path.dirname(template)
     local = self.path('result.txt')
     remote = '/configfile.txt'
     first_name = u'S\u00E9bastien'
     with hide('everything'):
         upload_template(template_name, remote, {'first_name': first_name},
             use_jinja=True, template_dir=template_dir)
         get(remote, local)
     eq_contents(local, first_name.encode('utf-8'))
예제 #29
0
 def test_upload_template_handles_template_dir(self):
     """
     upload_template() should work OK with template dir
     """
     template = self.mkfile('template.txt', '%(varname)s')
     template_dir = os.path.dirname(template)
     local = self.path('result.txt')
     remote = '/configfile.txt'
     var = 'foobar'
     with hide('everything'):
         upload_template('template.txt',
                         remote, {'varname': var},
                         template_dir=template_dir)
         get(remote, local)
     eq_contents(local, var)
 def test_upload_template_handles_jinja_template(self):
     """
     upload_template() should work OK with Jinja2 template
     """
     template = self.mkfile('template_jinja2.txt', '{{ first_name }}')
     template_name = os.path.basename(template)
     template_dir = os.path.dirname(template)
     local = self.path('result.txt')
     remote = '/configfile.txt'
     first_name = u'S\u00E9bastien'
     with hide('everything'):
         upload_template(template_name, remote, {'first_name': first_name},
             use_jinja=True, template_dir=template_dir)
         get(remote, local)
     eq_contents(local, first_name.encode('utf-8'))
예제 #31
0
 def test_put_should_accept_file_like_objects(self):
     """
     put()'s local_path arg should take file-like objects too
     """
     local = self.path('whatever')
     fake_file = StringIO()
     fake_file.write("testing file-like objects in put()")
     pointer = fake_file.tell()
     target = '/new_file.txt'
     with hide('everything'):
         put(fake_file, target)
         get(target, local)
     eq_contents(local, fake_file.getvalue())
     # Sanity test of file pointer
     eq_(pointer, fake_file.tell())
예제 #32
0
 def test_upload_template_handles_template_dir(self):
     """
     upload_template() should work OK with template dir
     """
     template = self.mkfile('template.txt', '%(varname)s')
     template_dir = os.path.dirname(template)
     local = self.path('result.txt')
     remote = '/configfile.txt'
     var = 'foobar'
     with hide('everything'):
         upload_template(
             'template.txt', remote, {'varname': var},
             template_dir=template_dir
         )
         get(remote, local)
     eq_contents(local, var)
예제 #33
0
    def test_put_to_empty_directory_uses_cwd(self):
        """
        put() expands empty remote arg to remote cwd

        Not a terribly sharp test -- we just get() with a relative path and are
        testing to make sure they match up -- but should still suffice.
        """
        text = "foo!"
        local = self.path('foo.txt')
        local2 = self.path('foo2.txt')
        with open(local, 'w') as fd:
            fd.write(text)
        with hide('everything'):
            put(local)
            get('foo.txt', local2)
        eq_contents(local2, text)
예제 #34
0
    def test_put_to_empty_directory_uses_cwd(self):
        """
        put() expands empty remote arg to remote cwd

        Not a terribly sharp test -- we just get() with a relative path and are
        testing to make sure they match up -- but should still suffice.
        """
        text = "foo!"
        local = self.path('foo.txt')
        local2 = self.path('foo2.txt')
        with open(local, 'w') as fd:
            fd.write(text)
        with hide('everything'):
            put(local)
            get('foo.txt', local2)
        eq_contents(local2, text)
예제 #35
0
 def test_get_tree_with_implicit_local_path(self):
     """
     Download entire tree without specifying a local path
     """
     dirname = env.host_string.replace(':', '-')
     try:
         with hide('everything'):
             get('tree')
         leaves = filter(lambda x: x[0].startswith('/tree'), FILES.items())
         for path, contents in leaves:
             path = os.path.join(dirname, path[1:])
             eq_contents(path, contents)
             os.remove(path)
     # Cleanup
     finally:
         if os.path.exists(dirname):
             shutil.rmtree(dirname)
예제 #36
0
 def test_get_tree_with_implicit_local_path(self):
     """
     Download entire tree without specifying a local path
     """
     dirname = env.host_string.replace(':', '-')
     try:
         with hide('everything'):
             get('tree')
         leaves = filter(lambda x: x[0].startswith('/tree'), FILES.items())
         for path, contents in leaves:
             path = os.path.join(dirname, path[1:])
             eq_contents(path, contents)
             os.remove(path)
     # Cleanup
     finally:
         if os.path.exists(dirname):
             shutil.rmtree(dirname)
예제 #37
0
 def test_upload_template_handles_jinja_template(self):
     """
     upload_template() should work OK with Jinja2 template
     """
     template = self.mkfile("template_jinja2.txt", "{{ first_name }}")
     template_name = os.path.basename(template)
     template_dir = os.path.dirname(template)
     local = self.path("result.txt")
     remote = "/configfile.txt"
     first_name = u"S\u00E9bastien"
     with hide("everything"):
         upload_template(
             template_name, remote, {"first_name": first_name}, use_jinja=True, template_dir=template_dir
         )
         get(remote, local)
     if six.PY2 is True:
         first_name = first_name.encode("utf-8")
     eq_contents(local, first_name)
예제 #38
0
 def test_put_from_empty_directory_uses_cwd(self):
     """
     put() expands empty local arg to local cwd
     """
     text = 'foo!'
     # Don't use the current cwd since that's a whole lotta files to upload
     old_cwd = os.getcwd()
     os.chdir(self.tmpdir)
     # Write out file right here
     with open('file.txt', 'w') as fd:
         fd.write(text)
     with hide('everything'):
         # Put our cwd (which should only contain the file we just created)
         put('', '/')
         # Get it back under a new name (noting that when we use a truly
         # empty put() local call, it makes a directory remotely with the
         # name of the cwd)
         remote = os.path.join(os.path.basename(self.tmpdir), 'file.txt')
         get(remote, 'file2.txt')
     # Compare for sanity test
     eq_contents('file2.txt', text)
     # Restore cwd
     os.chdir(old_cwd)
예제 #39
0
 def test_put_from_empty_directory_uses_cwd(self):
     """
     put() expands empty local arg to local cwd
     """
     text = 'foo!'
     # Don't use the current cwd since that's a whole lotta files to upload
     old_cwd = os.getcwd()
     os.chdir(self.tmpdir)
     # Write out file right here
     with open('file.txt', 'w') as fd:
         fd.write(text)
     with hide('everything'):
         # Put our cwd (which should only contain the file we just created)
         put('', '/')
         # Get it back under a new name (noting that when we use a truly
         # empty put() local call, it makes a directory remotely with the
         # name of the cwd)
         remote = os.path.join(os.path.basename(self.tmpdir), 'file.txt')
         get(remote, 'file2.txt')
     # Compare for sanity test
     eq_contents('file2.txt', text)
     # Restore cwd
     os.chdir(old_cwd)