def test_project_build_detail_view_with_archived_artifacts(self): """ If we have archived artifacts for this build, we should provide the list of archived items in the response context. """ dependency = DependencyFactory.create() ProjectDependency.objects.create( project=self.project, dependency=dependency) projectbuild = build_project(self.project, queue_build=False) build = BuildFactory.create( job=dependency.job, build_id=projectbuild.build_key) artifact = ArtifactFactory.create(build=build, filename="file1.gz") process_build_dependencies(build.pk) archive = ArchiveFactory.create(policy="cdimage", default=True) items = [x for x in archive.add_build(build)[artifact] if x.projectbuild_dependency] url = reverse( "project_projectbuild_detail", kwargs={"project_pk": self.project.pk, "build_pk": projectbuild.pk}) response = self.app.get(url, user="******") self.assertEqual(items, list(response.context["archived_items"]))
def test_archive_projectbuild(self): """ Archive project build should create an archiver and archive it. """ archive = ArchiveFactory.create() project = ProjectFactory.create() dependency = DependencyFactory.create() ProjectDependency.objects.create( project=project, dependency=dependency) projectbuild = build_project(project, queue_build=False) build = BuildFactory.create( job=dependency.job, build_id=projectbuild.build_id) ArtifactFactory.create_batch(3, build=build) with mock.patch.object(archive, "get_archiver") as mock_archive: archive_projectbuild(projectbuild, archive) mock_archive.return_value.return_value.assert_has_calls( [mock.call.archive()])
def test_item_from_artifact_and_archived_artifact(self): """ Return an artifact or archived artifact in a standard format for display. """ project = ProjectFactory.create() dependency = DependencyFactory.create() 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, phase=Build.FINALIZED) # Create the artifact and check the display format artifact = ArtifactFactory.create(build=build, filename="file1.gz") artifact_item = ProjectDetailView.item_from_artifact(artifact) self.assertIsNotNone(artifact_item) self.assertTrue(isinstance(artifact_item, dict)) self.assertTrue("build_name" in artifact_item) self.assertTrue("filename" in artifact_item) self.assertTrue("url" in artifact_item) self.assertTrue("archived" in artifact_item) # Archive the artifact and check the display format process_build_dependencies(build.pk) archive = ArchiveFactory.create(policy="cdimage", default=True) items = [] for x in archive.add_build(build)[artifact]: if x.projectbuild_dependency: items.append(x) self.assertEquals(len(items), 1) archived_item = ProjectDetailView.item_from_archived_artifact(items[0]) self.assertIsNotNone(archived_item) self.assertTrue(isinstance(archived_item, dict)) self.assertTrue("build_name" in archived_item) self.assertTrue("filename" in archived_item) self.assertTrue("url" in archived_item) self.assertTrue("archived" in archived_item)
def test_project_detail_artifacts(self): """ The project detail should return artifacts with the URL from Jenkins or from the archive (for archived artifacts). """ project = ProjectFactory.create() dependency = DependencyFactory.create() 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, phase=Build.FINALIZED) artifact = ArtifactFactory.create(build=build, filename="file1.gz") process_build_dependencies(build.pk) # The project detail should link to the artifact from Jenkins project_url = reverse("project_detail", kwargs={"pk": project.pk}) response = self.app.get(project_url, user="******") self.assertEqual(200, response.status_code) self.assertIsNotNone( response.context["project"].get_current_projectbuild()) self.assertEqual( [ProjectDetailView.item_from_artifact(artifact)], response.context["current_artifacts"]) # Archive the artifact and the view should display the archived item archive = ArchiveFactory.create(policy="cdimage", default=True) items = [] for x in archive.add_build(build)[artifact]: if x.projectbuild_dependency: items.append(ProjectDetailView.item_from_archived_artifact(x)) project_url = reverse("project_detail", kwargs={"pk": project.pk}) response = self.app.get(project_url, user="******") self.assertEqual(200, response.status_code) self.assertEqual(items, response.context["current_artifacts"])
def test_get_transport_for_projectbuild(self): """ get_transport_for_projectbuild returns an Archiver ready to archive a project build. """ archive = ArchiveFactory.create() project = ProjectFactory.create() dependency = DependencyFactory.create() ProjectDependency.objects.create( project=project, dependency=dependency) projectbuild = build_project(project, queue_build=False) mock_policy = mock.Mock() with mock.patch.multiple( archive, get_archiver=mock.DEFAULT, get_policy=mock.DEFAULT) as mock_archive: mock_archive["get_policy"].return_value = mock_policy get_transport_for_projectbuild(projectbuild, archive) mock_policy.assert_called_once_with(projectbuild) mock_archive["get_archiver"].return_value.assert_called_once_with( mock_policy.return_value, archive)