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

Python api_client.post_data函数代码示例

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

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



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

示例1: test_send_with_event

def test_send_with_event(patch_smtp, api_client, example_draft, event):
    # Create a draft
    r = api_client.post_data('/drafts', example_draft)
    msgs = patch_smtp
    assert r.status_code == 200
    draft_public_id = json.loads(r.data)['id']
    version = json.loads(r.data)['version']

    # Send the draft along with an event ID to use for invites
    r = api_client.post_data('/send',
                             {'draft_id': draft_public_id,
                              'version': version,
                              'event_id': event.public_id})
    assert r.status_code == 200

    # Make sure one message was sent
    assert len(msgs) == 1
    recipients, raw_msg = msgs[0]
    msg = mime.from_string(raw_msg)

    # Check the MIME body of the message to make sure the event is there
    parts = []
    for mimepart in msg.walk(with_self=msg.content_type.is_singlepart()):
        format_type = mimepart.content_type.format_type
        subtype = mimepart.content_type.subtype
        parts.append((format_type, subtype))
    assert ('text', 'plain') in parts
    assert ('text', 'html') in parts
    assert ('text', 'calendar') in parts
开发者ID:akatsoulas,项目名称:sync-engine,代码行数:29,代码来源:test_sending.py


示例2: test_contacts_updated

def test_contacts_updated(api_client):
    """Tests that draft-contact associations are properly created and
    updated."""
    draft = {"to": [{"email": "[email protected]"}, {"email": "[email protected]"}]}

    r = api_client.post_data("/drafts", draft)
    assert r.status_code == 200
    draft_id = json.loads(r.data)["id"]
    draft_version = json.loads(r.data)["version"]

    r = api_client.get_data("/[email protected]")
    assert len(r) == 1

    updated_draft = {"to": [{"email": "[email protected]"}, {"email": "[email protected]"}], "version": draft_version}

    r = api_client.put_data("/drafts/{}".format(draft_id), updated_draft)
    assert r.status_code == 200

    r = api_client.get_data("/[email protected]")
    assert len(r) == 1

    r = api_client.get_data("/[email protected]")
    assert len(r) == 0

    r = api_client.get_data("/[email protected]")
    assert len(r) == 1

    # Check that contacts aren't created for garbage recipients.
    r = api_client.post_data("/drafts", {"to": [{"name": "who", "email": "nope"}]})
    assert r.status_code == 200
    r = api_client.get_data("/threads?to=nope")
    assert len(r) == 0
    r = api_client.get_data("/contacts?filter=nope")
    assert len(r) == 0
开发者ID:busseyl,项目名称:sync-engine,代码行数:34,代码来源:test_drafts.py


示例3: test_api_list

def test_api_list(db, api_client, calendar):
    e_data = {'title': 'subj', 'description': 'body1',
              'calendar_id': calendar.public_id,
              'when': {'time': 1}, 'location': 'InboxHQ'}
    e_data2 = {'title': 'subj2', 'description': 'body2',
               'calendar_id': calendar.public_id,
               'when': {'time': 1}, 'location': 'InboxHQ'}
    api_client.post_data('/events', e_data)
    api_client.post_data('/events', e_data2)

    event_list = api_client.get_data('/events')
    event_titles = [event['title'] for event in event_list]
    assert 'subj' in event_titles
    assert 'subj2' in event_titles

    event_descriptions = [event['description'] for event in event_list]
    assert 'body1' in event_descriptions
    assert 'body2' in event_descriptions

    event_ids = [event['id'] for event in event_list]

    for e_id in event_ids:
        ev = db.session.query(Event).filter_by(public_id=e_id).one()
        db.session.delete(ev)
    db.session.commit()
开发者ID:yodiyo,项目名称:sync-engine,代码行数:25,代码来源:test_events.py


示例4: test_api_get

def test_api_get(db, api_client, calendar):
    e_data = {'title': 'subj', 'when': {'time': 1},
              'calendar_id': calendar.public_id, 'location': 'InboxHQ'}
    e_data2 = {'title': 'subj2', 'when': {'time': 1},
               'calendar_id': calendar.public_id, 'location': 'InboxHQ'}
    api_client.post_data('/events', e_data)
    api_client.post_data('/events', e_data2)

    event_list = api_client.get_data('/events')

    event_ids = [event['id'] for event in event_list]

    c1found = False
    c2found = False
    for c_id in event_ids:
        event = api_client.get_data('/events/' + c_id)

        if event['title'] == 'subj':
            c1found = True

        if event['title'] == 'subj2':
            c2found = True

    assert c1found
    assert c2found
