• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.mock_archive函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_search_serializer_mixed_model

    def test_search_serializer_mixed_model(self):

        user = AuthUserFactory()
        project = ProjectFactory(creator=user, is_public=True)
        component = NodeFactory(parent=project, creator=user, is_public=True)
        file_component = utils.create_test_file(component, user)
        context = {'request': make_drf_request_with_version(version='2.0')}
        schema = RegistrationSchema.objects.filter(
            name='Replication Recipe (Brandt et al., 2013): Post-Completion',
            schema_version=LATEST_SCHEMA_VERSION).first()

        # test_search_serializer_mixed_model_project
        result = SearchSerializer(project, context=context).data
        assert result['data']['type'] == 'nodes'

        # test_search_serializer_mixed_model_component
        result = SearchSerializer(component, context=context).data
        assert result['data']['type'] == 'nodes'

        # test_search_serializer_mixed_model_registration
        with mock_archive(project, autocomplete=True, autoapprove=True, schema=schema) as registration:
            result = SearchSerializer(registration, context=context).data
            assert result['data']['type'] == 'registrations'

        # test_search_serializer_mixed_model_file
        result = SearchSerializer(file_component, context=context).data
        assert result['data']['type'] == 'files'

        # test_search_serializer_mixed_model_user
        result = SearchSerializer(user, context=context).data
        assert result['data']['type'] == 'users'
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:31,代码来源:test_serializers.py


示例2: test_archive_success

 def test_archive_success(self):
     node = factories.NodeFactory(creator=self.user)
     file_trees, selected_files, node_index = generate_file_tree([node])
     data = generate_metadata(
         file_trees,
         selected_files,
         node_index
     )
     schema = generate_schema_from_data(data)
     with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
         with mock.patch.object(StorageAddonBase, '_get_file_tree', mock.Mock(return_value=file_trees[node._id])):
             job = factories.ArchiveJobFactory()
             archive_success(registration._id, job._id)
             for key, question in registration.registered_meta[schema._id].items():
                 target = None
                 if isinstance(question.get('value'), dict):
                     target = [v for v in question['value'].values() if 'extra' in v and 'sha256' in v['extra'][0]][0]
                 elif 'extra' in question and 'hashes' in question['extra'][0]:
                     target = question
                 if target:
                     assert_in(registration._id, target['extra'][0]['viewUrl'])
                     assert_not_in(node._id, target['extra'][0]['viewUrl'])
                     del selected_files[target['extra'][0]['sha256']]
                 else:
                     # check non-file questions are unmodified
                     assert_equal(data[key]['value'], question['value'])
             assert_false(selected_files)
开发者ID:atelic,项目名称:osf.io,代码行数:27,代码来源:test_archiver.py


示例3: test_archive_failure_different_name_same_sha

    def test_archive_failure_different_name_same_sha(self):
        file_tree = file_tree_factory(0, 0, 0)
        fake_file = file_factory()
        fake_file2 = file_factory(sha256=fake_file['extra']['hashes']['sha256'])
        file_tree['children'] = [fake_file2]

        node = factories.NodeFactory(creator=self.user)
        data = {
            ('q_' + fake_file['name']): {
                'value': fake.word(),
                'extra': [{
                    'sha256': fake_file['extra']['hashes']['sha256'],
                    'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                        node._id,
                        fake_file['path']
                    ),
                    'selectedFileName': fake_file['name'],
                    'nodeId': node._id
                }]
            }
        }
        schema = generate_schema_from_data(data)
        draft = factories.DraftRegistrationFactory(branched_from=node, registration_schema=schema, registered_metadata=data)

        with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
            with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_tree)):
                job = factories.ArchiveJobFactory(initiator=registration.creator)
                draft.registered_node = registration
                draft.save()
                with assert_raises(ArchivedFileNotFound):
                    archive_success(registration._id, job._id)
开发者ID:adlius,项目名称:osf.io,代码行数:31,代码来源:test_archiver.py


