当前位置: 首页>>代码示例>>Python>>正文


Python factories.ProjectFactory类代码示例

本文整理汇总了Python中projects.tests.factories.ProjectFactory的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory类的具体用法?Python ProjectFactory怎么用?Python ProjectFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ProjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_new_project_no_permissions

def test_new_project_no_permissions():
    user, organization, client = setup()
    assert login(client, user)

    assert len(user.get_projects()) == 0
    response = client.post(
        path=reverse('projects:new_project'),
        data={
        },
    )
    assert response.status_code == HTTP_403_FORBIDDEN

    project = ProjectFactory(organization=organization)
    project.add_manage(user)
    assert len(user.get_projects()) == 1
    response = client.post(
        path=reverse('projects:new_project'),
        data={
            'name': 'Test Project',
            'description': 'Test Description',
            'organization': organization.pk
        },
    )
    assert response.status_code == HTTP_403_FORBIDDEN
    assert len(user.get_projects()) == 1
开发者ID:bgroff,项目名称:kala-app,代码行数:25,代码来源:test_new_project.py

示例2: test_cdimage_archiver_policy

    def test_cdimage_archiver_policy(self):
        """
        If we use the cdimage policy, then the file path is quite different.
        """
        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)

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

        archive.add_artifact(
            artifact, projectbuild=projectbuild)
        archived = archive.get_archived_artifact(artifact)
        self.assertEqual(artifact, archived.artifact)
        self.assertEqual(
            "%s/%s/testing.gz" % (
                slugify(project.name), projectbuild.build_id),
            archived.archived_path)
        self.assertIsNone(archived.archived_at)
开发者ID:notnownikki,项目名称:capomastro,代码行数:26,代码来源:test_models.py

示例3: test_archive_projectbuild_with_prearchived_artifact

    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))
开发者ID:notnownikki,项目名称:capomastro,代码行数:30,代码来源:test_models.py

示例4: test_archive_projectbuild

    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))
开发者ID:notnownikki,项目名称:capomastro,代码行数:28,代码来源:test_models.py

示例5: test_generate_checksums

    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")
开发者ID:bigkevmcd,项目名称:capomastro,代码行数:30,代码来源:test_transports.py

示例6: setup

def setup():
    user = UserFactory.create()
    organization = OrganizationFactory.create()
    project = ProjectFactory.create(organization=organization)
    document = DocumentFactory.create(project=project)

    return user, organization, project, document, Client()
开发者ID:bgroff,项目名称:kala-app,代码行数:7,代码来源:__init__.py

示例7: test_process_build_artifacts

    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")
开发者ID:bigkevmcd,项目名称:capomastro,代码行数:35,代码来源:test_tasks.py

示例8: test_process_build_artifacts_with_no_default_archive

    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)))
开发者ID:bigkevmcd,项目名称:capomastro,代码行数:35,代码来源:test_tasks.py

示例9: test_generate_checksums

    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)
开发者ID:bigkevmcd,项目名称:capomastro,代码行数:33,代码来源:test_tasks.py

示例10: test_generate_checksums_no_transport

    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")
开发者ID:bigkevmcd,项目名称:capomastro,代码行数:29,代码来源:test_tasks.py

示例11: test_build_with_several_projectbuild_dependencies

    def test_build_with_several_projectbuild_dependencies(self):
        """
        A build of dependency that's autotracked by several projects should
        trigger creation of all projectbuilds correctly.
        """
        project1, dependency = self.create_dependencies()
        project2 = ProjectFactory.create()
        ProjectDependency.objects.create(project=project2,
                                         dependency=dependency)

        projectbuild = build_project(project1, queue_build=False)

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

        process_build_dependencies(build.pk)

        self.assertEqual(
            [dependency, dependency],
            sorted([b.dependency for b in
                    ProjectBuildDependency.objects.all()]))
        self.assertEqual(
            [build, build],
            sorted([b.build for b in
                    ProjectBuildDependency.objects.all()]))
开发者ID:devton,项目名称:capomastro,代码行数:25,代码来源:test_tasks.py

示例12: test_link_artifact_in_archive

    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)
开发者ID:bigkevmcd,项目名称:capomastro,代码行数:32,代码来源:test_tasks.py

示例13: test_user_has_document_permissions

def test_user_has_document_permissions():
    user = UserFactory.create()

    organization = OrganizationFactory.create()
    project = ProjectFactory.create(organization=organization)
    document = DocumentFactory.create(project=project)
    document.add_create(user)

    assert len(user.get_organizations()) == 1
    assert len(user.get_projects()) == 1
    assert len(user.get_documents()) == 1

    assert organization.can_manage(user) == False
    assert organization.can_invite(user) == False
    assert organization.can_create(user) == False

    assert project.can_invite(user) == False
    assert project.can_create(user) == False
    assert project.can_manage(user) == False

    assert document.can_create(user) == True
    assert document.can_invite(user) == False
    assert document.can_manage(user) == False

    document.delete_create(user)
    document.add_invite(user)
    assert document.can_create(user) == True
    assert document.can_invite(user) == True
    assert document.can_manage(user) == False

    document.delete_invite(user)
    document.add_manage(user)
    assert document.can_create(user) == True
    assert document.can_invite(user) == True
    assert document.can_manage(user) == True
开发者ID:bgroff,项目名称:kala-app,代码行数:35,代码来源:test_permissions.py

示例14: test_remove_hook_if_need

 def test_remove_hook_if_need(self):
     """Test remove hook if need"""
     project = ProjectFactory.create(run_here=False)
     site = Site.objects.get_current()
     url = 'https://{}/api/v1/nodes/hook/'.format(site.domain)
     hook = MagicMock(config={'url': url})
     project.repo.get_hooks.return_value = [hook]
     project.save()
     hook.delete.call_count.should.be.equal(1)
开发者ID:michaeljoseph,项目名称:coviolations_web,代码行数:9,代码来源:test_models.py

示例15: test_user_has_superuser

def test_user_has_superuser():
    user = UserFactory.create(is_superuser=True)

    organization = OrganizationFactory.create()
    project = ProjectFactory.create(organization=organization)
    DocumentFactory.create(project=project)
    UserFactory.create()

    assert len(user.get_organizations()) == 1
    assert len(user.get_projects()) == 1
    assert len(user.get_documents()) == 1
    assert len(user.get_users()) == 2
开发者ID:bgroff,项目名称:kala-app,代码行数:12,代码来源:test_permissions.py


注:本文中的projects.tests.factories.ProjectFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。