Esempio n. 1
0
 def test_install_dir_moves_dir_into_place(self):
     download_image = os.path.join(self.make_dir(), 'download-image')
     published_image = os.path.join(self.make_dir(), 'published-image')
     contents = factory.getRandomString()
     os.makedirs(download_image)
     sample_file = factory.make_file(download_image, contents=contents)
     install_dir(download_image, published_image)
     self.assertThat(
         os.path.join(published_image, os.path.basename(sample_file)),
         FileContains(contents))
Esempio n. 2
0
 def test_install_dir_moves_dir_into_place(self):
     download_image = os.path.join(self.make_dir(), 'download-image')
     published_image = os.path.join(self.make_dir(), 'published-image')
     contents = factory.getRandomString()
     os.makedirs(download_image)
     sample_file = factory.make_file(download_image, contents=contents)
     install_dir(download_image, published_image)
     self.assertThat(
         os.path.join(published_image, os.path.basename(sample_file)),
         FileContains(contents))
Esempio n. 3
0
 def test_install_dir_replaces_existing_dir(self):
     download_image = os.path.join(self.make_dir(), 'download-image')
     published_image = os.path.join(self.make_dir(), 'published-image')
     os.makedirs(download_image)
     sample_file = factory.make_file(download_image)
     os.makedirs(published_image)
     obsolete_file = factory.make_file(published_image)
     install_dir(download_image, published_image)
     self.assertThat(
         os.path.join(published_image, os.path.basename(sample_file)),
         FileExists())
     self.assertThat(obsolete_file, Not(FileExists()))
Esempio n. 4
0
 def test_install_dir_replaces_existing_dir(self):
     download_image = os.path.join(self.make_dir(), 'download-image')
     published_image = os.path.join(self.make_dir(), 'published-image')
     os.makedirs(download_image)
     sample_file = factory.make_file(download_image)
     os.makedirs(published_image)
     obsolete_file = factory.make_file(published_image)
     install_dir(download_image, published_image)
     self.assertThat(
         os.path.join(published_image, os.path.basename(sample_file)),
         FileExists())
     self.assertThat(obsolete_file, Not(FileExists()))
Esempio n. 5
0
 def test_install_dir_normalises_permissions(self):
     # install_dir() normalises directory permissions to 0755 and file
     # permissions to 0644.
     target_dir = FilePath(self.make_dir())
     new_dir = FilePath(self.make_dir())
     new_dir.chmod(0700)
     new_image = new_dir.child("image")
     new_image.touch()
     new_image.chmod(0600)
     install_dir(new_dir.path, target_dir.path)
     self.assertEqual("rwxr-xr-x", target_dir.getPermissions().shorthand())
     self.assertEqual(
         "rw-r--r--",
         target_dir.child("image").getPermissions().shorthand())
Esempio n. 6
0
    def test_install_dir_replaces_existing_symlink(self):
        download_image = os.path.join(self.make_dir(), 'download-image')
        published_image = os.path.join(self.make_dir(), 'published-image')
        linked_image = os.path.join(self.make_dir(), 'linked-image')
        os.makedirs(download_image)
        sample_file = factory.make_file(download_image)
        os.makedirs(published_image)
        os.symlink(published_image, linked_image)

        install_dir(download_image, linked_image)

        self.assertThat(linked_image, DirExists())
        self.assertThat(
            os.path.join(linked_image, os.path.basename(sample_file)),
            FileExists())
Esempio n. 7
0
    def test_install_dir_replaces_existing_symlink(self):
        download_image = os.path.join(self.make_dir(), 'download-image')
        published_image = os.path.join(self.make_dir(), 'published-image')
        linked_image = os.path.join(self.make_dir(), 'linked-image')
        os.makedirs(download_image)
        sample_file = factory.make_file(download_image)
        os.makedirs(published_image)
        os.symlink(published_image, linked_image)

        install_dir(download_image, linked_image)

        self.assertThat(linked_image, DirExists())
        self.assertThat(
            os.path.join(linked_image, os.path.basename(sample_file)),
            FileExists())
Esempio n. 8
0
 def test_install_dir_normalises_permissions(self):
     # install_dir() normalises directory permissions to 0755 and file
     # permissions to 0644.
     target_dir = FilePath(self.make_dir())
     new_dir = FilePath(self.make_dir())
     new_dir.chmod(0700)
     new_image = new_dir.child("image")
     new_image.touch()
     new_image.chmod(0600)
     install_dir(new_dir.path, target_dir.path)
     self.assertEqual(
         "rwxr-xr-x",
         target_dir.getPermissions().shorthand())
     self.assertEqual(
         "rw-r--r--",
         target_dir.child("image").getPermissions().shorthand())
Esempio n. 9
0
 def test_install_dir_sweeps_aside_dot_new_and_dot_old_if_any(self):
     # If directories <old>.old or <old>.new already exist, they're
     # probably from an aborted previous run.  They won't stop
     # install_dir from doing its work.
     download_image = os.path.join(self.make_dir(), 'download-image')
     published_image = os.path.join(self.make_dir(),
                                    factory.getRandomString())
     contents = factory.getRandomString()
     os.makedirs(download_image)
     sample_file = factory.make_file(download_image, contents=contents)
     os.makedirs('%s.old' % published_image)
     os.makedirs('%s.new' % published_image)
     install_dir(download_image, published_image)
     self.assertThat(
         os.path.join(published_image, os.path.basename(sample_file)),
         FileContains(contents))
     self.assertThat('%s.old' % published_image, Not(DirExists()))
     self.assertThat('%s.new' % published_image, Not(DirExists()))
Esempio n. 10
0
 def test_install_dir_sweeps_aside_dot_new_and_dot_old_if_any(self):
     # If directories <old>.old or <old>.new already exist, they're
     # probably from an aborted previous run.  They won't stop
     # install_dir from doing its work.
     download_image = os.path.join(self.make_dir(), 'download-image')
     published_image = os.path.join(
         self.make_dir(), factory.getRandomString())
     contents = factory.getRandomString()
     os.makedirs(download_image)
     sample_file = factory.make_file(download_image, contents=contents)
     os.makedirs('%s.old' % published_image)
     os.makedirs('%s.new' % published_image)
     install_dir(download_image, published_image)
     self.assertThat(
         os.path.join(published_image, os.path.basename(sample_file)),
         FileContains(contents))
     self.assertThat('%s.old' % published_image, Not(DirExists()))
     self.assertThat('%s.new' % published_image, Not(DirExists()))