示例4: test_archive_success_different_name_same_sha

    def test_archive_success_different_name_same_sha(self):
        file_tree = file_tree_factory(0, 0, 0)
        fake_file = file_factory()
        fake_file2 = file_factory(sha256=fake_file['extra']['hashes']['sha256'])
        file_tree['children'] = [fake_file, fake_file2]

        node = factories.NodeFactory(creator=self.user)
        data = {
            ('q_' + fake_file['name']): {
                'value': fake.word(),
                'extra': [{
                    'sha256': fake_file['extra']['hashes']['sha256'],
                    'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                        node._id,
                        fake_file['path']
                    ),
                    'selectedFileName': fake_file['name'],
                    'nodeId': node._id
                }]
            }
        }
        schema = generate_schema_from_data(data)

        with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
            with mock.patch.object(StorageAddonBase, '_get_file_tree', mock.Mock(return_value=file_tree)):
                job = factories.ArchiveJobFactory()
                archive_success(registration._id, job._id)
                for key, question in registration.registered_meta[schema._id].items():
                    assert_equal(question['extra'][0]['selectedFileName'], fake_file['name'])
开发者ID:atelic,项目名称:osf.io,代码行数:29,代码来源:test_archiver.py


示例5: test_archive_success_same_file_in_component

    def test_archive_success_same_file_in_component(self):
        file_tree = file_tree_factory(3, 3, 3)
        selected = select_files_from_tree(file_tree).values()[0]

        child_file_tree = file_tree_factory(0, 0, 0)
        child_file_tree['children'] = [selected]

        node = factories.NodeFactory(creator=self.user)
        child = factories.NodeFactory(creator=self.user, parent=node)

        data = {
            ('q_' + selected['name']): {
                'value': fake.word(),
                'extra': [{
                    'sha256': selected['extra']['hashes']['sha256'],
                    'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                        child._id,
                        selected['path']
                    ),
                    'selectedFileName': selected['name'],
                    'nodeId': child._id
                }]
            }
        }
        schema = generate_schema_from_data(data)

        with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
            with mock.patch.object(StorageAddonBase, '_get_file_tree', mock.Mock(return_value=file_tree)):
                job = factories.ArchiveJobFactory()
                archive_success(registration._id, job._id)
                child_reg = registration.nodes[0]
                for key, question in registration.registered_meta[schema._id].items():
                    assert_in(child_reg._id, question['extra'][0]['viewUrl'])
开发者ID:atelic,项目名称:osf.io,代码行数:33,代码来源:test_archiver.py


示例6: test_archive_success_with_deeply_nested_schema

 def test_archive_success_with_deeply_nested_schema(self):
     node = factories.NodeFactory(creator=self.user)
     file_trees, selected_files, node_index = generate_file_tree([node])
     data = {
         ('q_' + selected_file['name']): {
             'value': fake.word(),
             'extra': [{
                 'selectedFileName': selected_file['name'],
                 'nodeId': node._id,
                 'sha256': sha256,
                 'viewUrl': '/project/{0}/files/osfstorage{1}'.format(node._id, selected_file['path'])
             }]
         }
         for sha256, selected_file in selected_files.items()
     }
     schema = generate_schema_from_data(data)
     with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
         with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_trees[node._id])):
             job = factories.ArchiveJobFactory(initiator=registration.creator)
             archive_success(registration._id, job._id)
             registration.reload()
             for key, question in registration.registered_meta[schema._id].items():
                 target = None
                 if isinstance(question['value'], dict):
                     target = [v for v in question['value'].values() if 'extra' in v and 'sha256' in v['extra'][0]][0]
                 elif 'extra' in question and 'sha256' in question['extra'][0]:
                     target = question
                 if target:
                     assert_in(registration._id, target['extra'][0]['viewUrl'])
                     assert_not_in(node._id, target['extra'][0]['viewUrl'])
                     del selected_files[target['extra'][0]['sha256']]
                 else:
                     # check non-file questions are unmodified
                     assert_equal(data[key]['value'], question['value'])
             assert_false(selected_files)
开发者ID:adlius,项目名称:osf.io,代码行数:35,代码来源:test_archiver.py


