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


Python NodeFactory.has_addon方法代码示例

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


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

示例1: test_node_serializer

# 需要导入模块: from osf_tests.factories import NodeFactory [as 别名]
# 或者: from osf_tests.factories.NodeFactory import has_addon [as 别名]
    def test_node_serializer(self, user):

        #   test_node_serialization
        parent = ProjectFactory(creator=user)
        node = NodeFactory(creator=user, parent=parent)
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(node, context={'request': req}).data
        data = result['data']
        assert data['id'] == node._id
        assert data['type'] == 'nodes'

        # Attributes
        attributes = data['attributes']
        assert attributes['title'] == node.title
        assert attributes['description'] == node.description
        assert attributes['public'] == node.is_public
        assert set(attributes['tags']) == set(node.tags.values_list('name', flat=True))
        assert not attributes['current_user_can_comment']
        assert attributes['category'] == node.category
        assert attributes['registration'] == node.is_registration
        assert attributes['fork'] == node.is_fork
        assert attributes['collection'] == node.is_collection
        assert attributes['analytics_key'] == node.keenio_read_key
        assert attributes['wiki_enabled'] == node.has_addon('wiki')

        # Relationships
        relationships = data['relationships']
        assert 'region' in relationships
        assert 'children' in relationships
        assert 'contributors' in relationships
        assert 'files' in relationships
        assert 'parent' in relationships
        assert 'affiliated_institutions' in relationships
        assert 'registrations' in relationships
        assert 'forked_from' not in relationships
        parent_link = relationships['parent']['links']['related']['href']
        assert urlparse(
            parent_link).path == '/{}nodes/{}/'.format(API_BASE, parent._id)

    #   test_fork_serialization
        node = NodeFactory(creator=user)
        fork = node.fork_node(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        forked_from = relationships['forked_from']['links']['related']['href']
        assert urlparse(
            forked_from).path == '/{}nodes/{}/'.format(API_BASE, node._id)

    #   test_template_serialization
        node = NodeFactory(creator=user)
        fork = node.use_as_template(auth=Auth(user))
        req = make_drf_request_with_version(version='2.0')
        result = NodeSerializer(fork, context={'request': req}).data
        data = result['data']

        # Relationships
        relationships = data['relationships']
        templated_from = relationships['template_node']['links']['related']['href']
        assert urlparse(
            templated_from).path == '/{}nodes/{}/'.format(API_BASE, node._id)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:66,代码来源:test_serializers.py


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