开发者ID:yodiyo,项目名称:sync-engine,代码行数:25,代码来源:test_events.py


示例5: test_quoted_printable_encoding_avoided_for_compatibility

def test_quoted_printable_encoding_avoided_for_compatibility(
        patch_smtp, api_client):
    # Test that messages with long lines don't get quoted-printable encoded,
    # for maximum server compatibility.
    api_client.post_data(
        '/send',
        {'to': [{'email': '[email protected]'}],
         'subject': 'In Catilinam',
         'body': 'Etenim quid est, Catilina, quod iam amplius exspectes, si '
         'neque nox tenebris obscurare coeptus nefarios neque privata domus '
         'parietibus continere voces conjurationis tuae potest? Si '
         'illustrantur, si erumpunt omnia? Muta iam istam mentem, mihi crede! '
         'obliviscere caedis atque incendiorum. Teneris undique: luce sunt '
         'clariora nobis tua consilia omnia; quae iam mecum licet recognoscas.'
         ' Meministine me ante diem duodecimum Kalendas Novembres dicere in '
         'senatu, fore in armis certo die, qui dies futurus esset ante diem '
         'sextum Kalendas Novembres, C. Manlium, audaciae satellitem atque '
         'administrum tuae? Num me fefellit, Catilina, non modo res tanta, tam'
         ' atrox, tamque incredibilis, verum id quod multo magis admirandum, '
         'dies? '})
    _, msg = patch_smtp[-1]
    parsed = mime.from_string(msg)
    assert len(parsed.parts) == 2
    for part in parsed.parts:
        if part.content_type.value == 'text/html':
            assert part.content_encoding[0] == 'base64'
        elif part.content_type.value == 'text/plain':
            assert part.content_encoding[0] in ('7bit', 'base64')
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:28,代码来源:test_sending.py


示例6: test_write_endpoints

def test_write_endpoints(db, setup_account, api_client, default_account):
    # Write operations (create, update, delete) succeed.
    r = api_client.post_data(
        '/drafts',
        data={
            'body': '<html><body><h2>Sea, birds and sand.</h2></body></html>'
        })
    assert r.status_code == 200
    draft_id = json.loads(r.data)['id']

    endpoint = '/messages/{}'.format(setup_account['message'])
    r = api_client.put_data(endpoint, data={"starred": True})
    assert r.status_code == 200

    endpoint = '/events/{}'.format(setup_account['event'])
    r = api_client.delete(endpoint)
    assert r.status_code == 200

    default_account.sync_state = 'invalid'
    db.session.commit()

    # Write operations fail with an HTTP 403.
    r = api_client.post_data('/labels', data={"display_name": "Neu!"})
    assert r.status_code == 403

    endpoint = '/threads/{}'.format(setup_account['thread'])
    r = api_client.put_data(endpoint, data={"starred": True})
    assert r.status_code == 403

    endpoint = '/drafts/{}'.format(draft_id)
    r = api_client.delete(endpoint)
    assert r.status_code == 403
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:32,代码来源:test_invalid_account.py


示例7: test_send_draft

def test_send_draft(db, api_client, example_draft, default_account):

    r = api_client.post_data('/drafts', example_draft)
    assert r.status_code == 200
    public_id = json.loads(r.data)['id']
    version = json.loads(r.data)['version']

    r = api_client.post_data('/send', {'draft_id': public_id,
                                       'version': version})
    assert r.status_code == 200

    draft = api_client.get_data('/drafts/{}'.format(public_id))
    assert draft is not None

    assert draft['object'] != 'draft'

    with crispin_client(default_account.id, default_account.provider) as c:
        criteria = ['NOT DELETED', 'SUBJECT "{0}"'.format(
            example_draft['subject'])]

        c.conn.select_folder(default_account.drafts_folder.name,
                             readonly=False)

        draft_uids = c.conn.search(criteria)
        assert not draft_uids, 'Message still in Drafts folder'

        c.conn.select_folder(default_account.sent_folder.name, readonly=False)

        sent_uids = c.conn.search(criteria)
        assert sent_uids, 'Message missing from Sent folder'

        c.conn.delete_messages(sent_uids)
        c.conn.expunge()
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:33,代码来源:test_send.py


示例8: test_send_rejected_without_recipients

def test_send_rejected_without_recipients(api_client):
    r = api_client.post_data('/drafts', {'subject': 'Hello there'})
    draft_public_id = json.loads(r.data)['id']
    version = json.loads(r.data)['version']

    r = api_client.post_data('/send',
                             {'draft_id': draft_public_id,
                              'version': version})
    assert r.status_code == 400
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:9,代码来源:test_sending.py


