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


Python ProjectFactory.set_preprint_file方法代码示例

本文整理汇总了Python中tests.factories.ProjectFactory.set_preprint_file方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.set_preprint_file方法的具体用法?Python ProjectFactory.set_preprint_file怎么用?Python ProjectFactory.set_preprint_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.factories.ProjectFactory的用法示例。


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

示例1: TestSetPreprintFile

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import set_preprint_file [as 别名]
class TestSetPreprintFile(OsfTestCase):

    def setUp(self):
        super(TestSetPreprintFile, self).setUp()

        self.user = AuthUserFactory()
        self.auth = Auth(user=self.user)
        self.read_write_user = AuthUserFactory()
        self.read_write_user_auth = Auth(user=self.read_write_user)

        self.project = ProjectFactory(creator=self.user)
        self.file = OsfStorageFile.create(
            is_file=True,
            node=self.project,
            path='/panda.txt',
            name='panda.txt',
            materialized_path='/panda.txt')
        self.file.save()

        self.file_two = OsfStorageFile.create(
            is_file=True,
            node=self.project,
            path='/pandapanda.txt',
            name='pandapanda.txt',
            materialized_path='/pandapanda.txt')
        self.file_two.save()

        self.project.add_contributor(self.read_write_user, permissions=[permissions.WRITE])
        self.project.save()

    @assert_logs(NodeLog.MADE_PUBLIC, 'project')
    @assert_logs(NodeLog.PREPRINT_INITIATED, 'project', -2)
    def test_is_preprint_property_new_file(self):
        self.project.set_preprint_file(self.file, auth=self.auth, save=True)
        self.project.reload()
        assert_true(self.project.is_preprint)

    def test_project_made_public(self):
        assert_false(self.project.is_public)
        self.project.set_preprint_file(self.file, auth=self.auth, save=True)
        assert_true(self.project.is_public)

    def test_add_primary_file(self):
        self.project.set_preprint_file(self.file, auth=self.auth, save=True)
        assert_equal(self.project.preprint_file, self.file)
        assert_equal(type(self.project.preprint_file), type(self.file.stored_object))

    @assert_logs(NodeLog.PREPRINT_FILE_UPDATED, 'project')
    def test_change_primary_file(self):
        self.project.set_preprint_file(self.file, auth=self.auth, save=True)
        assert_equal(self.project.preprint_file, self.file)

        self.project.set_preprint_file(self.file_two, auth=self.auth, save=True)
        assert_equal(self.project.preprint_file._id, self.file_two._id)

    def test_add_invalid_file(self):
        with assert_raises(AttributeError):
            self.project.set_preprint_file('inatlanta', auth=self.auth, save=True)

    def test_preprint_created_date(self):
        self.project.set_preprint_file(self.file, auth=self.auth, save=True)
        assert_equal(self.project.preprint_file._id, self.file._id)

        assert(self.project.preprint_created)
        assert_not_equal(self.project.date_created, self.project.preprint_created)

    def test_non_admin_update_file(self):
        self.project.set_preprint_file(self.file, auth=self.auth, save=True)
        assert_equal(self.project.preprint_file._id, self.file._id)

        with assert_raises(PermissionsError):
            self.project.set_preprint_file(self.file_two, auth=self.read_write_user_auth, save=True)
        assert_equal(self.project.preprint_file._id, self.file._id)
开发者ID:monikagrabowska,项目名称:osf.io,代码行数:75,代码来源:test_preprints.py


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