示例7: test_archive_success_escaped_file_names

    def test_archive_success_escaped_file_names(self):
        file_tree = file_tree_factory(0, 0, 0)
        fake_file = file_factory(name='>and&and<')
        fake_file_name = strip_html(fake_file['name'])
        file_tree['children'] = [fake_file]

        node = factories.NodeFactory(creator=self.user)
        data = {
            ('q_' + fake_file_name): {
                'value': fake.word(),
                'extra': [{
                    'sha256': fake_file['extra']['hashes']['sha256'],
                    'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                        node._id,
                        fake_file['path']
                    ),
                    'selectedFileName': fake_file_name,
                    'nodeId': node._id
                }]
            }
        }
        schema = generate_schema_from_data(data)
        draft = factories.DraftRegistrationFactory(branched_from=node, registration_schema=schema, registered_metadata=data)

        with test_utils.mock_archive(node, schema=schema, data=data, autocomplete=True, autoapprove=True) as registration:
            with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock.Mock(return_value=file_tree)):
                job = factories.ArchiveJobFactory(initiator=registration.creator)
                archive_success(registration._id, job._id)
                registration.reload()
                for key, question in registration.registered_meta[schema._id].items():
                    assert_equal(question['extra'][0]['selectedFileName'], fake_file_name)
开发者ID:adlius,项目名称:osf.io,代码行数:31,代码来源:test_archiver.py


示例8: test_cannot_request_termination_on_component_of_embargo

    def test_cannot_request_termination_on_component_of_embargo(self):
        node = ProjectFactory()
        ProjectFactory(parent=node, creator=node.creator)  # child project

        with utils.mock_archive(node, embargo=True, autocomplete=True, autoapprove=True) as reg:
            with assert_raises(NodeStateError):
                reg._nodes.first().request_embargo_termination(Auth(node.creator))
开发者ID:leb2dg,项目名称:osf.io,代码行数:7,代码来源:test_embargoes.py


示例9: test_is_pending_registration_searches_parents

 def test_is_pending_registration_searches_parents(self):
     user = factories.AuthUserFactory()
     node = factories.NodeFactory(creator=user)
     child = factories.NodeFactory(creator=user, parent=node)
     factories.NodeFactory(creator=user, parent=child)
     with mock_archive(node) as registration:
         sub_reg = registration.nodes[0].nodes[0]
         assert_true(sub_reg.is_pending_registration)
开发者ID:545zhou,项目名称:osf.io,代码行数:8,代码来源:test_sanctions.py


示例10: test_embargo_end_date_searches_parents

 def test_embargo_end_date_searches_parents(self):
     user = factories.AuthUserFactory()
     node = factories.NodeFactory(creator=user)
     child = factories.NodeFactory(creator=user, parent=node)
     factories.NodeFactory(creator=user, parent=child)
     with mock_archive(node, embargo=True) as registration:
         sub_reg = registration.nodes[0].nodes[0]
         assert_equal(sub_reg.embargo_end_date, registration.embargo_end_date)
开发者ID:545zhou,项目名称:osf.io,代码行数:8,代码来源:test_sanctions.py


示例11: test_is_embargoed_searches_parents

 def test_is_embargoed_searches_parents(self):
     user = factories.AuthUserFactory()
     node = factories.NodeFactory(creator=user)
     child = factories.NodeFactory(creator=user, parent=node)
     factories.NodeFactory(creator=user, parent=child)
     with mock_archive(node, embargo=True, autoapprove=True) as registration:
         sub_reg = registration.nodes[0].nodes[0]
         assert_true(sub_reg.is_embargoed)
开发者ID:545zhou,项目名称:osf.io,代码行数:8,代码来源:test_sanctions.py


示例12: test_migrate_registration_extra

 def test_migrate_registration_extra(self):
     with utils.mock_archive(
             self.node,
             schema=self.prereg_schema,
             data=self.data,
             autocomplete=True,
             autoapprove=True
     ) as reg:
         migrate()
         reg.reload()
         data = reg.registered_meta[self.prereg_schema._id]
         assert_true(
             isinstance(data['uploader']['extra'], list)
         )
         assert_true(
             isinstance(
                 data['nested']['value']['uploader']['extra'],
                 list
             )
         )
         assert_true(
             isinstance(
                 data['nested']['value']['question']['extra'],
                 list
             )
         )
         assert_equal(
             self.data['uploader']['extra'],
             data['uploader']['extra'][0]
         )
         assert_equal(
             self.data['nested']['value']['uploader']['extra'],
             data['nested']['value']['uploader']['extra'][0]
         )
         assert_equal(
             self.data['nested']['value']['question']['value'],
             data['nested']['value']['question']['value']
         )
         assert_equal(
             self.data['nested']['value']['other'],
             data['nested']['value']['other']
         )
         assert_equal(
             self.data['other'],
             data['other']
         )
         assert_true(
             data['bad']['extra'][0].get('data', False)
         )
         assert_true(
             isinstance(data['bad']['extra'][0]['data'], dict)
         )
         assert_equal(
             data['bad']['extra'][0]['data']['name'], 'file.txt'
         )
         assert_equal(
             data['bad']['extra'][0]['data']['sha256'], '2413fb3709b05939f04cf2e92f7d0897fc2596f9ad0b8a9ea855c7bfebaae892'
         )
