Exemple #1
0
def test_update(db, config, action_queue, message, attach):
    from inbox.server.sendmail.base import create_draft, update_draft
    from inbox.server.models.tables.base import Account

    account = db.session.query(Account).get(ACCOUNT_ID)
    to, subject, body = message
    attachment = attach
    cc = '*****@*****.**'
    bcc = None

    original_draft = create_draft(db.session, account, None,
                                  'Parent draft', 'Parent draft',
                                  None, None)
    assert original_draft, 'original draft message missing'
    original_id = original_draft.public_id

    # Update a 'valid' draft
    updated_draft = update_draft(db.session, account, original_id, to, subject,
                                 body, attachment, cc, bcc)
    assert updated_draft, 'updated draft message missing'
    updated_id = updated_draft.public_id

    assert original_id != updated_id,\
        'updated draft message has same public_id as original draft'

    assert updated_draft.parent_draft.public_id == original_id,\
        'updated draft has incorrect parent_draft'

    # Update an already-updated draft
    reupdated_draft = update_draft(db.session, account, original_id, to,
                                   subject, body, attachment, cc, bcc)

    assert reupdated_draft.parent_draft.public_id != original_id,\
        'copy of original draft not created'

    assert reupdated_draft.parent_draft.draft_copied_from ==\
        original_draft.id,\
        'copy of original draft has incorrect draft_copied_from id'

    cleanup(account, subject)
Exemple #2
0
def test_update(db, config, action_queue, message, attach):
    from inbox.server.sendmail.base import create_draft, update_draft
    from inbox.server.models.tables.base import Account

    account = db.session.query(Account).get(ACCOUNT_ID)
    to, subject, body = message
    attachment = attach
    cc = '*****@*****.**'
    bcc = None

    original_draft = create_draft(db.session, account, None, 'Parent draft',
                                  'Parent draft', None, None)
    assert original_draft, 'original draft message missing'
    original_id = original_draft.public_id

    # Update a 'valid' draft
    updated_draft = update_draft(db.session, account, original_id, to, subject,
                                 body, attachment, cc, bcc)
    assert updated_draft, 'updated draft message missing'
    updated_id = updated_draft.public_id

    assert original_id != updated_id,\
        'updated draft message has same public_id as original draft'

    assert updated_draft.parent_draft.public_id == original_id,\
        'updated draft has incorrect parent_draft'

    # Update an already-updated draft
    reupdated_draft = update_draft(db.session, account, original_id, to,
                                   subject, body, attachment, cc, bcc)

    assert reupdated_draft.parent_draft.public_id != original_id,\
        'copy of original draft not created'

    assert reupdated_draft.parent_draft.draft_copied_from ==\
        original_draft.id,\
        'copy of original draft has incorrect draft_copied_from id'

    cleanup(account, subject)
Exemple #3
0
def test_delete(db, config, action_queue, message, attach):
    from inbox.server.sendmail.base import (create_draft, update_draft,
                                            delete_draft)
    from inbox.server.models.tables.base import SpoolMessage, Account

    account = db.session.query(Account).get(ACCOUNT_ID)
    to, subject, body = message
    attachment = attach
    cc = '*****@*****.**'
    bcc = None

    original_draft = create_draft(db.session, account, None,
                                  'Parent draft', 'Parent draft',
                                  None, None)
    assert original_draft, 'original draft message missing'
    original_id = original_draft.public_id

    updated_draft = update_draft(db.session, account, original_id, to, subject,
                                 body, attachment, cc, bcc)
    assert updated_draft, 'updated draft message missing'
    updated_id = updated_draft.public_id

    delete_draft(db.session, account, updated_id)

    with pytest.raises(NoResultFound):
        db.session.query(SpoolMessage).filter_by(
            public_id=updated_id).one()

        db.session.query(SpoolMessage).filter_by(
            public_id=original_id).one()

    new_count = db.session.query(SpoolMessage).filter_by(
        public_id=updated_id).count()
    assert new_count == 0, 'new draft not deleted'

    old_count = db.session.query(SpoolMessage).filter_by(
        public_id=original_id).count()
    assert old_count == 0, 'original draft not deleted'

    cleanup(account, subject)
Exemple #4
0
def test_delete(db, config, action_queue, message, attach):
    from inbox.server.sendmail.base import (create_draft, update_draft,
                                            delete_draft)
    from inbox.server.models.tables.base import SpoolMessage, Account

    account = db.session.query(Account).get(ACCOUNT_ID)
    to, subject, body = message
    attachment = attach
    cc = '*****@*****.**'
    bcc = None

    original_draft = create_draft(db.session, account, None, 'Parent draft',
                                  'Parent draft', None, None)
    assert original_draft, 'original draft message missing'
    original_id = original_draft.public_id

    updated_draft = update_draft(db.session, account, original_id, to, subject,
                                 body, attachment, cc, bcc)
    assert updated_draft, 'updated draft message missing'
    updated_id = updated_draft.public_id

    delete_draft(db.session, account, updated_id)

    with pytest.raises(NoResultFound):
        db.session.query(SpoolMessage).filter_by(public_id=updated_id).one()

        db.session.query(SpoolMessage).filter_by(public_id=original_id).one()

    new_count = db.session.query(SpoolMessage).filter_by(
        public_id=updated_id).count()
    assert new_count == 0, 'new draft not deleted'

    old_count = db.session.query(SpoolMessage).filter_by(
        public_id=original_id).count()
    assert old_count == 0, 'original draft not deleted'

    cleanup(account, subject)
