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

Python api_client.post_data函数代码示例

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

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



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

示例1: test_update_draft

def test_update_draft(api_client):
    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.post_data('/drafts/{}'.format(draft_public_id),
                             updated_draft)
    updated_public_id = json.loads(r.data)['id']
    updated_version = json.loads(r.data)['version']

    assert updated_public_id == draft_public_id and \
        updated_version != version

    drafts = api_client.get_data('/drafts')
    assert len(drafts) == 1
    assert drafts[0]['id'] == updated_public_id
开发者ID:MediaPreneur,项目名称:inbox,代码行数:26,代码来源:test_drafts.py


示例2: test_create_tag

def test_create_tag(api_client, default_namespace):
    ns_id = default_namespace.public_id

    post_resp = api_client.post_data('/tags/', {'name': 'foo'})
    assert post_resp.status_code == 200
    tag_resp = json.loads(post_resp.data)
    assert tag_resp['name'] == 'foo'
    assert tag_resp['namespace_id'] == ns_id
    tag_id = tag_resp['id']

    # Check getting the tag
    tag_data = api_client.get_data('/tags/{}'.format(tag_id))
    assert tag_data['name'] == 'foo'
    assert tag_data['namespace_id'] == ns_id
    assert tag_data['id'] == tag_id

    # Check listing the tag
    assert 'foo' in [tag['name'] for tag in api_client.get_data('/tags/')]

    # Make sure we can specify the namespace that we are creating the tag in
    bad_ns_id = 0000000000000000000000000
    tag_data = {'name': 'foo3', 'namespace_id': bad_ns_id}
    put_resp = api_client.post_data('/tags/', tag_data)
    assert put_resp.status_code == 400
    assert 'foo3' not in [tag['name'] for tag in api_client.get_data('/tags/')]
开发者ID:dlitz,项目名称:inbox,代码行数:25,代码来源:test_tags.py


示例3: test_search_response

def test_search_response(db, api_client, search_engine):
    endpoint = '/messages/search'
    resp = api_client.post_data(endpoint + '?limit={}&offset={}'.
                                format(1, 0), {})
    assert resp.status_code == 200
    result_dict = json.loads(resp.data)
    results = result_dict['results']
    assert len(results) == 1

    search_repr = results[0]['object']
    message_id = search_repr['id']

    api_repr = api_client.get_data('/messages/{}'.format(message_id))

    assert search_repr['to'] == api_repr['to']
    assert search_repr['from'] == api_repr['from']
    assert search_repr['cc'] == api_repr['cc']
    assert search_repr['bcc'] == api_repr['bcc']
    assert search_repr['files'] == api_repr['files']

    endpoint = '/threads/search'
    resp = api_client.post_data(endpoint + '?limit={}&offset={}'.
                                format(1, 0), {})
    assert resp.status_code == 200
    result_dict = json.loads(resp.data)
    results = result_dict['results']
    assert len(results) == 1

    search_repr = results[0]['object']
    thread_id = search_repr['id']

    api_repr = api_client.get_data('/threads/{}'.format(thread_id))

    assert sorted(search_repr['tags']) == sorted(api_repr['tags'])
    assert search_repr['participants'] == api_repr['participants']
开发者ID:Analect,项目名称:sync-engine,代码行数:35,代码来源:test_search.py


示例4: 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:PriviPK,项目名称:privipk-sync-engine,代码行数:25,代码来源:test_events.py


示例5: test_delete_draft

def test_delete_draft(api_client):
    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.post_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
开发者ID:MediaPreneur,项目名称:inbox,代码行数:25,代码来源:test_drafts.py


示例6: 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:biddyweb,项目名称:sync-engine,代码行数:33,代码来源:test_send.py


示例7: test_api_list

