def test_archive_file(self): """ LocalTransport should copy the file from the supplied fileobj to a local path. """ transport = LocalTransport(self.archive) fakefile = StringIO(u"This is the artifact") transport.archive_file(fakefile, "/temp/temp.gz") filename = os.path.join(self.basedir, "temp/temp.gz") self.assertEqual(file(filename).read(), "This is the artifact")
def test_link_filename_to_filename_with_preexisting_file(self): """ If the filename for the destination already exists, then we shouldn't attempt to link the file. """ transport = LocalTransport(self.archive) fakefile = StringIO("This is the artifact") transport.archive_file(fakefile, "/temp/temp.gz") transport.link_filename_to_filename("/temp/temp.gz", "/temp/temp.gz") filename = os.path.join(self.basedir, "temp/temp.gz") # Test that the number of links to this file is 2 # (the original, and the newly created hardlink) self.assertEqual(1, os.stat(filename).st_nlink)
def test_link_artifact_to_current(self): """ Create a link in the parent directory for this artifact, pointing to the directory of the artifact, with the name "current". """ transport = LocalTransport(self.archive) fakefile = StringIO("This is the artifact") transport.archive_file(fakefile, "/temp/temp.gz") current_dir = transport.link_to_current("/temp/temp.gz") self.assertEqual(os.path.join(self.basedir, "current"), current_dir) self.assertTrue(os.path.islink(current_dir), "current is not a symlink") self.assertEqual( os.path.dirname(transport.get_relative_filename("/temp/temp.gz")), os.path.realpath(current_dir))
def test_link_filename_to_filename(self): """ LocalTransport.link_filename_to_filename should hardlink the source to the destination. """ transport = LocalTransport(self.archive) fakefile = StringIO("This is the artifact") transport.archive_file(fakefile, "/temp/temp.gz") transport.link_filename_to_filename("/temp/temp.gz", "/temp/temp1.gz") filename1 = os.path.join(self.basedir, "temp/temp.gz") # Test that the number of links to this file is 2 # (the original, and the newly created hardlink) self.assertEqual(2, os.stat(filename1).st_nlink) filename2 = os.path.join(self.basedir, "temp/temp1.gz") self.assertEqual(file(filename2).read(), "This is the artifact")
def test_link_artifact_to_current(self): """ Create a link in the parent directory for this artifact, pointing to the directory of the artifact, with the name "current". """ transport = LocalTransport(self.archive) fakefile = StringIO("This is the artifact") transport.archive_file(fakefile, "/temp/temp.gz") current_dir = transport.link_to_current("/temp/temp.gz") self.assertEqual(os.path.join(self.basedir, "current"), current_dir) self.assertTrue( os.path.islink(current_dir), "current is not a symlink") self.assertEqual( os.path.dirname(transport.get_relative_filename("/temp/temp.gz")), os.path.realpath(current_dir))
def test_link_artifact_to_current_replaces_existing_current(self): """ If we run link_artifact_to_current with a new path, it should ensure that the "current" directory is the new one. """ transport = LocalTransport(self.archive) fakefile = StringIO("This is the artifact") transport.archive_file(fakefile, "/temp1/temp.gz") transport.link_to_current("/temp1/temp.gz") fakefile = StringIO("Another artifact") transport.archive_file(fakefile, "/temp2/temp.gz") current_dir = transport.link_to_current("/temp2/temp.gz") self.assertEqual( os.path.dirname(transport.get_relative_filename("/temp2/temp.gz")), os.path.realpath(current_dir))
def test_archive_file(self): """ LocalTransport should copy the file from the supplied fileobj to a local path. """ transport = LocalTransport(self.archive) fakefile = StringIO(u"This is the artifact") size = transport.archive_file(fakefile, "/temp/temp.gz") self.assertEqual(20, size) filename = os.path.join(self.basedir, "temp/temp.gz") self.assertEqual(file(filename).read(), "This is the artifact")