Пример #1
0
    def test_artifact_get_url(self):
        """
        ArchiveArtifact.get_url should return a valid URL for an artifact
        within the archive.
        """
        project, dependency = self.create_dependencies()
        ProjectDependency.objects.create(project=project,
                                         dependency=dependency)

        projectbuild = build_project(project, queue_build=False)

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

        ArtifactFactory.create(build=build, filename="file1.gz")
        archive = ArchiveFactory.create(policy="cdimage")
        update_projectbuilds(build)
        create_projectbuilds_for_autotracking(build)
        archive.add_build(build)

        [item1, item2] = list(archive.get_archived_artifacts_for_build(build))

        self.assertEqual(
            "http://example.com/projects/%s" % item1.archived_path,
            item1.get_url())
        self.assertEqual(
            "http://example.com/projects/%s" % item2.archived_path,
            item2.get_url())
Пример #2
0
    def test_artifact_get_url(self):
        """
        ArchiveArtifact.get_url should return a valid URL for an artifact within
        the archive.
        """
        project, dependency = self.create_dependencies()
        ProjectDependency.objects.create(
            project=project, dependency=dependency)

        projectbuild = build_project(project, queue_build=False)

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

        artifact = ArtifactFactory.create(build=build, filename="file1.gz")
        archive = ArchiveFactory.create(policy="cdimage")

        update_projectbuilds(build)
        create_projectbuilds_for_autotracking(build)
        archive.add_build(build)

        [item1, item2] = list(archive.get_archived_artifacts_for_build(build))

        self.assertEqual(
            "http://example.com/projects/%s" % item1.archived_path,
            item1.get_url())
        self.assertEqual(
            "http://example.com/projects/%s" % item2.archived_path,
            item2.get_url())
Пример #3
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)))
Пример #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)))