Exemplo n.º 1
0
    def test_link_artifact_in_archive(self):
        """
        The link_artifact_in_archive task should use the transport to link the
        specified artifacts.
        """
        project = ProjectFactory.create()
        dependency = DependencyFactory.create()
        ProjectDependency.objects.create(
            project=project, dependency=dependency)
        build = BuildFactory.create(job=dependency.job, phase=Build.FINALIZED)
        artifact = ArtifactFactory.create(
            build=build, filename="testing/testing.txt")

        # We need to ensure that the artifacts are all connected up.
        process_build_dependencies(build.pk)

        archive = ArchiveFactory.create(
            transport="local", basedir=self.basedir, default=True)
        [item1, item2] = archive.add_build(artifact.build)[artifact]
        item1.archived_size = 1000
        item1.save()

        transport = mock.Mock(spec=LocalTransport)
        with mock.patch.object(
                Archive, "get_transport", return_value=transport):
            link_artifact_in_archive(item1.pk, item2.pk)

        transport.link_filename_to_filename.assert_called_once_with(
            item1.archived_path, item2.archived_path)
        transport.link_to_current.assert_called_once_with(item2.archived_path)
        item1 = ArchiveArtifact.objects.get(pk=item1.pk)
        self.assertEqual(1000, item1.archived_size)
Exemplo n.º 2
0
    def test_link_artifact_in_archive(self):
        """
        The link_artifact_in_archive task should use the transport to link the
        specified artifacts.
        """
        project = ProjectFactory.create()
        dependency = DependencyFactory.create()
        ProjectDependency.objects.create(project=project,
                                         dependency=dependency)
        build = BuildFactory.create(job=dependency.job, phase=Build.FINALIZED)
        artifact = ArtifactFactory.create(build=build,
                                          filename="testing/testing.txt")

        # We need to ensure that the artifacts are all connected up.
        process_build_dependencies(build.pk)

        archive = ArchiveFactory.create(transport="local",
                                        basedir=self.basedir,
                                        default=True)
        [item1, item2] = archive.add_build(artifact.build)[artifact]
        item1.archived_size = 1000
        item1.save()

        transport = mock.Mock(spec=LocalTransport)
        with mock.patch.object(Archive,
                               "get_transport",
                               return_value=transport):
            link_artifact_in_archive(item1.pk, item2.pk)

        transport.link_filename_to_filename.assert_called_once_with(
            item1.archived_path, item2.archived_path)
        transport.link_to_current.assert_called_once_with(item2.archived_path)
        item1 = ArchiveArtifact.objects.get(pk=item1.pk)
        self.assertEqual(1000, item1.archived_size)
Exemplo n.º 3
0
    def test_archive_artifact_from_finalized_projectbuild(self):
        """
        If the build is complete, and the item being archived is in a FINALIZED
        ProjectBuild, it should use the transport to set the current directory
        correctly.
        """
        project = ProjectFactory.create()
        dependency1 = DependencyFactory.create()
        ProjectDependency.objects.create(project=project,
                                         dependency=dependency1)

        dependency2 = DependencyFactory.create()
        ProjectDependency.objects.create(project=project,
                                         dependency=dependency2)

        projectbuild = build_project(project, queue_build=False)
        build1 = BuildFactory.create(job=dependency1.job,
                                     build_id=projectbuild.build_key,
                                     phase=Build.FINALIZED)
        build2 = BuildFactory.create(job=dependency2.job,
                                     build_id=projectbuild.build_key,
                                     phase=Build.FINALIZED)

        artifact = ArtifactFactory.create(build=build2,
                                          filename="testing/testing.txt")

        # We need to ensure that the artifacts are all connected up.
        process_build_dependencies(build1.pk)
        process_build_dependencies(build2.pk)

        archive = ArchiveFactory.create(transport="local",
                                        basedir=self.basedir,
                                        default=True)
        [item1, item2] = archive.add_build(artifact.build)[artifact]

        transport = LoggingTransport(archive)
        with mock.patch.object(Archive,
                               "get_transport",
                               return_value=transport):
            link_artifact_in_archive(item1.pk, item2.pk)

        # Both builds are complete, we expect this to be made the current
        # build.
        self.assertEqual([
            "START",
            "Link %s to %s" % (item1.archived_path, item2.archived_path),
            "Make %s current" % item2.archived_path, "END"
        ], transport.log)
Exemplo n.º 4
0
    def test_archive_artifact_from_finalized_projectbuild(self):
        """
        If the build is complete, and the item being archived is in a FINALIZED
        ProjectBuild, it should use the transport to set the current directory
        correctly.
        """
        project = ProjectFactory.create()
        dependency1 = DependencyFactory.create()
        ProjectDependency.objects.create(
            project=project, dependency=dependency1)

        dependency2 = DependencyFactory.create()
        ProjectDependency.objects.create(
            project=project, dependency=dependency2)

        projectbuild = build_project(project, queue_build=False)
        build1 = BuildFactory.create(
            job=dependency1.job, build_id=projectbuild.build_key,
            phase=Build.FINALIZED)
        build2 = BuildFactory.create(
            job=dependency2.job, build_id=projectbuild.build_key,
            phase=Build.FINALIZED)

        artifact = ArtifactFactory.create(
            build=build2, filename="testing/testing.txt")

        # We need to ensure that the artifacts are all connected up.
        process_build_dependencies(build1.pk)
        process_build_dependencies(build2.pk)

        archive = ArchiveFactory.create(
            transport="local", basedir=self.basedir, default=True)
        [item1, item2] = archive.add_build(artifact.build)[artifact]

        transport = LoggingTransport(archive)
        with mock.patch.object(
                Archive, "get_transport", return_value=transport):
            link_artifact_in_archive(item1.pk, item2.pk)

        # Both builds are complete, we expect this to be made the current
        # build.
        self.assertEqual(
            ["START",
             "Link %s to %s" % (item1.archived_path, item2.archived_path),
             "Make %s current" % item2.archived_path,
             "END"],
            transport.log)