示例9: test_create_event

def test_create_event(db, api_client, calendar):
    e_data = {'title': 'subj', 'description': 'body1',
              'calendar_id': calendar.public_id,
              'when': {'time': 1}, 'location': 'InboxHQ'}
    e_data2 = {'title': 'subj2', 'description': 'body2',
               'calendar_id': calendar.public_id,
               'when': {'time': 1}, 'location': 'InboxHQ'}
    api_client.post_data('/events', e_data)
    api_client.post_data('/events', e_data2)
    db.session.commit()
开发者ID:yodiyo,项目名称:sync-engine,代码行数:10,代码来源:test_events.py


示例10: test_multisend_init_rejected_with_existing_draft

def test_multisend_init_rejected_with_existing_draft(api_client,
                                                     example_draft):
    r = api_client.post_data('/drafts', example_draft)
    draft_public_id = json.loads(r.data)['id']
    version = json.loads(r.data)['version']

    r = api_client.post_data('/send-multiple',
                             {'draft_id': draft_public_id,
                              'version': version})
    assert r.status_code == 400
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:10,代码来源:test_sending.py


示例11: test_invalid_timestamp

def test_invalid_timestamp(api_client, default_namespace):
    # Valid UNIX timestamp
    response = api_client.post_data(
        '/delta/generate_cursor', data={'start': int(time.time())})
    assert response.status_code == 200

    # Invalid timestamp
    response = api_client.post_data(
        '/delta/generate_cursor', data={'start': 1434591487647})
    assert response.status_code == 400
开发者ID:rskumar,项目名称:sync-engine,代码行数:10,代码来源:test_streaming.py


示例12: test_sending_from_email_alias

def test_sending_from_email_alias(patch_smtp, api_client):
    api_client.post_data('/send',
                         {'to': [{'email': '[email protected]'}],
                          'from': [{'name': 'admin',
                                    'email': '[email protected]'}],
                          'subject': 'Banalities',
                          'body': '<html>Hello there</html>'})
    _, msg = patch_smtp[-1]
    parsed = mime.from_string(msg)
    assert 'From' in parsed.headers
    assert parsed.headers['From'] == 'admin <[email protected]>'
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:11,代码来源:test_sending.py


示例13: test_sent_messages_shown_in_delta

def test_sent_messages_shown_in_delta(patch_smtp, api_client, example_draft):
    ts = int(time.time())
    r = api_client.post_data('/delta/generate_cursor', {'start': ts})
    cursor = json.loads(r.data)['cursor']
    r = api_client.post_data('/send', example_draft)
    message_id = json.loads(r.data)['id']
    deltas = api_client.get_data('/delta?cursor={}'.format(cursor))['deltas']
    message_delta = next((d for d in deltas if d['id'] == message_id), None)
    assert message_delta is not None
    assert message_delta['object'] == 'message'
    assert message_delta['event'] == 'create'
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:11,代码来源:test_sending.py


示例14: test_reply_headers_set

def test_reply_headers_set(db, patch_smtp, api_client, example_draft, thread,
                           message):
    message.message_id_header = '<[email protected]>'
    db.session.commit()
    thread_id = api_client.get_data('/threads')[0]['id']

    api_client.post_data('/send', {'to': [{'email': '[email protected]'}],
                                   'thread_id': thread_id})
    _, msg = patch_smtp[-1]
    parsed = mime.from_string(msg)
    assert 'In-Reply-To' in parsed.headers
    assert 'References' in parsed.headers
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:12,代码来源:test_sending.py


示例15: test_get_all_drafts

def test_get_all_drafts(api_client, example_draft):
    r = api_client.post_data("/drafts", example_draft)
    first_public_id = json.loads(r.data)["id"]

    r = api_client.post_data("/drafts", example_draft)
    second_public_id = json.loads(r.data)["id"]

    drafts = api_client.get_data("/drafts")
    assert len(drafts) == 2
    assert first_public_id != second_public_id
    assert {first_public_id, second_public_id} == {draft["id"] for draft in drafts}
    assert all(item["object"] == "draft" for item in drafts)
开发者ID:busseyl,项目名称:sync-engine,代码行数:12,代码来源:test_drafts.py


示例16: test_get_all_drafts

def test_get_all_drafts(api_client, example_draft):
    r = api_client.post_data('/drafts', example_draft)
    first_public_id = json.loads(r.data)['id']

    r = api_client.post_data('/drafts', example_draft)
    second_public_id = json.loads(r.data)['id']

    drafts = api_client.get_data('/drafts')
    assert len(drafts) == 2
    assert first_public_id != second_public_id
    assert {first_public_id, second_public_id} == {draft['id'] for draft in
                                                   drafts}
    assert all(item['object'] == 'draft' for item in drafts)
