本文整理汇总了Python中tests.util.base.api_client.put_data函数的典型用法代码示例。如果您正苦于以下问题:Python put_data函数的具体用法?Python put_data怎么用?Python put_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了put_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_tag
def test_delete_tag(api_client, default_namespace, thread):
post_resp = api_client.post_data('/tags/', {'name': 'foo'})
tag_resp = json.loads(post_resp.data)
tag_id = tag_resp['id']
thread_id = api_client.get_data('/threads')[0]['id']
api_client.put_data('/threads/{}'.format(thread_id), {'add_tags': ['foo']})
del_resp = api_client.delete('/tags/' + tag_id)
assert del_resp.status_code == 200
tag_data = api_client.get_data('/tags/{}'.format(tag_id))
assert tag_data['message'] == 'No tag found'
thread = api_client.get_data('/threads/{}'.format(thread_id))
assert 'foo' not in [tag['name'] for tag in thread['tags']]
del_resp = api_client.delete('/tags/!' + tag_id)
assert del_resp.status_code == 400
assert json.loads(del_resp.data)['message'].startswith('Invalid id')
del_resp = api_client.delete('/tags/0000000000000000000000000')
assert del_resp.status_code == 404
del_resp = api_client.delete('/tags/inbox')
assert del_resp.status_code == 400
assert 'user-created' in json.loads(del_resp.data)['message']
示例2: 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']
version = json.loads(r.data)['version']
updated_draft = {
'subject': 'updated draft',
'body': 'updated draft',
'version': version
}
r = api_client.put_data('/drafts/{}'.format(original_public_id),
updated_draft)
assert r.status_code == 200
updated_public_id = json.loads(r.data)['id']
updated_version = json.loads(r.data)['version']
assert updated_version != version
conflicting_draft = {
'subject': 'conflicting draft',
'body': 'conflicting draft',
'version': version
}
r = api_client.put_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
示例3: test_unread_cascades_to_messages
def test_unread_cascades_to_messages(log, api_client, default_account, thread,
message):
thread_id = api_client.get_data('/threads/')[0]['id']
thread_path = '/threads/{}'.format(thread_id)
api_client.put_data(thread_path, {'add_tags': ['unread']})
messages = api_client.get_data('/messages?thread_id={}'.format(thread_id))
assert all([msg['unread'] for msg in messages])
api_client.put_data(thread_path, {'remove_tags': ['unread']})
messages = api_client.get_data('/messages?thread_id={}'.format(thread_id))
assert not any([msg['unread'] for msg in messages])
示例4: test_events_are_condensed
def test_events_are_condensed(api_client):
"""Test that multiple revisions of the same object are rolled up in the
delta response."""
ts = int(time.time())
api_client.post_data('/tags/', {'name': 'foo'})
cursor = get_cursor(api_client, ts)
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, {'remove_tags': ['foo']})
sync_data = api_client.get_data('/delta?cursor={}'.format(cursor))
assert len(sync_data['deltas']) == 2
示例5: test_unread_cascades_to_messages
def test_unread_cascades_to_messages(patch_network_functions, log, api_client,
syncback_service, default_account):
thread_id = api_client.get_data('/threads/')[0]['id']
thread_path = '/threads/{}'.format(thread_id)
api_client.put_data(thread_path, {'add_tags': ['unread']})
gevent.sleep(3)
messages = api_client.get_data('/messages?thread_id={}'.format(thread_id))
assert all([msg['unread'] for msg in messages])
api_client.put_data(thread_path, {'remove_tags': ['unread']})
gevent.sleep(3)
messages = api_client.get_data('/messages?thread_id={}'.format(thread_id))
assert not any([msg['unread'] for msg in messages])
示例6: 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
示例7: test_events_are_condensed
def test_events_are_condensed(api_client):
"""Test that multiple revisions of the same object are rolled up in the
delta response."""
ts = int(time.time())
cursor = get_cursor(api_client, ts)
# Create, then modify a tag; then modify it again
tag = json.loads(api_client.post_data('/tags/', {'name': 'foo'}).data)
tag_id = tag['id']
api_client.put_data('/tags/{}'.format(tag_id), {'name': 'bar'})
api_client.put_data('/tags/{}'.format(tag_id), {'name': 'baz'})
# Modify a thread, then modify it again
thread_id = api_client.get_data('/threads/')[0]['id']
thread_path = '/threads/{}'.format(thread_id)
api_client.put_data(thread_path, {'add_tags': [tag_id]})
api_client.put_data(thread_path, {'remove_tags': [tag_id]})
sync_data = api_client.get_data('/delta?cursor={}'.format(cursor))
assert len(sync_data['deltas']) == 3
first_delta = sync_data['deltas'][0]
assert first_delta['object'] == 'tag' and first_delta['event'] == 'create'
# Check that successive modifies are condensed.
second_delta = sync_data['deltas'][1]
assert (second_delta['object'] == 'tag' and
second_delta['event'] == 'modify')
assert second_delta['attributes']['name'] == 'baz'
third_delta = sync_data['deltas'][2]
assert (third_delta['object'] == 'thread' and
third_delta['event'] == 'modify')
示例8: test_move_to_read_only_calendar
def test_move_to_read_only_calendar(db, api_client):
acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
ns_id = acct.namespace.public_id
calendar_list = api_client.get_data('/calendars', ns_id)
read_only_calendar = None
writeable_calendar = None
writeable_event = None
for c in calendar_list:
if c['read_only']:
read_only_calendar = c
else:
writeable_calendar = c
for e_id in c['event_ids']:
e = api_client.get_data('/events/' + e_id, ns_id)
if not e['read_only']:
writeable_event = e
break
assert read_only_calendar
assert writeable_event
assert writeable_calendar
e_id = writeable_event['id']
e_data = {'calendar_id': read_only_calendar['id']}
resp = api_client.put_data('/events/' + e_id, e_data, ns_id)
assert resp.status_code != 200
示例9: test_update_calendar
def test_update_calendar(db, api_client):
acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
ns_id = acct.namespace.public_id
c_data = {'name': 'Vacation'}
resp = api_client.post_data('/calendars', c_data, ns_id)
resp_data = json.loads(resp.data)
cal_id = resp_data['id']
c_update_data = {'name': 'OOO'}
resp = api_client.put_data('/calendars/' + cal_id, c_update_data, ns_id)
c_put_data = json.loads(resp.data)
assert resp.status_code == 200
assert c_put_data['namespace_id'] == ns_id
assert c_put_data['name'] == c_update_data['name']
assert c_put_data['description'] is None
assert c_put_data['read_only'] is False
assert c_put_data['object'] == 'calendar'
assert c_put_data['event_ids'] == []
resp_data = api_client.get_data('/calendars/' + cal_id, ns_id)
assert resp_data['namespace_id'] == ns_id
assert resp_data['name'] == c_update_data['name']
assert resp_data['description'] is None
assert resp_data['read_only'] is False
assert resp_data['object'] == 'calendar'
assert resp_data['event_ids'] == []
cal = db.session.query(Calendar).filter_by(public_id=cal_id).one()
db.session.delete(cal)
db.session.commit()
示例10: test_api_update_invalid
def test_api_update_invalid(db, api_client):
acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
ns_id = acct.namespace.public_id
e_update_data = {'title': 'new title'}
e_id = generate_public_id()
e_put_resp = api_client.put_data('/events/' + e_id, e_update_data, ns_id)
assert e_put_resp.status_code != 200
示例11: test_update_to_nonexistent_draft
def test_update_to_nonexistent_draft(api_client):
updated_draft = {"subject": "updated draft", "body": "updated draft", "version": 22}
r = api_client.put_data("/drafts/{}".format("notarealid"), updated_draft)
assert r.status_code == 404
drafts = api_client.get_data("/drafts")
assert len(drafts) == 0
示例12: 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"]]
示例13: 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.put_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
示例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
示例15: test_update_draft
def test_update_draft(api_client):
original_draft = {"subject": "original 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"]
assert version == 0
# Sleep so that timestamp on updated draft is different.
gevent.sleep(1)
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"]
assert updated_public_id == draft_public_id
assert updated_version > 0
drafts = api_client.get_data("/drafts")
assert len(drafts) == 1
assert drafts[0]["id"] == updated_public_id
# Check that the thread is updated too.
thread = api_client.get_data("/threads/{}".format(drafts[0]["thread_id"]))
assert thread["subject"] == "updated draft"
assert thread["first_message_timestamp"] == drafts[0]["date"]
assert thread["last_message_timestamp"] == drafts[0]["date"]