def test_cdimage_archiver_policy(self):
        """
        If we use the cdimage policy, then the file path but should delegate to
        the default policy for builds without a projectbuild.
        """
        project, dependency = self.create_dependencies()
        projectbuild = build_project(project, queue_build=False)

        build = BuildFactory.create(job=dependency.job,
                                    build_id=projectbuild.build_key)

        ArtifactFactory.create(build=build, filename="testing.gz")
        update_projectbuilds(build)

        archive = ArchiveFactory.create(policy="cdimage")
        archive.add_build(build)

        archived = archive.get_archived_artifacts_for_build(build).order_by(
            "archived_path")
        policy = CdimageArchivePolicy()
        paths = []
        for item in archived:
            projectbuild = (item.projectbuild_dependency
                            and item.projectbuild_dependency.projectbuild
                            or None)
            paths.append(
                policy.get_path_for_artifact(item.artifact,
                                             build=build,
                                             dependency=item.dependency,
                                             projectbuild=projectbuild))
        self.assertEqual(
            "\n".join(paths),
            "\n".join(archived.values_list("archived_path", flat=True)))
Exemple #2
0
    def test_cdimage_archiver_policy(self):
        """
        If we use the cdimage policy, then the file path but should delegate to
        the default policy for builds without a projectbuild.
        """
        project, dependency = self.create_dependencies()
        projectbuild = build_project(project, queue_build=False)

        build = BuildFactory.create(
            job=dependency.job, build_id=projectbuild.build_key)

        ArtifactFactory.create(build=build, filename="testing.gz")
        update_projectbuilds(build)

        archive = ArchiveFactory.create(policy="cdimage")
        archive.add_build(build)

        archived = archive.get_archived_artifacts_for_build(build).order_by(
            "archived_path")
        policy = CdimageArchivePolicy()
        paths = []
        for item in archived:
            projectbuild = (item.projectbuild_dependency and
                            item.projectbuild_dependency.projectbuild or None)
            paths.append(policy.get_path_for_artifact(
                item.artifact, build=build, dependency=item.dependency,
                projectbuild=projectbuild))
        self.assertEqual(
            "\n".join(paths),
            "\n".join(archived.values_list("archived_path", flat=True)))
    def test_mappings_into_cdimage_structure(self):
        """
        Artifact paths and filenames are translated into
        a cdimage-like path, using the project name and
        build id.
        """
        mock_build = mock.Mock()
        mock_build.project.name = "my-project"
        mock_build.build_id = "20010101.0"
        mock_artifact_1 = mock.Mock()
        mock_artifact_1.url = "/first/path/thing.txt"
        mock_artifact_1.filename = "thing.txt"
        mock_artifact_2 = mock.Mock()
        mock_artifact_2.url = "/second/path/stuff.txt"
        mock_artifact_2.filename = "stuff.txt"
        mock_build.get_current_artifacts()
        mock_build.get_current_artifacts.return_value = [
            mock_artifact_1, mock_artifact_2]

        policy = CdimageArchivePolicy(projectbuild=mock_build)
        mappings = policy.get_mappings()
        expected = {
            "/first/path/thing.txt": "my-project/20010101.0/thing.txt",
            "/second/path/stuff.txt": "my-project/20010101.0/stuff.txt"
        }
        self.assertEqual(expected, mappings)
