def test_archive_artifact_from_finalized_dependency_build(self): """ archive_artifact_from_jenkins should get a transport, and then call start, end and archive_artifact on the transport. the correct storage. """ archive = ArchiveFactory.create( transport="local", basedir=self.basedir) dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) artifact = ArtifactFactory.create( build=build, filename="testing/testing.txt") [item] = archive.add_build(artifact.build)[artifact] transport = LoggingTransport(archive) with mock.patch.object( Archive, "get_transport", return_value=transport): archive_artifact_from_jenkins(item.pk) self.assertEqual( ["START", "%s -> %s root:testing" % (artifact.url, item.archived_path), "Make %s current" % item.archived_path, "END"], transport.log)
def test_archive_artifact_from_jenkins_transport_lifecycle(self): """ archive_artifact_from_jenkins should get a transport, and copy the file to the correct storage. """ archive = ArchiveFactory.create( transport="local", basedir=self.basedir) dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) artifact = ArtifactFactory.create( build=build, filename="testing/testing.txt") archive.add_build(artifact.build) [item] = list(archive.get_archived_artifacts_for_build(build)) self.assertIsNone(item.archived_at) transport = LoggingTransport(archive) with mock.patch.object( Archive, "get_transport", return_value=transport): archive_artifact_from_jenkins(item.pk) [item] = list(archive.get_archived_artifacts_for_build(build)) self.assertEqual( ["START", "%s -> %s root:testing" % (artifact.url, item.archived_path), "Make %s current" % item.archived_path, "END"], transport.log) self.assertIsNotNone(item.archived_at)
def test_archive_artifact_from_jenkins(self): """ archive_artifact_from_jenkins should get a transport, and then call start, end and archive_artifact on the transport. the correct storage. """ archive = ArchiveFactory.create( transport="local", basedir=self.basedir) dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) artifact = ArtifactFactory.create( build=build, filename="testing/testing.txt") items = archive.add_build(artifact.build) fakefile = StringIO(u"Artifact from Jenkins") with mock.patch("archives.transports.urllib2") as urllib2_mock: urllib2_mock.urlopen.return_value = fakefile archive_artifact_from_jenkins(items[artifact][0].pk) [item] = list(archive.get_archived_artifacts_for_build(build)) filename = os.path.join(self.basedir, item.archived_path) self.assertEqual(file(filename).read(), "Artifact from Jenkins") self.assertEqual(21, item.archived_size)
def test_archive_artifact_from_finalized_dependency_build(self): """ archive_artifact_from_jenkins should get a transport, and then call start, end and archive_artifact on the transport. the correct storage. """ archive = ArchiveFactory.create(transport="local", basedir=self.basedir) dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) artifact = ArtifactFactory.create(build=build, filename="testing/testing.txt") [item] = archive.add_build(artifact.build)[artifact] transport = LoggingTransport(archive) with mock.patch.object(Archive, "get_transport", return_value=transport): archive_artifact_from_jenkins(item.pk) self.assertEqual([ "START", "%s -> %s root:testing" % (artifact.url, item.archived_path), "Make %s current" % item.archived_path, "END" ], transport.log)
def test_archive_artifact_from_jenkins(self): """ archive_artifact_from_jenkins should get a transport, and then call start, end and archive_artifact on the transport. the correct storage. """ archive = ArchiveFactory.create(transport="local", basedir=self.basedir) dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) artifact = ArtifactFactory.create(build=build, filename="testing/testing.txt") items = archive.add_build(artifact.build) fakefile = StringIO(u"Artifact from Jenkins") with mock.patch("archives.transports.urllib2") as urllib2_mock: urllib2_mock.urlopen.return_value = fakefile archive_artifact_from_jenkins(items[artifact][0].pk) [item] = list(archive.get_archived_artifacts_for_build(build)) filename = os.path.join(self.basedir, item.archived_path) self.assertEqual(file(filename).read(), "Artifact from Jenkins") self.assertEqual(21, item.archived_size)
def test_archive_artifact_from_jenkins_transport_lifecycle(self): """ archive_artifact_from_jenkins should get a transport, and copy the file to the correct storage. """ archive = ArchiveFactory.create(transport="local", basedir=self.basedir) dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) artifact = ArtifactFactory.create(build=build, filename="testing/testing.txt") archive.add_build(artifact.build) [item] = list(archive.get_archived_artifacts_for_build(build)) self.assertIsNone(item.archived_at) transport = LoggingTransport(archive) with mock.patch.object(Archive, "get_transport", return_value=transport): archive_artifact_from_jenkins(item.pk) [item] = list(archive.get_archived_artifacts_for_build(build)) self.assertEqual([ "START", "%s -> %s root:testing" % (artifact.url, item.archived_path), "Make %s current" % item.archived_path, "END" ], transport.log) self.assertIsNotNone(item.archived_at)
def test_archive_artifact_from_non_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) build = BuildFactory.create(job=dependency1.job, build_id=projectbuild.build_key, phase=Build.FINALIZED) ProjectBuildDependency.objects.create(build=build, projectbuild=projectbuild, dependency=dependency1) 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) item = [ x for x in archive.add_build(artifact.build)[artifact] if x.projectbuild_dependency ][0] transport = LoggingTransport(archive) with mock.patch.object(Archive, "get_transport", return_value=transport): archive_artifact_from_jenkins(item.pk) self.assertEqual([ "START", "%s -> %s root:testing" % (artifact.url, item.archived_path), "END" ], transport.log)
def test_archive_artifact_from_non_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) build = BuildFactory.create( job=dependency1.job, build_id=projectbuild.build_key, phase=Build.FINALIZED) ProjectBuildDependency.objects.create( build=build, projectbuild=projectbuild, dependency=dependency1) 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) item = [x for x in archive.add_build(artifact.build)[artifact] if x.projectbuild_dependency][0] transport = LoggingTransport(archive) with mock.patch.object( Archive, "get_transport", return_value=transport): archive_artifact_from_jenkins(item.pk) self.assertEqual( ["START", "%s -> %s root:testing" % (artifact.url, item.archived_path), "END"], transport.log)
def test_archive_artifact_from_jenkins(self): """ archive_artifact_from_jenkins should get a transport, and then call start, end and archive_artifact on the transport. the correct storage. """ archive = ArchiveFactory.create( transport="local", basedir=self.basedir) artifact = ArtifactFactory.create(filename="testing/testing.txt") archive.add_artifact(artifact) fakefile = StringIO(u"Artifact from Jenkins") with mock.patch("archives.transports.urllib2") as urllib2_mock: urllib2_mock.urlopen.return_value = fakefile archive_artifact_from_jenkins(artifact.pk, archive.pk) item = archive.get_archived_artifact(artifact) filename = os.path.join(self.basedir, item.archived_path) self.assertEqual(file(filename).read(), "Artifact from Jenkins")
def test_archive_artifact_from_jenkins_transport_lifecycle(self): """ archive_artifact_from_jenkins should get a transport, and copy the file to the correct storage. """ archive = ArchiveFactory.create( transport="local", basedir=self.basedir) artifact = ArtifactFactory.create(filename="testing/testing.txt") item = archive.add_artifact(artifact) self.assertIsNone(item.archived_at) transport = LoggingTransport(archive) with mock.patch.object(Archive, "get_transport", return_value=transport) as archive_mock: archive_artifact_from_jenkins(artifact.pk, archive.pk) self.assertEqual( ["START", "%s -> testing/testing.txt root:testing" % artifact.url, "END"], transport.log) item = archive.get_archived_artifact(artifact) self.assertIsNotNone(item.archived_at)