开发者ID:545zhou,项目名称:osf.io,代码行数:58,代码来源:test_migrate_registration_extra.py


示例13: test_sanction_searches_parents

 def test_sanction_searches_parents(self):
     user = factories.AuthUserFactory()
     node = factories.NodeFactory(creator=user)
     child = factories.NodeFactory(creator=user, parent=node)
     factories.NodeFactory(creator=user, parent=child)
     with mock_archive(node) as registration:
         approval = registration.registration_approval
         sub_reg = registration.nodes[0].nodes[0]
         assert_equal(sub_reg.sanction, approval)
开发者ID:545zhou,项目名称:osf.io,代码行数:9,代码来源:test_sanctions.py


示例14: test_is_registration_approved_searches_parents

 def test_is_registration_approved_searches_parents(self):
     user = factories.AuthUserFactory()
     node = factories.NodeFactory(creator=user)
     child = factories.NodeFactory(creator=user, parent=node)
     factories.NodeFactory(creator=user, parent=child)
     with mock_archive(node) as registration:
         with mock.patch('website.project.sanctions.Sanction.is_approved', mock.Mock(return_value=True)):
             sub_reg = registration.nodes[0].nodes[0]
             assert_true(sub_reg.is_registration_approved)
开发者ID:545zhou,项目名称:osf.io,代码行数:9,代码来源:test_sanctions.py


示例15: setUp

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

        self.user = factories.AuthUserFactory()
        self.node = factories.ProjectFactory(creator=self.user)
        with mock_archive(self.node, embargo=True, autoapprove=True) as registration:
            self.registration = registration

        self.not_embargoed = factories.RegistrationFactory()
开发者ID:545zhou,项目名称:osf.io,代码行数:9,代码来源:test_sanctions.py


示例16: setUp

    def setUp(self):
        super(TestApproveEmbargoTerminations, self).setUp()
        self.user = AuthUserFactory()

        self.node = NodeFactory(creator=self.user)
        NodeFactory(
            creator=self.user,
            parent=NodeFactory(creator=self.user, parent=self.node)
        )

        # requesting termination but less than 48 hours old
        with mock_archive(self.node, embargo=True, autoapprove=True) as registration:
            registration.request_embargo_termination(auth=Auth(self.user))
            self.registration1 = registration

        # requesting termination and older than 48 hours
        with mock_archive(self.node, embargo=True, autoapprove=True) as registration:
            old_time = datetime.now() - timedelta(days=5)
            approval = registration.request_embargo_termination(auth=Auth(self.user))
            EmbargoTerminationApproval._storage[0].store.update(
                {'_id': approval._id},
                {'$set': {'initiation_date': old_time}},
            )
            self.registration2 = registration

        # requesting termination and older than 48 hours, but approved
        with mock_archive(self.node, embargo=True, autoapprove=True) as registration:
            old_time = datetime.now() - timedelta(days=5)
            approval = registration.request_embargo_termination(auth=Auth(self.user))
            EmbargoTerminationApproval._storage[0].store.update(
                {'_id': approval._id},
                {'$set': {'initiation_date': old_time}},
            )
            approval.state = Sanction.APPROVED
            approval.save()
            self.registration3 = registration

        # embargoed but not requesting termination
        with mock_archive(self.node, embargo=True, autoapprove=True) as registration:
            self.registration4 = registration

        EmbargoTerminationApproval._clear_caches()
开发者ID:545zhou,项目名称:osf.io,代码行数:42,代码来源:test_approve_embargo_terminations.py