开发者ID:brandoncc,项目名称:sync-engine,代码行数:13,代码来源:test_drafts.py


示例17: test_delete_draft

def test_delete_draft(api_client, thread, message):
    original_draft = {
        'subject': 'parent draft',
        'body': 'parent draft'
    }
    r = api_client.post_data('/drafts', original_draft)
    draft_public_id = json.loads(r.data)['id']
    version = json.loads(r.data)['version']

    updated_draft = {
        'subject': 'updated draft',
        'body': 'updated draft',
        'version': version
    }
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            updated_draft)
    updated_public_id = json.loads(r.data)['id']
    updated_version = json.loads(r.data)['version']

    r = api_client.delete('/drafts/{}'.format(updated_public_id),
                          {'version': updated_version})

    # Check that drafts were deleted
    drafts = api_client.get_data('/drafts')
    assert not drafts

    # Check that no orphaned threads are around
    threads = api_client.get_data('/threads?subject=parent%20draft')
    assert not threads
    threads = api_client.get_data('/threads?subject=updated%20draft')
    assert not threads

    # And check that threads aren't deleted if they still have messages.
    thread_public_id = api_client.get_data('/threads')[0]['id']

    reply_draft = {
        'subject': 'test reply',
        'body': 'test reply',
        'thread_id': thread_public_id
    }
    r = api_client.post_data('/drafts', reply_draft)
    public_id = json.loads(r.data)['id']
    version = json.loads(r.data)['version']
    thread = api_client.get_data('/threads/{}'.format(thread_public_id))
    assert len(thread['draft_ids']) > 0
    api_client.delete('/drafts/{}'.format(public_id),
                      {'version': version})
    thread = api_client.get_data('/threads/{}'.format(thread_public_id))
    assert thread
    assert len(thread['draft_ids']) == 0
开发者ID:brandoncc,项目名称:sync-engine,代码行数:50,代码来源:test_drafts.py


示例18: label_client

def label_client(db, gmail_account):
    api_client = new_api_client(db, gmail_account.namespace)

    # Whereas calling generic_account always makes a new IMAP account,
    # calling gmail_account checks first to see if there's an existing
    # Gmail account and uses it if so. This can cause namespace
    # conflicts if a label is "created" more than once. Since
    # labels can't be deleted and then re-created, this fixture only
    # makes a new label if there are no existing labels.
    g_data = api_client.get_raw('/labels/')
    if not json.loads(g_data.data):
        api_client.post_data('/labels/',
                             {"display_name": "Test_Label"})
    return api_client
开发者ID:busseyl,项目名称:sync-engine,代码行数:14,代码来源:test_folders_labels.py


示例19: test_api_remove_participant

def test_api_remove_participant(db, api_client, calendar):
    e_data = {
        'title': 'Friday Office Party',
        'when': {'time': 1407542195},
        'calendar_id': calendar.public_id,
        'participants': [{'email': '[email protected]'},
                         {'email': '[email protected]'},
                         {'email': '[email protected]'},
                         {'email': '[email protected]'},
                         {'email': '[email protected]'}]
    }

    e_resp = api_client.post_data('/events', e_data)
    e_resp_data = json.loads(e_resp.data)
    assert len(e_resp_data['participants']) == 5
    for i, p in enumerate(e_resp_data['participants']):
        res = [e for e in e_resp_data['participants']
               if e['email'] == p['email']]
        assert len(res) == 1
        assert res[0]['name'] is None

    event_id = e_resp_data['id']
    e_data['participants'].pop()
    e_resp = api_client.put_data('/events/' + event_id, e_data)
    e_resp_data = json.loads(e_resp.data)
    assert len(e_resp_data['participants']) == 4
    for i, p in enumerate(e_resp_data['participants']):
        res = [e for e in e_resp_data['participants']
               if e['email'] == p['email']]
        assert len(res) == 1
        assert p['name'] is None
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:31,代码来源:test_event_participants.py


示例20: test_multisend_handle_recipients_rejected

def test_multisend_handle_recipients_rejected(recipients_refused, api_client,
                                              multisend,
                                              patch_crispin_del_sent):
    r = api_client.post_data('/send-multiple/' + multisend['id'],
                             multisend['send_req'])
    assert r.status_code == 402
    assert json.loads(r.data)['message'] == 'Sending to all recipients failed'
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:7,代码来源:test_sending.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python api_client.put_data函数代码示例发布时间:2022-05-27
下一篇:
Python api_client.get_raw函数代码示例发布时间: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