def test_api_list(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    e_data = {'title': 'subj', 'description': 'body1',
              'when': {'time': 1}, 'location': 'InboxHQ'}
    e_data2 = {'title': 'subj2', 'description': 'body2',
               'when': {'time': 1}, 'location': 'InboxHQ'}
    api_client.post_data('/events', e_data, ns_id)
    api_client.post_data('/events', e_data2, ns_id)

    event_list = api_client.get_data('/events', ns_id)
    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:dlitz,项目名称:inbox,代码行数:26,代码来源:test_events.py


示例8: test_send_existing_draft

def test_send_existing_draft(patch_smtp, 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',
                             {'draft_id': draft_public_id,
                              'version': version})
    assert r.status_code == 200

    # Test that the sent draft can't be sent again.
    r = api_client.post_data('/send',
                             {'draft_id': draft_public_id,
                              'version': version})
    assert r.status_code == 400

    drafts = api_client.get_data('/drafts')
    threads_with_drafts = api_client.get_data('/threads?tag=drafts')
    assert not drafts
    assert not threads_with_drafts

    sent_threads = api_client.get_data('/threads?tag=sent')
    assert len(sent_threads) == 1

    message = api_client.get_data('/messages/{}'.format(draft_public_id))
    assert message['object'] == 'message'
开发者ID:Analect,项目名称:sync-engine,代码行数:26,代码来源:test_sending.py


示例9: test_send

def test_send(api_client, example_draft, real_syncback_service, monkeypatch):
    # We're not testing the actual SMTP sending or syncback here, so
    # monkey-patch to make this run faster.
    monkeypatch.setattr('inbox.sendmail.base.get_sendmail_client',
                        lambda *args, **kwargs: MockSMTPClient())
    monkeypatch.setattr('inbox.actions.save_draft',
                        lambda *args, **kwargs: None)
    monkeypatch.setattr('inbox.actions.delete_draft',
                        lambda *args, **kwargs: None)
    r = api_client.post_data('/drafts', example_draft)
    draft_public_id = json.loads(r.data)['id']

    r = api_client.post_data('/send', {'draft_id': draft_public_id})

    # TODO(emfree) do this more rigorously
    gevent.sleep(1)

    drafts = api_client.get_data('/drafts')
    threads_with_drafts = api_client.get_data('/threads?tag=drafts')
    assert not drafts
    assert not threads_with_drafts

    sent_threads = api_client.get_data('/threads?tag=sent')
    assert len(sent_threads) == 1

    message = api_client.get_data('/messages/{}'.format(draft_public_id))
    assert message['state'] == 'sent'
    assert message['object'] == 'message'
开发者ID:AmyWeiner,项目名称:inbox,代码行数:28,代码来源:test_drafts.py


示例10: test_api_get

def test_api_get(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    e_data = {'title': 'subj', 'when': {'time': 1}, 'location': 'InboxHQ'}
    e_data2 = {'title': 'subj2', 'when': {'time': 1}, 'location': 'InboxHQ'}
    api_client.post_data('/events', e_data, ns_id)
    api_client.post_data('/events', e_data2, ns_id)

    event_list = api_client.get_data('/events', ns_id)

    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, ns_id)

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

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

    assert c1found
    assert c2found
开发者ID:dlitz,项目名称:inbox,代码行数:26,代码来源:test_events.py


示例11: 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:PriviPK,项目名称:privipk-sync-engine,代码行数:25,代码来源:test_events.py


示例12: test_conflicting_updates

def test_conflicting_updates(api_client):
    original_draft = {
        'subject': 'parent draft',
        'body': 'parent draft'
    }
    r = api_client.post_data('/drafts', original_draft)
    original_public_id = json.loads(r.data)['id']

    updated_draft = {
        'subject': 'updated draft',
        'body': 'updated draft'
    }
    r = api_client.post_data('/drafts/{}'.format(original_public_id),
                             updated_draft)
    assert r.status_code == 200
    updated_public_id = json.loads(r.data)['id']

    conflicting_draft = {
        'subject': 'conflicting draft',
        'body': 'conflicting draft'
    }
    r = api_client.post_data('/drafts/{}'.format(original_public_id),
                             conflicting_draft)
    assert r.status_code == 409

    drafts = api_client.get_data('/drafts')
    assert len(drafts) == 1
    assert drafts[0]['id'] == updated_public_id
开发者ID:AmyWeiner,项目名称:inbox,代码行数:28,代码来源:test_drafts.py


示例13: test_add_remove_tags

def test_add_remove_tags(api_client):
    assert 'foo' not in [tag['name'] for tag in api_client.get_data('/tags/')]
    assert 'bar' not in [tag['name'] for tag in api_client.get_data('/tags/')]

    api_client.post_data('/tags/', {'name': 'foo'})
    api_client.post_data('/tags/', {'name': 'bar'})

    thread_id = api_client.get_data('/threads/')[0]['id']
    thread_path = '/threads/{}'.format(thread_id)
    api_client.put_data(thread_path, {'add_tags': ['foo']})
    api_client.put_data(thread_path, {'add_tags': ['bar']})

    tag_names = [tag['name'] for tag in
                 api_client.get_data(thread_path)['tags']]
    assert 'foo' in tag_names
    assert 'bar' in tag_names

    # Check that tag was only applied to this thread
    another_thread_id = api_client.get_data('/threads/')[1]['id']
    tag_names = get_tag_names(
        api_client.get_data('/threads/{}'.format(another_thread_id)))
    assert 'foo' not in tag_names

    api_client.put_data(thread_path, {'remove_tags': ['foo']})
    api_client.put_data(thread_path, {'remove_tags': ['bar']})
    tag_names = get_tag_names(api_client.get_data(thread_path))
    assert 'foo' not in tag_names
    assert 'bar' not in tag_names
开发者ID:dlitz,项目名称:inbox,代码行数:28,代码来源:test_tags.py


示例14: test_delete_draft

def test_delete_draft(api_client):
    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 "drafts" in [t["name"] for t in thread["tags"]]
    api_client.delete("/drafts/{}".format(public_id), {"version": version})
    thread = api_client.get_data("/threads/{}".format(thread_public_id))
    assert thread
    assert "drafts" not in [t["name"] for t in thread["tags"]]
开发者ID:PriviPK,项目名称:privipk-sync-engine,代码行数:35,代码来源:test_drafts.py


示例15: test_drafts_filter

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

    r = api_client.get_data('/drafts')
    matching_saved_drafts = [draft for draft in r if draft['id'] == public_id]
    thread_public_id = matching_saved_drafts[0]['thread_id']

    reply_draft = {
        'subject': 'test reply',
        'body': 'test reply',
        'thread_id': thread_public_id
    }
    r = api_client.post_data('/drafts', reply_draft)

    _filter = '?thread_id=0000000000000000000000000'
    results = api_client.get_data('/drafts' + _filter)
    assert len(results) == 0

    results = api_client.get_data('/drafts?thread_id={}'
                                  .format(thread_public_id))
    assert len(results) == 2

    results = api_client.get_data('/drafts?offset={}&thread_id={}'
                                  .format(1, thread_public_id))
    assert len(results) == 1
开发者ID:dlitz,项目名称:inbox,代码行数:26,代码来源:test_drafts.py


示例16: test_lens_tx

def test_lens_tx(api_client, db):
    api_client.post_data('/drafts/', {
        'subject': 'Calaveras Dome / Hammer Dome',
        'to': [{'name': 'Somebody', 'email': '[email protected]'}],
        'cc': [{'name': 'Another Person', 'email': '[email protected]'}]
    })

    transaction = db.session.query(Transaction). \
        filter(Transaction.table_name == 'spoolmessage'). \
        order_by(desc(Transaction.id)).first()

    draft = db.session.query(SpoolMessage). \
        order_by(desc(SpoolMessage.id)).first()
    thread = draft.thread


    filter = Lens(subject='/Calaveras/')
    assert filter.match(transaction)

    filter = Lens(subject='Calaveras')
    assert not filter.match(transaction)

    filter = Lens(from_addr='[email protected]')
    assert filter.match(transaction)

    filter = Lens(from_addr='/inboxapp/')
    assert filter.match(transaction)

    filter = Lens(cc_addr='/Another/')
    assert filter.match(transaction)

    early_ts = calendar.timegm(thread.subjectdate.utctimetuple()) - 1
    late_ts = calendar.timegm(thread.subjectdate.utctimetuple()) + 1

    filter = Lens(started_before=late_ts)
    assert filter.match(transaction)

    filter = Lens(started_before=early_ts)
    assert not filter.match(transaction)

    filter = Lens(started_after=late_ts)
    assert not filter.match(transaction)

    filter = Lens(started_after=early_ts)
    assert filter.match(transaction)

    filter = Lens(last_message_after=early_ts)
    assert filter.match(transaction)

    filter = Lens(last_message_after=late_ts)
    assert not filter.match(transaction)

    filter = Lens(subject='/Calaveras/', any_email='Nobody')
    assert not filter.match(transaction)

    filter = Lens(subject='/Calaveras/', any_email='/inboxapp/')
    assert filter.match(transaction)

    with pytest.raises(ValueError):
        filter = Lens(subject='/*/')
开发者ID:AmyWeiner,项目名称:inbox,代码行数:60,代码来源:test_lens.py


示例17: 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:Analect,项目名称:sync-engine,代码行数:28,代码来源:test_sending.py


示例18: test_reply_headers_set

def test_reply_headers_set(patch_smtp, api_client, example_draft):
    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:Analect,项目名称:sync-engine,代码行数:9,代码来源:test_sending.py


示例19: 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:Analect,项目名称:sync-engine,代码行数:9,代码来源:test_sending.py


示例20: 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:PriviPK,项目名称:privipk-sync-engine,代码行数:10,代码来源:test_events.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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