Exemple #4
0
    def test_archive_build_several_projectbuild_dependencies(self):
        """
        If we archive a build that is used in several projectbuilds, then we
        should get multiple copies of the artifact.
        """
        project1, dependency1, dependency2 = self.create_dependencies(
            2)
        project2 = ProjectFactory.create(name="Project 2")
        ProjectDependency.objects.create(
            project=project2, dependency=dependency1)

        projectbuild = build_project(project1, queue_build=False)

        build1 = BuildFactory.create(
            job=dependency1.job, build_id=projectbuild.build_key)
        build2 = BuildFactory.create(
            job=dependency2.job, build_id=projectbuild.build_key)

        artifact1 = ArtifactFactory.create(build=build1, filename="file1.gz")
        artifact2 = ArtifactFactory.create(build=build2, filename="file2.gz")
        archive = ArchiveFactory.create(policy="cdimage")

        update_projectbuilds(build1)
        create_projectbuilds_for_autotracking(build1)
        archive.add_build(build1)
        self.assertEqual(3, archive.items.count())

        update_projectbuilds(build2)
        create_projectbuilds_for_autotracking(build2)
        archive.add_build(build2)
        self.assertEqual(5, archive.items.count())

        artifacts = ArchiveArtifact.objects.all().order_by("archived_path")
        policy = CdimageArchivePolicy()
        self.assertEqual(
            "{dependency1}\n{dependency2}\n"
            "project-1/{build}/file1.gz\nproject-1/{build}/file2.gz\n"
            "project-2/{build}/file1.gz".format(
                dependency1=policy.get_path_for_artifact(
                    artifact=artifact1, build=build1, dependency=dependency1),
                dependency2=policy.get_path_for_artifact(
                    artifact=artifact2, build=build2, dependency=dependency2),
                build=projectbuild.build_id),
            "\n".join(artifacts.values_list("archived_path", flat=True)))
    def test_archive_build_several_projectbuild_dependencies(self):
        """
        If we archive a build that is used in several projectbuilds, then we
        should get multiple copies of the artifact.
        """
        project1, dependency1, dependency2 = self.create_dependencies(2)
        project2 = ProjectFactory.create(name="Project 2")
        ProjectDependency.objects.create(project=project2,
                                         dependency=dependency1)

        projectbuild = build_project(project1, queue_build=False)

        build1 = BuildFactory.create(job=dependency1.job,
                                     build_id=projectbuild.build_key)
        build2 = BuildFactory.create(job=dependency2.job,
                                     build_id=projectbuild.build_key)

        artifact1 = ArtifactFactory.create(build=build1, filename="file1.gz")
        artifact2 = ArtifactFactory.create(build=build2, filename="file2.gz")
        archive = ArchiveFactory.create(policy="cdimage")

        update_projectbuilds(build1)
        create_projectbuilds_for_autotracking(build1)
        archive.add_build(build1)
        self.assertEqual(3, archive.items.count())

        update_projectbuilds(build2)
        create_projectbuilds_for_autotracking(build2)
        archive.add_build(build2)
        self.assertEqual(5, archive.items.count())

        artifacts = ArchiveArtifact.objects.all().order_by("archived_path")
        policy = CdimageArchivePolicy()
        self.assertEqual(
            "{dependency1}\n{dependency2}\n"
            "project-1/{build}/file1.gz\nproject-1/{build}/file2.gz\n"
            "project-2/{build}/file1.gz".format(
                dependency1=policy.get_path_for_artifact(
                    artifact=artifact1, build=build1, dependency=dependency1),
                dependency2=policy.get_path_for_artifact(
                    artifact=artifact2, build=build2, dependency=dependency2),
                build=projectbuild.build_id),
            "\n".join(artifacts.values_list("archived_path", flat=True)))
    def test_get_path_for_artifact(self):
        """
        The CdimageArchivePolicy should calculate a cdimage-like path using the
        project name and build id.
        url.
        """
        project = ProjectFactory.create(name="My Test Project")
        dependency = DependencyFactory.create()
        ProjectDependency.objects.create(
            project=project, dependency=dependency)

        from projects.helpers import build_project
        projectbuild = build_project(project, queue_build=False)

        build = BuildFactory.create(
            job=dependency.job, build_id=projectbuild.build_id)

        artifact = ArtifactFactory.create(
            filename="thing.txt", build=build)
        policy = CdimageArchivePolicy()
        self.assertEqual(
            "%s/%s/thing.txt" % ("my-test-project", build.build_id),
            policy.get_path_for_artifact(artifact, projectbuild=projectbuild))
    def test_get_path_for_artifact_with_dependency(self):
        """
        If the cdimage archiver gets a dependency with no projectbuild, it
        should delegate to the DefaultPolicy to generate the archive filename.
        """
        project = ProjectFactory.create(name="My Test Project")
        dependency = DependencyFactory.create()
        ProjectDependency.objects.create(
            project=project, dependency=dependency)

        from projects.helpers import build_project
        projectbuild = build_project(project, queue_build=False)

        build = BuildFactory.create(
            job=dependency.job, build_id=projectbuild.build_id)

        artifact = ArtifactFactory.create(
            filename="thing.txt", build=build)

        policy = CdimageArchivePolicy()
        self.assertEqual(
            "%s/%s/thing.txt" % ("my-test-project", build.build_id),
            policy.get_path_for_artifact(
                artifact, dependency=dependency, projectbuild=projectbuild))
Exemple #8
0
    def test_get_path_for_artifact_with_dependency(self):
        """
        If the cdimage archiver gets a dependency with no projectbuild, it
        should delegate to the DefaultPolicy to generate the archive filename.
        """
        project = ProjectFactory.create(name="My Test Project")
        dependency = DependencyFactory.create()
        ProjectDependency.objects.create(project=project,
                                         dependency=dependency)

        from projects.helpers import build_project
        projectbuild = build_project(project, queue_build=False)

        build = BuildFactory.create(job=dependency.job,
                                    build_id=projectbuild.build_id)

        artifact = ArtifactFactory.create(filename="thing.txt", build=build)

        policy = CdimageArchivePolicy()
        self.assertEqual(
            "%s/%s/thing.txt" % ("my-test-project", build.build_id),
            policy.get_path_for_artifact(artifact,
                                         dependency=dependency,
                                         projectbuild=projectbuild))
Exemple #9
0
    def test_get_path_for_artifact(self):
        """
        The CdimageArchivePolicy should calculate a cdimage-like path using the
        project name and build id.
        url.
        """
        project = ProjectFactory.create(name="My Test Project")
        dependency = DependencyFactory.create()
        ProjectDependency.objects.create(project=project,
                                         dependency=dependency)

        from projects.helpers import build_project
        projectbuild = build_project(project, queue_build=False)

        build = BuildFactory.create(job=dependency.job,
                                    build_id=projectbuild.build_id)

        artifact = ArtifactFactory.create(filename="thing.txt", build=build)
        policy = CdimageArchivePolicy()
        self.assertEqual(
            "%s/%s/thing.txt" % ("my-test-project", build.build_id),
            policy.get_path_for_artifact(artifact,
                                         dependency=dependency,
                                         projectbuild=projectbuild))