本文整理汇总了Python中jenkins.tests.factories.ArtifactFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python ArtifactFactory.create方法的具体用法?Python ArtifactFactory.create怎么用?Python ArtifactFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jenkins.tests.factories.ArtifactFactory
的用法示例。
在下文中一共展示了ArtifactFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_generate_checksums_no_transport
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_generate_checksums_no_transport(self):
"""
generate_checksums should call the generate_checksums method
on the transport from the archive with the build to generate
the checksums for. If there is no default archive, a checksum
cannot be calculated and there should be an early exit.
"""
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)
ProjectBuildDependency.objects.create(
build=build, projectbuild=projectbuild, dependency=dependency)
ArtifactFactory.create(build=build, filename="testing/testing.txt")
# No archive defined
transport = LoggingTransport(None)
# Mock the logger
with mock.patch.object(logging, "info", return_value=None) as mock_log:
return_value = generate_checksums(build.pk)
self.assertEqual([], transport.log)
self.assertEqual(build.pk, return_value)
mock_log.assert_called_once_with(
"No default archiver - no checksum to generate")
示例2: test_process_build_artifacts
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_process_build_artifacts(self):
"""
process_build_artifacts is chained from the Jenkins postbuild
processing, it should arrange for the artifacts for the provided build
to be archived in the default archive.
"""
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)
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,
policy="cdimage")
with mock.patch("archives.transports.urllib2") as urllib2_mock:
urllib2_mock.urlopen.side_effect = lambda x: StringIO(
u"Artifact from Jenkins")
process_build_artifacts(build.pk)
[item1, item2] = list(archive.get_archived_artifacts_for_build(build))
filename = os.path.join(self.basedir, item1.archived_path)
self.assertEqual(file(filename).read(), "Artifact from Jenkins")
filename = os.path.join(self.basedir, item2.archived_path)
self.assertEqual(file(filename).read(), "Artifact from Jenkins")
示例3: test_cdimage_archiver_policy
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
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)))
示例4: test_artifact_get_url
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
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())
示例5: test_archive_build_projectbuild
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_archive_build_projectbuild(self):
"""
The archiver can handle archiving a build from a projectbuild.
"""
project, dependency1, dependency2 = self.create_dependencies(2)
ProjectDependency.objects.create(
project=project, dependency=dependency2)
projectbuild = build_project(project, queue_build=False)
archive = ArchiveFactory.create(policy="cdimage")
build1 = BuildFactory.create(
job=dependency1.job, build_id=projectbuild.build_key)
artifact1 = ArtifactFactory.create(
build=build1, filename="artifact1.gz")
update_projectbuilds(build1)
build1_items = archive.add_build(build1)
self.assertEqual(2, len(build1_items[artifact1]))
build2 = BuildFactory.create(
job=dependency2.job, build_id=projectbuild.build_key)
artifact2 = ArtifactFactory.create(build=build2, filename="artifact2.gz")
update_projectbuilds(build2)
build2_items = archive.add_build(build2)
self.assertEqual(2, len(build2_items[artifact2]))
self.assertEqual(4, archive.items.count())
self.assertEqual(
2,
ArchiveArtifact.objects.filter(
projectbuild_dependency__projectbuild=projectbuild).count())
示例6: test_archive_projectbuild_with_prearchived_artifact
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_archive_projectbuild_with_prearchived_artifact(self):
"""
If we archive a project build with several artifacts, it should return
only the newly added artifacts.
"""
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)
build2 = BuildFactory.create(
job=dependency2.job, build_id=projectbuild.build_key)
ArtifactFactory.create(build=build1, filename="artifact1.gz")
artifact = ArtifactFactory.create(
build=build2, filename="artifact2.gz")
archive = ArchiveFactory.create()
archive.add_artifact(artifact, projectbuild=projectbuild)
result = archive.archive_projectbuild(projectbuild)
self.assertEqual(2, archive.items.count())
self.assertEqual(1, len(result))
示例7: test_archive_projectbuild
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_archive_projectbuild(self):
"""
The archiver can handle archiving an entire project build.
"""
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)
build2 = BuildFactory.create(
job=dependency2.job, build_id=projectbuild.build_key)
ArtifactFactory.create(build=build1, filename="artifact1.gz")
ArtifactFactory.create(build=build2, filename="artifact2.gz")
archive = ArchiveFactory.create()
result = archive.archive_projectbuild(projectbuild)
self.assertEqual(2, archive.items.count())
self.assertEqual(2, len(result))
示例8: test_process_build_artifacts_with_no_default_archive
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_process_build_artifacts_with_no_default_archive(self):
"""
If we have no default archive, we should log the fact that we can't
automatically archive 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)
ArtifactFactory.create(
build=build, filename="testing/testing.txt")
archive = ArchiveFactory.create(
transport="local", basedir=self.basedir, default=False)
with mock.patch("archives.tasks.logging") as mock_logging:
result = process_build_artifacts.delay(build.pk)
# We must return the build.pk for further chained calls to work.
self.assertEqual(build.pk, result.get())
mock_logging.assert_has_calls([
mock.call.info(
"Processing build artifacts from build %s %d",
build, build.number),
mock.call.info(
"No default archiver - build not automatically archived.")
])
self.assertEqual(
[],
list(archive.get_archived_artifacts_for_build(build)))
示例9: test_get_archived_artifact_artifact_not_in_archive
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_get_archived_artifact_artifact_not_in_archive(self):
"""
If the specified build is not recorded in the archive then we should
get an empty set back.
"""
dependency = DependencyFactory.create()
build = BuildFactory.create(job=dependency.job)
ArtifactFactory.create(build=build)
archive = ArchiveFactory.create()
self.assertEqual(
0,
archive.get_archived_artifacts_for_build(build).count())
示例10: test_generate_checksums
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_generate_checksums(self):
"""
generate_checksums should call the generate_checksums method
on the transport from the archive with the build to generate
the checksums for.
"""
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)
projectbuild_dependency = ProjectBuildDependency.objects.create(
build=build, projectbuild=projectbuild, dependency=dependency)
artifact = ArtifactFactory.create(
build=build, filename="testing/testing.txt")
archive = ArchiveFactory.create(
transport="local", basedir=self.basedir, default=True)
archived_artifact = ArchiveArtifact.objects.create(
build=build, archive=archive, artifact=artifact,
archived_path="/srv/builds/200101.01/artifact_filename",
projectbuild_dependency=projectbuild_dependency)
transport = LoggingTransport(archive)
with mock.patch.object(
Archive, "get_transport", return_value=transport):
generate_checksums(build.pk)
self.assertEqual(
["START", "Checksums generated for %s" % archived_artifact, "END"],
transport.log)
示例11: test_archive_artifact_from_jenkins_transport_lifecycle
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
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)
示例12: test_generate_checksums
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
def test_generate_checksums(self):
"""
generate_checksums should send commands to the ssh client
to generate an sha256sum for the passed in archived artifact.
"""
# a project with a build and an archived artifact
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)
projectbuild_dependency = ProjectBuildDependency.objects.create(
build=build, projectbuild=projectbuild, dependency=dependency)
artifact = ArtifactFactory.create(
build=build, filename="artifact_filename")
archived_artifact = ArchiveArtifact.objects.create(
build=build, archive=self.archive, artifact=artifact,
archived_path="/srv/builds/200101.01/artifact_filename",
projectbuild_dependency=projectbuild_dependency)
transport = SshTransport(self.archive)
with mock.patch.object(transport, "_run_command") as mock_run:
transport.generate_checksums(archived_artifact)
mock_run.assert_called_once_with(
"cd `dirname /var/tmp/srv/builds/200101.01/artifact_filename` "
"&& sha256sum artifact_filename >> SHA256SUMS")
示例13: test_link_artifact_in_archive
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
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)
示例14: test_project_build_detail_view_with_archived_artifacts
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
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="testing")
self.assertEqual(items, list(response.context["archived_items"]))
示例15: test_archive_artifact_from_finalized_dependency_build
# 需要导入模块: from jenkins.tests.factories import ArtifactFactory [as 别名]
# 或者: from jenkins.tests.factories.ArtifactFactory import create [as 别名]
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)