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


Python fake.word函数代码示例

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


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

示例1: test_do_not_create_public_wiki_page

    def test_do_not_create_public_wiki_page(
        self, app, user_creator, user_read_contributor, user_non_contributor,
        url_node_public, wiki_public
    ):
        # test_do_not_create_home_wiki_page
        res = app.post_json_api(url_node_public, create_wiki_payload('home'), auth=user_creator.auth, expect_errors=True)
        assert res.status_code == 409
        assert res.json['errors'][0]['detail'] == "A wiki page with the name 'home' already exists."

        # test_do_not_create_wiki_page_name_exists
        res = app.post_json_api(url_node_public, create_wiki_payload(wiki_public.page_name), auth=user_creator.auth, expect_errors=True)
        assert res.status_code == 409
        assert res.json['errors'][0]['detail'] == "A wiki page with the name '{}' already exists.".format(wiki_public.page_name)

        # test_do_not_create_public_wiki_page_as_read_contributor
        res = app.post_json_api(url_node_public, create_wiki_payload(fake.word()), auth=user_read_contributor.auth, expect_errors=True)
        assert res.status_code == 403

        # test_do_not_create_public_wiki_page_as_non_contributor
        res = app.post_json_api(url_node_public, create_wiki_payload(fake.word()), auth=user_non_contributor.auth, expect_errors=True)
        assert res.status_code == 403

        # test_do_not_create_public_wiki_page_as_unauthenticated
        res = app.post_json_api(url_node_public, create_wiki_payload(fake.word()), expect_errors=True)
        assert res.status_code == 401
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:25,代码来源:test_node_wiki_list.py

示例2: test_send_with_sendgrid_success

    def test_send_with_sendgrid_success(self):
        mock_client = mock.MagicMock()
        mock_client.send.return_value = 200, 'success'
        from_addr, to_addr = fake_email(), fake_email()
        category1, category2 = fake.word(), fake.word()
        subject = fake.bs()
        message = fake.text()
        ret = _send_with_sendgrid(
            from_addr=from_addr,
            to_addr=to_addr,
            subject=subject,
            message=message,
            mimetype='html',
            client=mock_client,
            categories=(category1, category2)
        )
        assert_true(ret)

        assert_equal(mock_client.send.call_count, 1)
        # First call's argument should be a Mail object with
        # the correct configuration
        first_call_arg = mock_client.send.call_args[0][0]
        assert_is_instance(first_call_arg, sendgrid.Mail)
        assert_equal(first_call_arg.from_email, from_addr)
        assert_equal(first_call_arg.to[0], to_addr)
        assert_equal(first_call_arg.subject, subject)
        assert_in(message, first_call_arg.html)
        # Categories are set
        assert_equal(first_call_arg.smtpapi.data['category'], (category1, category2))
开发者ID:erinspace,项目名称:osf.io,代码行数:29,代码来源:test_email.py

示例3: test_do_not_create_registration_wiki_page

    def test_do_not_create_registration_wiki_page(
        self, app, user_creator,
        url_registration_public, url_registration_private
    ):
        # test_do_not_create_wiki_on_public_registration
        res = app.post_json_api(url_registration_public, create_wiki_payload(fake.word()), auth=user_creator.auth, expect_errors=True)
        assert res.status_code == 405

        # test_do_not_create_wiki_on_embargoed_registration
        res = app.post_json_api(url_registration_private, create_wiki_payload(fake.word()), auth=user_creator.auth, expect_errors=True)
        assert res.status_code == 405
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:11,代码来源:test_node_wiki_list.py

示例4: generate_metadata

def generate_metadata(file_trees, selected_files, node_index):
    data = {}
    uploader_types = {
        ('q_' + selected_file['name']): {
            'value': fake.word(),
            'extra': [{
                'sha256': sha256,
                'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                    node_index[sha256],
                    selected_file['path']
                ),
                'selectedFileName': selected_file['name'],
                'nodeId': node_index[sha256]
            }]
        }
        for sha256, selected_file in selected_files.items()
    }
    data.update(uploader_types)
    object_types = {
        ('q_' + selected_file['name'] + '_obj'): {
            'value': {
                name_factory(): {
                    'value': fake.word(),
                    'extra': [{
                        'sha256': sha256,
                        'viewUrl': '/project/{0}/files/osfstorage{1}'.format(
                            node_index[sha256],
                            selected_file['path']
                        ),
                        'selectedFileName': selected_file['name'],
                        'nodeId': node_index[sha256]
                    }]
                },
                name_factory(): {
                    'value': fake.word()
                }
            }
        }
        for sha256, selected_file in selected_files.items()
    }
    data.update(object_types)
    other_questions = {
        'q{}'.format(i): {
            'value': fake.word()
        }
        for i in range(5)
    }
    data.update(other_questions)
    return data