Exemple #5
0
def test_update_reply(db, config, action_queue, message, attach):
    from inbox.server.sendmail.base import create_draft, update_draft
    from inbox.server.models.tables.base import Account, Thread, DraftThread

    account = db.session.query(Account).get(ACCOUNT_ID)
    to, subject, body = message
    attachment = attach
    cc = '*****@*****.**'
    bcc = None

    thread = db.session.query(Thread).filter(
        Thread.namespace_id == NAMESPACE_ID,
        Thread.id == THREAD_ID).one()
    thread_public_id = thread.public_id

    original_draft = create_draft(db.session, account, to, subject, body,
                                  attachment, cc, bcc, thread_public_id)
    assert original_draft, 'original draft message missing'
    original_id = original_draft.public_id

    # Update a 'valid' draft
    updated_draft = update_draft(db.session, account, original_id, to, subject,
                                 body, attachment, cc, bcc)
    assert updated_draft, 'updated draft message missing'
    updated_id = updated_draft.public_id

    assert original_id != updated_id,\
        'updated draft message has same public_id as original draft'

    assert updated_draft.parent_draft.public_id == original_draft.public_id,\
        'updated draft has incorrect parent_draft'

    assert original_draft.replyto_thread_id == \
        updated_draft.replyto_thread_id, \
        'updated draft has incorrect replyto_thread_id'

    # Update an already-updated draft
    reupdated_draft = update_draft(db.session, account, original_id, to,
                                   subject, body, attachment, cc, bcc)

    assert reupdated_draft.parent_draft.public_id != \
        original_draft.public_id, 'copy of original draft not created'

    assert reupdated_draft.parent_draft.draft_copied_from == \
        original_draft.id, \
        'copy of original draft has incorrect draft_copied_from id'

    assert reupdated_draft.replyto_thread_id != \
        updated_draft.replyto_thread_id, \
        'copy of draftthread not created'

    draftthread = db.session.query(DraftThread).get(
        reupdated_draft.replyto_thread_id)
    assert draftthread, 'copy of draftthread missing'

    thread_copy_1 = updated_draft.replyto_thread
    thread_copy_2 = reupdated_draft.replyto_thread

    assert thread_copy_2.master_public_id == thread_copy_1.master_public_id \
        and thread_copy_2.thread_id == thread_copy_1.thread_id and \
        thread_copy_2.message_id == thread_copy_1.message_id, \
        'copy of draftthread has incorrect references'

    cleanup(account, subject)
Exemple #6
0
def test_update_reply(db, config, action_queue, message, attach):
    from inbox.server.sendmail.base import create_draft, update_draft
    from inbox.server.models.tables.base import Account, Thread, DraftThread

    account = db.session.query(Account).get(ACCOUNT_ID)
    to, subject, body = message
    attachment = attach
    cc = '*****@*****.**'
    bcc = None

    thread = db.session.query(Thread).filter(
        Thread.namespace_id == NAMESPACE_ID, Thread.id == THREAD_ID).one()
    thread_public_id = thread.public_id

    original_draft = create_draft(db.session, account, to, subject, body,
                                  attachment, cc, bcc, thread_public_id)
    assert original_draft, 'original draft message missing'
    original_id = original_draft.public_id

    # Update a 'valid' draft
    updated_draft = update_draft(db.session, account, original_id, to, subject,
                                 body, attachment, cc, bcc)
    assert updated_draft, 'updated draft message missing'
    updated_id = updated_draft.public_id

    assert original_id != updated_id,\
        'updated draft message has same public_id as original draft'

    assert updated_draft.parent_draft.public_id == original_draft.public_id,\
        'updated draft has incorrect parent_draft'

    assert original_draft.replyto_thread_id == \
        updated_draft.replyto_thread_id, \
        'updated draft has incorrect replyto_thread_id'

    # Update an already-updated draft
    reupdated_draft = update_draft(db.session, account, original_id, to,
                                   subject, body, attachment, cc, bcc)

    assert reupdated_draft.parent_draft.public_id != \
        original_draft.public_id, 'copy of original draft not created'

    assert reupdated_draft.parent_draft.draft_copied_from == \
        original_draft.id, \
        'copy of original draft has incorrect draft_copied_from id'

    assert reupdated_draft.replyto_thread_id != \
        updated_draft.replyto_thread_id, \
        'copy of draftthread not created'

    draftthread = db.session.query(DraftThread).get(
        reupdated_draft.replyto_thread_id)
    assert draftthread, 'copy of draftthread missing'

    thread_copy_1 = updated_draft.replyto_thread
    thread_copy_2 = reupdated_draft.replyto_thread

    assert thread_copy_2.master_public_id == thread_copy_1.master_public_id \
        and thread_copy_2.thread_id == thread_copy_1.thread_id and \
        thread_copy_2.message_id == thread_copy_1.message_id, \
        'copy of draftthread has incorrect references'

    cleanup(account, subject)