示例17: setUp

    def setUp(self):
        super(TestSearchRegistrations, self).setUp()
        self.url = '/{}search/registrations/'.format(API_BASE)

        ensure_schemas()
        self.schema = MetaSchema.find_one(
            Q('name', 'eq', 'Replication Recipe (Brandt et al., 2013): Post-Completion') &
            Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
        )

        with mock_archive(self.project, autocomplete=True, autoapprove=True, schema=self.schema) as registration:
            self.registration = registration

        with mock_archive(self.project_two, autocomplete=True, autoapprove=True,
                          schema=self.schema) as registration_two:
            self.registration_two = registration_two

        with mock_archive(self.private_project, autocomplete=True, autoapprove=True,
                          schema=self.schema) as private_registration:
            self.private_registration = private_registration

        self.private_registration.is_public = False
        self.private_registration.save()
开发者ID:alexschiller,项目名称:osf.io,代码行数:23,代码来源:test_views.py


示例18: setUp

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

        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user, is_public=True)
        self.component = NodeFactory(parent=self.project, creator=self.user, is_public=True)
        self.file = utils.create_test_file(self.component, self.user)

        self.schema = MetaSchema.find_one(
            Q('name', 'eq', 'Replication Recipe (Brandt et al., 2013): Post-Completion') &
            Q('schema_version', 'eq', LATEST_SCHEMA_VERSION)
        )

        with mock_archive(self.project, autocomplete=True, autoapprove=True, schema=self.schema) as registration:
            self.registration = registration
开发者ID:adlius,项目名称:osf.io,代码行数:15,代码来源:test_serializers.py


示例19: setUp

 def setUp(self):
     super(TestRegistrationRetractions, self).setUp()
     self.user = factories.UserFactory(usename='Doug Bogie')
     self.title = 'Red Special'
     self.consolidate_auth = Auth(user=self.user)
     self.project = factories.ProjectFactory(
         title=self.title,
         creator=self.user,
         is_public=True,
     )
     with mock_archive(
             self.project,
             autocomplete=True,
             autoapprove=True
     ) as registration:
         self.registration = registration
开发者ID:baylee-d,项目名称:osf.io,代码行数:16,代码来源:test_elastic.py


示例20: test_archive_success_with_components

    def test_archive_success_with_components(self):
        node = factories.NodeFactory(creator=self.user)
        comp1 = factories.NodeFactory(parent=node, creator=self.user)
        factories.NodeFactory(parent=comp1, creator=self.user)
        factories.NodeFactory(parent=node, creator=self.user)
        nodes = [n for n in node.node_and_primary_descendants()]
        file_trees, selected_files, node_index = generate_file_tree(nodes)
        data = generate_metadata(
            file_trees,
            selected_files,
            node_index
        )
        schema = generate_schema_from_data(data)

        with test_utils.mock_archive(node, schema=schema, data=copy.deepcopy(data), autocomplete=True, autoapprove=True) as registration:
            def mock_get_file_tree(self, *args, **kwargs):
                return file_trees[self.owner.registered_from._id]
            with mock.patch.object(BaseStorageAddon, '_get_file_tree', mock_get_file_tree):
                job = factories.ArchiveJobFactory(initiator=registration.creator)
                archive_success(registration._id, job._id)

            registration.reload()

            for key, question in registration.registered_meta[schema._id].items():
                target = None
                if isinstance(question['value'], dict):
                    target = [v for v in question['value'].values() if 'extra' in v and 'sha256' in v['extra'][0]]
                elif 'extra' in question and 'sha256' in question['extra']:
                    target = question

                if target:
                    node_id = re.search(
                        r'^/project/(?P<node_id>\w{5}).+$',
                        target[0]['extra'][0]['viewUrl']
                    ).groupdict()['node_id']
                    assert_in(
                        node_id,
                        [r._id for r in registration.node_and_primary_descendants()]
                    )
                    if target[0]['extra'][0]['sha256'] in selected_files:
                        del selected_files[target[0]['extra'][0]['sha256']]
                else:
                    # check non-file questions are unmodified
                    assert_equal(data[key]['value'], question['value'])
            # ensure each selected file was checked
            assert_false(selected_files)
开发者ID:adlius,项目名称:osf.io,代码行数:46,代码来源:test_archiver.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.mock_http函数代码示例发布时间:2022-05-27
下一篇:
Python utils.make_drf_request_with_version函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap