Ejemplo n.º 1
0
def test_delete_remote_draft(db, api_client):
    from inbox.models.message import Message

    # Non-Inbox created draft, therefore don't set inbox_uid
    message = Message()
    message.namespace_id = NAMESPACE_ID
    message.thread_id = 1
    message.received_date = datetime.utcnow()
    message.size = len('')
    message.is_draft = True
    message.is_read = True
    message.sanitized_body = ''
    message.snippet = ''

    db.session.add(message)
    db.session.commit()

    drafts = api_client.get_data('/drafts')
    assert len(drafts) == 1

    public_id = drafts[0]['id']
    version = drafts[0]['version']

    assert public_id == message.public_id and version == message.version

    api_client.delete('/drafts/{}'.format(public_id),
                      {'version': version})

    # Check that drafts were deleted
    drafts = api_client.get_data('/drafts')
    assert not drafts
Ejemplo n.º 2
0
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"]]
Ejemplo n.º 3
0
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']
Ejemplo n.º 4
0
def test_api_delete(db, api_client, calendar):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    e_data = {
        'title': '',
        'calendar_id': calendar.public_id,
        'when': {
            'time': 1407542195
        },
    }

    e_resp = api_client.post_data('/events', e_data, ns_id)
    e_resp_data = json.loads(e_resp.data)
    assert e_resp_data['object'] == 'event'
    assert e_resp_data['namespace_id'] == acct.namespace.public_id
    assert e_resp_data['title'] == e_data['title']
    assert e_resp_data['when']['time'] == e_data['when']['time']
    assert 'id' in e_resp_data
    e_id = e_resp_data['id']

    api_client.delete('/events/' + e_id, ns_id=ns_id)

    event = api_client.get_data('/events/' + e_id, ns_id)
    assert event['type'] == 'invalid_request_error'
Ejemplo n.º 5
0
def test_delete_remote_draft(db, api_client):
    from inbox.models.message import Message

    # Non-Inbox created draft, therefore don't set inbox_uid
    message = Message()
    message.namespace_id = NAMESPACE_ID
    message.thread_id = 1
    message.received_date = datetime.utcnow()
    message.size = len('')
    message.is_draft = True
    message.is_read = True
    message.sanitized_body = ''
    message.snippet = ''

    db.session.add(message)
    db.session.commit()

    drafts = api_client.get_data('/drafts')
    assert len(drafts) == 1

    public_id = drafts[0]['id']
    version = drafts[0]['version']

    assert public_id == message.public_id and version == message.version

    api_client.delete('/drafts/{}'.format(public_id), {'version': version})

    # Check that drafts were deleted
    drafts = api_client.get_data('/drafts')
    assert not drafts
Ejemplo n.º 6
0
def test_delete_tag(api_client, default_namespace):
    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']
Ejemplo n.º 7
0
def test_api_delete_invalid(db, api_client, calendar):
    e_id = 'asdf'
    resp = api_client.delete('/events/' + e_id)
    assert resp.status_code != 200

    e_id = generate_public_id()
    resp = api_client.delete('/events/' + e_id)
    assert resp.status_code != 200
Ejemplo n.º 8
0
def test_api_delete_invalid(db, api_client, calendar):
    e_id = 'asdf'
    resp = api_client.delete('/events/' + e_id)
    assert resp.status_code != 200

    e_id = generate_public_id()
    resp = api_client.delete('/events/' + e_id)
    assert resp.status_code != 200
Ejemplo n.º 9
0
def test_api_delete_invalid(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    e_id = 'asdf'
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code != 200

    e_id = generate_public_id()
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code != 200
Ejemplo n.º 10
0
def test_api_delete_invalid(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    e_id = 'asdf'
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code != 200

    e_id = generate_public_id()
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code != 200
Ejemplo n.º 11
0
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']]
Ejemplo n.º 12
0
def test_get_invalid(api_client, uploaded_file_ids):
    data = api_client.get_data('/files/0000000000000000000000000')
    assert data['message'].startswith("Couldn't find file")
    data = api_client.get_data('/files/!')
    assert data['message'].startswith("Invalid id")

    data = api_client.get_data('/files/0000000000000000000000000/download')
    assert data['message'].startswith("Couldn't find file")
    data = api_client.get_data('/files/!/download')
    assert data['message'].startswith("Invalid id")

    r = api_client.delete('/files/0000000000000000000000000')
    assert r.status_code == 404
    r = api_client.delete('/files/!')
    assert r.status_code == 400
Ejemplo n.º 13
0
def test_get_invalid(api_client, uploaded_file_ids):
    data = api_client.get_data('/files/0000000000000000000000000')
    assert data['message'].startswith("Couldn't find file")
    data = api_client.get_data('/files/!')
    assert data['message'].startswith("Invalid file id")

    data = api_client.get_data('/files/0000000000000000000000000/download')
    assert data['message'].startswith("Couldn't find file")
    data = api_client.get_data('/files/!/download')
    assert data['message'].startswith("Invalid file id")

    r = api_client.delete('/files/0000000000000000000000000')
    assert r.status_code == 404
    r = api_client.delete('/files/!')
    assert r.status_code == 400
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
def test_delete_calendar_deletes_events(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    c_data = {'name': 'TBD'}
    resp = api_client.post_data('/calendars', c_data, ns_id)
    resp_data = json.loads(resp.data)
    cal_id = resp_data['id']

    e_data = {
        'calendar_id': cal_id,
        'title': 'subj',
        'description': 'body1',
        'when': {
            'time': 1
        },
        'location': 'InboxHQ'
    }
    api_client.post_data('/events', e_data, ns_id)
    _filter = "?filter=TBD"
    cal_list = api_client.get_data('/calendars' + _filter, ns_id)
    event_id = cal_list[0]['event_ids'][0]

    resp = api_client.get_data('/events/' + event_id, ns_id)

    resp = api_client.delete('/calendars/' + cal_id, ns_id)
    assert resp.status_code == 200

    resp = api_client.get_data('/events/' + event_id, ns_id)
    assert resp['type'] == 'invalid_request_error'
Ejemplo n.º 16
0
def test_delete_remote_draft(db, api_client, message):
    message.is_draft = True
    db.session.commit()

    drafts = api_client.get_data('/drafts')
    assert len(drafts) == 1

    public_id = drafts[0]['id']
    version = drafts[0]['version']

    assert public_id == message.public_id and version == message.version

    api_client.delete('/drafts/{}'.format(public_id), {'version': version})

    # Check that drafts were deleted
    drafts = api_client.get_data('/drafts')
    assert not drafts
Ejemplo n.º 17
0
def test_delete_remote_draft(db, api_client, message):
    message.is_draft = True
    db.session.commit()

    drafts = api_client.get_data("/drafts")
    assert len(drafts) == 1

    public_id = drafts[0]["id"]
    version = drafts[0]["version"]

    assert public_id == message.public_id and version == message.version

    api_client.delete("/drafts/{}".format(public_id), {"version": version})

    # Check that drafts were deleted
    drafts = api_client.get_data("/drafts")
    assert not drafts
Ejemplo n.º 18
0
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']]
Ejemplo n.º 19
0
def test_api_delete(db, api_client, calendar, default_account):
    e_data = {
        'title': '',
        'calendar_id': calendar.public_id,
        'when': {'time': 1407542195},
    }

    e_resp = api_client.post_data('/events', e_data)
    e_resp_data = json.loads(e_resp.data)
    assert e_resp_data['object'] == 'event'
    assert e_resp_data['title'] == e_data['title']
    assert e_resp_data['when']['time'] == e_data['when']['time']
    assert 'id' in e_resp_data
    e_id = e_resp_data['id']

    api_client.delete('/events/' + e_id)

    event = api_client.get_data('/events/' + e_id)
    assert event['type'] == 'invalid_request_error'
Ejemplo n.º 20
0
def test_delete(api_client, uploaded_file_ids, draft):
    non_attachment_id = uploaded_file_ids.pop()
    attachment_id = uploaded_file_ids.pop()
    draft['file_ids'] = [attachment_id]
    r = api_client.post_data('/drafts', draft)
    assert r.status_code == 200

    # Test that we can delete a non-attachment
    r = api_client.delete('/files/{}'.format(non_attachment_id))
    assert r.status_code == 200

    data = api_client.get_data('/files/{}'.format(non_attachment_id))
    assert data['message'].startswith("Couldn't find file")

    # Make sure that we cannot delete attachments
    r = api_client.delete('/files/{}'.format(attachment_id))
    assert r.status_code == 400

    data = api_client.get_data('/files/{}'.format(attachment_id))
    assert data['id'] == attachment_id
Ejemplo n.º 21
0
def test_delete(api_client, uploaded_file_ids, draft):
    non_attachment_id = uploaded_file_ids.pop()
    attachment_id = uploaded_file_ids.pop()
    draft['file_ids'] = [attachment_id]
    r = api_client.post_data('/drafts', draft)
    assert r.status_code == 200

    # Test that we can delete a non-attachment
    r = api_client.delete('/files/{}'.format(non_attachment_id))
    assert r.status_code == 200

    data = api_client.get_data('/files/{}'.format(non_attachment_id))
    assert data['message'].startswith("Couldn't find file")

    # Make sure that we cannot delete attachments
    r = api_client.delete('/files/{}'.format(attachment_id))
    assert r.status_code == 400

    data = api_client.get_data('/files/{}'.format(attachment_id))
    assert data['id'] == attachment_id
Ejemplo n.º 22
0
def test_api_delete(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    e_data = {
        'title': '',
        'when': {'time': 1407542195},
    }

    e_resp = api_client.post_data('/events', e_data, ns_id)
    e_resp_data = json.loads(e_resp.data)
    assert e_resp_data['object'] == 'event'
    assert e_resp_data['namespace_id'] == acct.namespace.public_id
    assert e_resp_data['title'] == e_data['title']
    assert e_resp_data['when']['time'] == e_data['when']['time']
    assert 'id' in e_resp_data
    e_id = e_resp_data['id']

    api_client.delete('/events/' + e_id, ns_id=ns_id)

    event = api_client.get_data('/events/' + e_id, ns_id)
    assert event['type'] == 'invalid_request_error'
Ejemplo n.º 23
0
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"]

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

    r = api_client.delete("/drafts/{}".format(updated_public_id))

    # Check that drafts were deleted
    drafts = api_client.get_data("/drafts")
    assert not drafts
Ejemplo n.º 24
0
def test_delete_readonly_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
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c

    assert read_only_calendar
    cal_id = read_only_calendar['id']

    resp = api_client.delete('/calendars/' + cal_id, ns_id)
    assert resp.status_code == 400
Ejemplo n.º 25
0
def test_delete_readonly_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
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c

    assert read_only_calendar
    cal_id = read_only_calendar['id']

    resp = api_client.delete('/calendars/' + cal_id, ns_id)
    assert resp.status_code == 400
Ejemplo n.º 26
0
def test_delete_calendar(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    c_data = {'name': 'Work'}

    resp = api_client.post_data('/calendars', c_data, ns_id)
    resp_data = json.loads(resp.data)

    cal_id = resp_data['id']

    resp = api_client.delete('/calendars/' + cal_id, ns_id)
    assert resp.status_code == 200

    event = api_client.get_data('/calendars/' + cal_id, ns_id)
    assert event['type'] == 'invalid_request_error'
Ejemplo n.º 27
0
def test_delete_calendar(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    c_data = {'name': 'Work'}

    resp = api_client.post_data('/calendars', c_data, ns_id)
    resp_data = json.loads(resp.data)

    cal_id = resp_data['id']

    resp = api_client.delete('/calendars/' + cal_id, ns_id)
    assert resp.status_code == 200

    event = api_client.get_data('/calendars/' + cal_id, ns_id)
    assert event['type'] == 'invalid_request_error'
Ejemplo n.º 28
0
def test_delete_from_readonly_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
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c
            for e_id in c['event_ids']:
                e = api_client.get_data('/events/' + e_id, ns_id)
                if e['read_only']:
                    read_only_event = e
                    break

    assert read_only_calendar
    assert read_only_event
    e_id = read_only_event['id']
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code != 200
Ejemplo n.º 29
0
def test_delete_from_readonly_calendar(db, api_client):
    calendar_list = api_client.get_data('/calendars')

    read_only_calendar = None
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c
            break
    events = api_client.get_data('/events?calendar_id={}'.format(
        read_only_calendar['id']))
    for event in events:
        if event['read_only']:
            read_only_event = event
            break

    assert read_only_calendar
    assert read_only_event
    e_id = read_only_event['id']
    resp = api_client.delete('/events/{}'.format(e_id))
    assert resp.status_code == 400
Ejemplo n.º 30
0
def test_delete_from_readonly_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
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c
            for e_id in c['event_ids']:
                e = api_client.get_data('/events/' + e_id, ns_id)
                if e['read_only']:
                    read_only_event = e
                    break

    assert read_only_calendar
    assert read_only_event
    e_id = read_only_event['id']
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code != 200
Ejemplo n.º 31
0
def test_api_delete(db, api_client, calendar, default_account):
    e_data = {
        'title': '',
        'calendar_id': calendar.public_id,
        'when': {'time': 1407542195},
    }

    e_resp = api_client.post_data('/events', e_data)
    e_resp_data = json.loads(e_resp.data)
    assert e_resp_data['object'] == 'event'
    assert e_resp_data['title'] == e_data['title']
    assert e_resp_data['when']['time'] == e_data['when']['time']
    assert 'id' in e_resp_data
    e_id = e_resp_data['id']

    e_delete_resp = api_client.delete('/events/' + e_id)
    assert e_delete_resp.status_code == 200

    e_resp = api_client.get_data('/events/' + e_id)
    assert e_resp['status'] == 'cancelled'
Ejemplo n.º 32
0
def test_api_delete(db, api_client, calendar, default_account):
    e_data = {
        'title': '',
        'calendar_id': calendar.public_id,
        'when': {
            'time': 1407542195
        },
    }

    e_resp = api_client.post_data('/events', e_data)
    e_resp_data = json.loads(e_resp.data)
    assert e_resp_data['object'] == 'event'
    assert e_resp_data['title'] == e_data['title']
    assert e_resp_data['when']['time'] == e_data['when']['time']
    assert 'id' in e_resp_data
    e_id = e_resp_data['id']

    e_delete_resp = api_client.delete('/events/' + e_id)
    assert e_delete_resp.status_code == 200

    e_resp = api_client.get_data('/events/' + e_id)
    assert e_resp['status'] == 'cancelled'
Ejemplo n.º 33
0
def test_delete_from_readonly_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
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c
            break
    events = api_client.get_data('/events?calendar_id={}'.format(
        read_only_calendar['id']))
    for event in events:
        if event['read_only']:
            read_only_event = event
            break

    assert read_only_calendar
    assert read_only_event
    e_id = read_only_event['id']
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code == 400
Ejemplo n.º 34
0
def test_delete_from_readonly_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
    for c in calendar_list:
        if c['read_only']:
            read_only_calendar = c
            break
    events = api_client.get_data('/events?calendar_id={}'.format(
        read_only_calendar['id']))
    for event in events:
        if event['read_only']:
            read_only_event = event
            break

    assert read_only_calendar
    assert read_only_event
    e_id = read_only_event['id']
    resp = api_client.delete('/events/' + e_id, ns_id=ns_id)
    assert resp.status_code == 400
Ejemplo n.º 35
0
def test_delete_calendar_deletes_events(db, api_client):
    acct = db.session.query(Account).filter_by(id=ACCOUNT_ID).one()
    ns_id = acct.namespace.public_id

    c_data = {'name': 'TBD'}
    resp = api_client.post_data('/calendars', c_data, ns_id)
    resp_data = json.loads(resp.data)
    cal_id = resp_data['id']

    e_data = {'calendar_id': cal_id,
              'title': 'subj', 'description': 'body1',
              'when': {'time': 1}, 'location': 'InboxHQ'}
    api_client.post_data('/events', e_data, ns_id)
    _filter = "?filter=TBD"
    cal_list = api_client.get_data('/calendars' + _filter, ns_id)
    event_id = cal_list[0]['event_ids'][0]

    resp = api_client.get_data('/events/' + event_id, ns_id)

    resp = api_client.delete('/calendars/' + cal_id, ns_id)
    assert resp.status_code == 200

    resp = api_client.get_data('/events/' + event_id, ns_id)
    assert resp['type'] == 'invalid_request_error'
Ejemplo n.º 36
0
def test_create_draft_with_attachments(api_client, attachments, example_draft):
    attachment_ids = []
    upload_path = api_client.full_path('/files')
    for filename, path in attachments:
        data = {'file': (open(path, 'rb'), filename)}
        r = api_client.client.post(upload_path, data=data)
        assert r.status_code == 200
        attachment_id = json.loads(r.data)[0]['id']
        attachment_ids.append(attachment_id)

    first_attachment = attachment_ids.pop()

    example_draft['file_ids'] = [first_attachment]
    r = api_client.post_data('/drafts', example_draft)
    assert r.status_code == 200
    returned_draft = json.loads(r.data)
    draft_public_id = returned_draft['id']
    example_draft['version'] = returned_draft['version']
    assert len(returned_draft['files']) == 1

    attachment_ids.append(first_attachment)
    example_draft['file_ids'] = attachment_ids
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            example_draft)
    assert r.status_code == 200
    returned_draft = json.loads(r.data)
    assert len(returned_draft['files']) == 3
    example_draft['version'] = returned_draft['version']

    # Make sure we can't delete the files now
    for file_id in attachment_ids:
        r = api_client.delete('/files/{}'.format(file_id))
        assert r.status_code == 400

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

    # Check that thread also gets the attachment tag
    thread_tags = threads_with_drafts[0]['tags']
    assert any('attachment' == tag['name'] for tag in thread_tags)

    # Now remove the attachment
    example_draft['file_ids'] = [first_attachment]
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            example_draft)

    draft_data = api_client.get_data('/drafts/{}'.format(draft_public_id))
    assert len(draft_data['files']) == 1
    example_draft['version'] = draft_data['version']

    example_draft['file_ids'] = []
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            example_draft)
    draft_data = api_client.get_data('/drafts/{}'.format(draft_public_id))
    assert r.status_code == 200
    assert len(draft_data['files']) == 0
    returned_draft = json.loads(r.data)

    # now that they're not attached, we should be able to delete them
    for file_id in attachment_ids:
        r = api_client.delete('/files/{}'.format(file_id))
        assert r.status_code == 200
Ejemplo n.º 37
0
def test_create_draft_with_attachments(api_client, attachments, example_draft):
    attachment_ids = []
    upload_path = api_client.full_path("/files")
    for filename, path in attachments:
        data = {"file": (open(path, "rb"), filename)}
        r = api_client.client.post(upload_path, data=data)
        assert r.status_code == 200
        attachment_id = json.loads(r.data)[0]["id"]
        attachment_ids.append(attachment_id)

    first_attachment = attachment_ids.pop()

    example_draft["file_ids"] = [first_attachment]
    r = api_client.post_data("/drafts", example_draft)
    assert r.status_code == 200
    returned_draft = json.loads(r.data)
    draft_public_id = returned_draft["id"]
    assert returned_draft["version"] == 0
    example_draft["version"] = returned_draft["version"]
    assert len(returned_draft["files"]) == 1

    attachment_ids.append(first_attachment)
    example_draft["file_ids"] = attachment_ids
    r = api_client.put_data("/drafts/{}".format(draft_public_id), example_draft)
    assert r.status_code == 200
    returned_draft = json.loads(r.data)
    assert len(returned_draft["files"]) == 3
    assert returned_draft["version"] == 1
    example_draft["version"] = returned_draft["version"]

    # Make sure we can't delete the files now
    for file_id in attachment_ids:
        r = api_client.delete("/files/{}".format(file_id))
        assert r.status_code == 400

    threads_with_drafts = api_client.get_data("/threads?tag=drafts")
    assert len(threads_with_drafts) == 1

    # Check that thread also gets the attachment tag
    thread_tags = threads_with_drafts[0]["tags"]
    assert any("attachment" == tag["name"] for tag in thread_tags)

    # Now remove the attachment
    example_draft["file_ids"] = [first_attachment]
    r = api_client.put_data("/drafts/{}".format(draft_public_id), example_draft)

    draft_data = api_client.get_data("/drafts/{}".format(draft_public_id))
    assert len(draft_data["files"]) == 1
    assert draft_data["version"] == 2
    example_draft["version"] = draft_data["version"]

    example_draft["file_ids"] = []
    r = api_client.put_data("/drafts/{}".format(draft_public_id), example_draft)
    draft_data = api_client.get_data("/drafts/{}".format(draft_public_id))
    assert r.status_code == 200
    assert len(draft_data["files"]) == 0
    assert draft_data["version"] == 3

    # now that they're not attached, we should be able to delete them
    for file_id in attachment_ids:
        r = api_client.delete("/files/{}".format(file_id))
        assert r.status_code == 200
Ejemplo n.º 38
0
def test_create_draft_with_attachments(api_client, attachments, example_draft):
    attachment_ids = []
    upload_path = api_client.full_path('/files')
    for filename, path in attachments:
        data = {'file': (open(path, 'rb'), filename)}
        r = api_client.client.post(upload_path, data=data)
        assert r.status_code == 200
        attachment_id = json.loads(r.data)[0]['id']
        attachment_ids.append(attachment_id)

    first_attachment = attachment_ids.pop()

    example_draft['file_ids'] = [first_attachment]
    r = api_client.post_data('/drafts', example_draft)
    assert r.status_code == 200
    returned_draft = json.loads(r.data)
    draft_public_id = returned_draft['id']
    example_draft['version'] = returned_draft['version']
    assert len(returned_draft['files']) == 1

    attachment_ids.append(first_attachment)
    example_draft['file_ids'] = attachment_ids
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            example_draft)
    assert r.status_code == 200
    returned_draft = json.loads(r.data)
    assert len(returned_draft['files']) == 3
    example_draft['version'] = returned_draft['version']

    # Make sure we can't delete the files now
    for file_id in attachment_ids:
        r = api_client.delete('/files/{}'.format(file_id))
        assert r.status_code == 400

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

    # Check that thread also gets the attachment tag
    thread_tags = threads_with_drafts[0]['tags']
    assert any('attachment' == tag['name'] for tag in thread_tags)

    # Now remove the attachment
    example_draft['file_ids'] = [first_attachment]
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            example_draft)

    draft_data = api_client.get_data('/drafts/{}'.format(draft_public_id))
    assert len(draft_data['files']) == 1
    example_draft['version'] = draft_data['version']

    example_draft['file_ids'] = []
    r = api_client.put_data('/drafts/{}'.format(draft_public_id),
                            example_draft)
    draft_data = api_client.get_data('/drafts/{}'.format(draft_public_id))
    assert r.status_code == 200
    assert len(draft_data['files']) == 0
    returned_draft = json.loads(r.data)

    # now that they're not attached, we should be able to delete them
    for file_id in attachment_ids:
        r = api_client.delete('/files/{}'.format(file_id))
        assert r.status_code == 200