Exemplo n.º 1
0
    def test_start(self):
        """
        LocalTransport.start should ensure that the basedir exists.
        """
        dirname = os.path.join(self.basedir, "temp")
        self.archive.basedir = dirname
        transport = LocalTransport(self.archive)
        transport.start()

        self.assertTrue(os.path.exists(dirname))
Exemplo n.º 2
0
    def test_start(self):
        """
        LocalTransport.start should ensure that the basedir exists.
        """
        dirname = os.path.join(self.basedir, "temp")
        self.archive.basedir = dirname
        transport = LocalTransport(self.archive)
        transport.start()

        self.assertTrue(os.path.exists(dirname))
Exemplo n.º 3
0
    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")
Exemplo n.º 4
0
    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")
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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))
Exemplo n.º 7
0
    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")
Exemplo n.º 8
0
    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))
Exemplo n.º 9
0
    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))
Exemplo n.º 10
0
    def test_archive_from_url(self):
        """
        archive_from_url takes a valid URL and opens the file and then passes
        it to archive_file.
        """
        fakefile = StringIO(u"Entirely new artifact")

        mock_request = mock.Mock()
        with mock.patch("archives.transports.urllib2") as urllib2_mock:
            urllib2_mock.Request.return_value = mock_request
            transport = LocalTransport(self.archive)
            urllib2_mock.urlopen.return_value = fakefile
            transport.archive_url("http://example.com/testing",
                                  "/temp/temp.gz", "username", "password")
        urllib2_mock.urlopen.assert_called_once_with(mock_request)
        urllib2_mock.Request.assert_called_once_with(
            "http://example.com/testing")
        mock_request.assert_has_calls(
            mock.call.add_header("Authorization",
                                 "Basic dXNlcm5hbWU6cGFzc3dvcmQ="))
        filename = os.path.join(self.basedir, "temp/temp.gz")
        self.assertEqual(file(filename).read(), "Entirely new artifact")
Exemplo n.º 11
0
    def test_archive_from_url(self):
        """
        archive_from_url takes a valid URL and opens the file and then passes it
        to archive_file.
        """
        fakefile = StringIO(u"Entirely new artifact")

        mock_request = mock.Mock()
        with mock.patch("archives.transports.urllib2") as urllib2_mock:
            urllib2_mock.Request.return_value = mock_request
            transport = LocalTransport(self.archive)
            urllib2_mock.urlopen.return_value = fakefile
            transport.archive_url(
                "http://example.com/testing", "/temp/temp.gz",
                "username", "password")
        urllib2_mock.urlopen.assert_called_once_with(mock_request)
        urllib2_mock.Request.assert_called_once_with(
            "http://example.com/testing")
        mock_request.assert_has_calls(
            mock.call.add_header(
                "Authorization", "Basic dXNlcm5hbWU6cGFzc3dvcmQ="))
        filename = os.path.join(self.basedir, "temp/temp.gz")
        self.assertEqual(file(filename).read(), "Entirely new artifact")
Exemplo n.º 12
0
    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))
Exemplo n.º 13
0
    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")