开发者ID:atelic,项目名称:osf.io,代码行数:49,代码来源:test_archiver.py

示例5: 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

示例6: 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

示例7: test_do_not_create_private_wiki_page

    def test_do_not_create_private_wiki_page(
        self, app, wiki_private, url_node_private,
        user_read_contributor, user_non_contributor
    ):

        # test_do_not_create_private_wiki_page_as_read_contributor
        res = app.post_json_api(url_node_private, create_wiki_payload(fake.word()), auth=user_read_contributor.auth, expect_errors=True)
        assert res.status_code == 403

        # test_do_not_create_private_wiki_page_as_non_contributor
        res = app.post_json_api(url_node_private, create_wiki_payload(fake.word()), auth=user_non_contributor.auth, expect_errors=True)
        assert res.status_code == 403

        # test_do_not_create_private_wiki_page_as_unauthenticated
        res = app.post_json_api(url_node_private, create_wiki_payload(fake.word()), expect_errors=True)
        assert res.status_code == 401
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:16,代码来源:test_node_wiki_list.py

示例8: 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

示例9: test_create_public_wiki_page_with_empty_content

 def test_create_public_wiki_page_with_empty_content(self, app, user_write_contributor, url_node_public, project_public):
     page_name = fake.word()
     payload = create_wiki_payload(page_name)
     payload['data']['attributes']['content'] = ''
     res = app.post_json_api(url_node_public, payload, auth=user_write_contributor.auth, expect_errors=True)
     assert res.status_code == 400
     assert res.json['errors'][0]['detail'] == 'This field may not be blank.'
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:7,代码来源:test_node_wiki_list.py

示例10: 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

示例11: 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

示例12: test_do_not_create_wiki_page_if_disabled

 def test_do_not_create_wiki_page_if_disabled(
     self, app, user_creator,
     project_public, url_node_public, wiki_public
 ):
     project_public.delete_addon('wiki', auth=Auth(user_creator))
     page_name = fake.word()
     res = app.post_json_api(url_node_public, create_wiki_payload(page_name), auth=user_creator.auth, expect_errors=True)
     assert res.status_code == 404
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:8,代码来源:test_node_wiki_list.py

示例13: test_do_not_create_wiki_page_if_publicly_editable_non_contrib

 def test_do_not_create_wiki_page_if_publicly_editable_non_contrib(
     self, app, user_creator, user_non_contributor,
     project_public, url_node_public, wiki_public
 ):
     project_public.addons_wiki_node_settings.set_editing(True, auth=Auth(user_creator))
     page_name = fake.word()
     res = app.post_json_api(url_node_public, create_wiki_payload(page_name), auth=user_non_contributor.auth, expect_errors=True)
     assert res.status_code == 403
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:8,代码来源:test_node_wiki_list.py

示例14: test_create_public_wiki_page_with_content

 def test_create_public_wiki_page_with_content(self, app, user_write_contributor, url_node_public, project_public):
     page_name = fake.word()
     payload = create_wiki_payload(page_name)
     payload['data']['attributes']['content'] = 'my first wiki page'
     res = app.post_json_api(url_node_public, payload, auth=user_write_contributor.auth)
     assert res.status_code == 201
     assert res.json['data']['attributes']['name'] == page_name
     wiki_page = WikiPage.objects.get_for_node(project_public, page_name)
     assert wiki_page.get_version().content == 'my first wiki page'
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:9,代码来源:test_node_wiki_list.py

示例15: folder_factory

def folder_factory(depth, num_files, num_folders, path_above):
    new_path = os.path.join(path_above.rstrip('/'), fake.word())
    return {
        'path': new_path,
        'kind': 'folder',
        'children': [
            file_factory()
            for i in range(num_files)
        ] + [
            folder_factory(depth - 1, num_files, num_folders, new_path)
        ] if depth > 0 else []
    }
开发者ID:atelic,项目名称:osf.io,代码行数:12,代码来源:test_archiver.py


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