当前位置: 首页>>代码示例>>Python>>正文


Python base.add_fake_message函数代码示例

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


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

示例1: test_namespace_limiting

def test_namespace_limiting(db, test_client):
    dt = datetime.datetime.utcnow()
    subject = dt.isoformat()
    db.session.add(Namespace())
    db.session.commit()
    namespaces = db.session.query(Namespace).all()
    assert len(namespaces) > 1
    for ns in namespaces:
        thread = Thread(namespace=ns, subjectdate=dt, recentdate=dt,
                        subject=subject)
        add_fake_message(db.session, ns.id, thread, received_date=dt,
                         subject=subject)
        db.session.add(Block(namespace=ns, filename=subject))
    db.session.commit()

    for ns in namespaces:
        r = json.loads(test_client.get('/n/{}/threads?subject={}'.
                                       format(ns.public_id, subject)).data)
        assert len(r) == 1

        r = json.loads(test_client.get('/n/{}/messages?subject={}'.
                                       format(ns.public_id, subject)).data)
        assert len(r) == 1

        r = json.loads(test_client.get('/n/{}/files?filename={}'.
                                       format(ns.public_id, subject)).data)
        assert len(r) == 1
开发者ID:Analect,项目名称:sync-engine,代码行数:27,代码来源:test_filtering.py

示例2: test_update_metadata

def test_update_metadata(db, folder):
    """Check that threads are updated correctly when a label that we haven't
    seen before is added to multiple threads -- previously, this would fail
    with an IntegrityError because autoflush was disabled."""
    first_thread = add_fake_thread(db.session, NAMESPACE_ID)
    second_thread = add_fake_thread(db.session, NAMESPACE_ID)
    uids = []

    first_thread_uids = (22222, 22223)
    for msg_uid in first_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, first_thread)
        uids.append(add_fake_imapuid(db.session, ACCOUNT_ID, message, folder, msg_uid))

    second_thread_uids = (22224, 22226)
    for msg_uid in second_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, second_thread)
        uids.append(add_fake_imapuid(db.session, ACCOUNT_ID, message, folder, msg_uid))
    db.session.add_all(uids)
    db.session.commit()

    msg_uids = first_thread_uids + second_thread_uids

    new_flags = {msg_uid: GmailFlags((), (u"\\some_new_label",)) for msg_uid in msg_uids}
    update_metadata(ACCOUNT_ID, db.session, folder.name, folder.id, msg_uids, new_flags)
    db.session.commit()
    assert "some_new_label" in [tag.name for tag in first_thread.tags]
    assert "some_new_label" in [tag.name for tag in second_thread.tags]
开发者ID:apolmig,项目名称:inbox,代码行数:27,代码来源:test_update_metadata.py

示例3: test_message_updates_create_transaction

def test_message_updates_create_transaction(db):
    with session_scope() as db_session:
        with db_session.no_autoflush:
            thr = add_fake_thread(db_session, NAMESPACE_ID)
            msg = add_fake_message(db_session, NAMESPACE_ID, thr)

            msg.is_read = True
            db_session.commit()
            transaction = get_latest_transaction(db_session, 'message', msg.id,
                                                 NAMESPACE_ID)
            assert transaction.record_id == msg.id
            assert transaction.object_type == 'message'
            assert transaction.command == 'update'

            msg = add_fake_message(db_session, NAMESPACE_ID, thr)
            msg.state = 'sent'
            db_session.commit()
            transaction = get_latest_transaction(db_session, 'message', msg.id,
                                                 NAMESPACE_ID)
            assert transaction.record_id == msg.id
            assert transaction.object_type == 'message'
            assert transaction.command == 'update'

            msg = add_fake_message(db_session, NAMESPACE_ID, thr)
            msg.is_draft = True
            db_session.commit()
            transaction = get_latest_transaction(db_session, 'message', msg.id,
                                                 NAMESPACE_ID)
            assert transaction.record_id == msg.id
            assert transaction.object_type == 'message'
            assert transaction.command == 'update'
开发者ID:GEverding,项目名称:inbox,代码行数:31,代码来源:test_transaction_creation.py

示例4: test_basic_message_grouping

def test_basic_message_grouping(db, default_namespace):
    first_thread = add_fake_thread(db.session, default_namespace.id)
    first_thread.subject = 'Some kind of test'

    add_fake_message(db.session, default_namespace.id,
                     thread=first_thread,
                     subject='Some kind of test',
                     from_addr=[('Karim Hamidou', '[email protected]')],
                     to_addr=[('Eben Freeman', '[email protected]')],
                     bcc_addr=[('Some person', '[email protected]')])

    msg2 = add_fake_message(db.session, default_namespace.id, thread=None,
                            subject='Re: Some kind of test',
                            from_addr=[('Some random dude',
                                        '[email protected]')],
                            to_addr=[('Karim Hamidou', '[email protected]')])

    matched_thread = fetch_corresponding_thread(db.session,
                                                default_namespace.id, msg2)
    assert matched_thread is None, "the algo shouldn't thread different convos"

    msg3 = add_fake_message(db.session, default_namespace.id, thread=None)
    msg3.subject = 'Re: Some kind of test'
    msg3.from_addr = [('Eben Freeman', '[email protected]')]
    msg3.to_addr =   [('Karim Hamidou', '[email protected]')]

    matched_thread = fetch_corresponding_thread(db.session, default_namespace.id, msg3)
    assert matched_thread is first_thread, "Should match on participants"
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:28,代码来源:test_threading.py

示例5: test_thread_count

def test_thread_count(db, api_client, default_account):
    date1 = datetime.datetime(2015, 1, 1, 0, 0, 0)
    date2 = datetime.datetime(2012, 1, 1, 0, 0, 0)
    date3 = datetime.datetime(2010, 1, 1, 0, 0, 0)
    date4 = datetime.datetime(2009, 1, 1, 0, 0, 0)
    date5 = datetime.datetime(2008, 1, 1, 0, 0, 0)

    thread1 = add_fake_thread(db.session, default_account.namespace.id)
    thread2 = add_fake_thread(db.session, default_account.namespace.id)

    test_subject = "test_thread_view_count_with_category"

    for thread in [thread1, thread2]:
        add_fake_message(db.session, default_account.namespace.id, thread,
                         subject=test_subject, received_date=date1)
        add_fake_message(db.session, default_account.namespace.id, thread,
                         subject=test_subject, received_date=date2,
                         add_sent_category=True)
        add_fake_message(db.session, default_account.namespace.id, thread,
                         subject=test_subject, received_date=date3)
        add_fake_message(db.session, default_account.namespace.id, thread,
                         subject=test_subject, received_date=date4,
                         add_sent_category=True)
        add_fake_message(db.session, default_account.namespace.id, thread,
                         subject=test_subject, received_date=date5)

    resp = api_client.get_raw('/threads/?view=count&in=sent')
    assert resp.status_code == 200
    threads = json.loads(resp.data)
    assert threads['count'] == 2
开发者ID:busseyl,项目名称:sync-engine,代码行数:30,代码来源:test_threads.py

示例6: test_thread_sent_recent_date

def test_thread_sent_recent_date(db, api_client, default_account):
    date1 = datetime.datetime(2015, 1, 1, 0, 0, 0)
    date2 = datetime.datetime(2012, 1, 1, 0, 0, 0)
    date3 = datetime.datetime(2010, 1, 1, 0, 0, 0)
    date4 = datetime.datetime(2009, 1, 1, 0, 0, 0)
    date5 = datetime.datetime(2008, 1, 1, 0, 0, 0)

    thread1 = add_fake_thread(db.session, default_account.namespace.id)

    test_subject = "test_thread_sent_recent_date"

    add_fake_message(db.session, default_account.namespace.id, thread1,
                     subject=test_subject, received_date=date1)
    add_fake_message(db.session, default_account.namespace.id, thread1,
                     subject=test_subject, received_date=date2,
                     add_sent_category=True)
    add_fake_message(db.session, default_account.namespace.id, thread1,
                     subject=test_subject, received_date=date3)
    add_fake_message(db.session, default_account.namespace.id, thread1,
                     subject=test_subject, received_date=date4,
                     add_sent_category=True)
    add_fake_message(db.session, default_account.namespace.id, thread1,
                     subject=test_subject, received_date=date5)

    resp = api_client.get_raw('/threads/')
    assert resp.status_code == 200
    threads = json.loads(resp.data)

    for thread in threads:  # should only be one
        assert datetime.datetime.fromtimestamp(
            thread['last_message_sent_timestamp']) == date2
开发者ID:busseyl,项目名称:sync-engine,代码行数:31,代码来源:test_threads.py

示例7: test_update_contacts_from_message

def test_update_contacts_from_message(db):
    thread = db.session.query(Thread).filter_by(
        namespace_id=NAMESPACE_ID).first()
    # Check that only one Contact is created for repeatedly-referenced
    # addresses.
    add_fake_message(db.session, NAMESPACE_ID, thread,
                     from_addr=[('', '[email protected]')],
                     cc_addr=[('', '[email protected]')])

    assert db.session.query(Contact).filter_by(
        email_address='[email protected]').count() == 1

    # Check that existing Contacts are used when we process a new message
    # referencing them.
    add_fake_message(db.session, NAMESPACE_ID, thread,
                     from_addr=[('', '[email protected]')],
                     cc_addr=[('', '[email protected]')],
                     to_addr=[('', '[email protected]'),
                              ('', '[email protected]')])

    assert db.session.query(Contact).filter(
        Contact.email_address.like('%@example.com')).count() == 3
    alpha = db.session.query(Contact).filter_by(
        email_address='[email protected]').one()
    assert len(alpha.message_associations) == 4
开发者ID:Dracophoenix1,项目名称:inbox,代码行数:25,代码来源:test_process_mail.py

示例8: test_update_metadata

def test_update_metadata(db):
    """Check that threads are updated correctly when a label that we haven't
    seen before is added to multiple threads -- previously, this would with an
    IntegrityError because autoflush was disabled."""
    first_thread = db.session.query(Thread).get(1)
    second_thread = db.session.query(Thread).get(2)
    folder = db.session.query(Folder).filter(
        Folder.account_id == ACCOUNT_ID,
        Folder.name == '[Gmail]/All Mail').one()
    uids = []

    first_thread_uids = (22222, 22223)
    for msg_uid in first_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, first_thread)
        uids.append(ImapUid(account_id=ACCOUNT_ID, message=message,
                            msg_uid=msg_uid, folder=folder))

    second_thread_uids = (22224, 22226)
    for msg_uid in second_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, second_thread)
        uids.append(ImapUid(account_id=ACCOUNT_ID, message=message,
                            msg_uid=msg_uid, folder=folder))
    db.session.add_all(uids)
    db.session.commit()

    msg_uids = first_thread_uids + second_thread_uids

    new_flags = {msg_uid: GmailFlags((), (u'\\some_new_label',))
                 for msg_uid in msg_uids}
    update_metadata(ACCOUNT_ID, db.session, folder.name, folder.id, msg_uids,
                    new_flags)
    db.session.commit()
    assert 'some_new_label' in [tag.name for tag in first_thread.tags]
    assert 'some_new_label' in [tag.name for tag in second_thread.tags]
开发者ID:Dracophoenix1,项目名称:inbox,代码行数:34,代码来源:test_update_metadata.py

示例9: test_received_before_after

def test_received_before_after(db, api_client, default_namespace):
    thread = add_fake_thread(db.session, default_namespace.id)
    message = add_fake_message(db.session, default_namespace.id, thread,
                               to_addr=[('Bob', '[email protected]')],
                               from_addr=[('Alice', '[email protected]')],
                               received_date=datetime.datetime(year=1999,
                                                               day=20,
                                                               month=03),
                               subject='some subject')

    thread2 = add_fake_thread(db.session, default_namespace.id)
    message2 = add_fake_message(db.session, default_namespace.id, thread,
                                to_addr=[('Bob', '[email protected]')],
                                from_addr=[('Alice', '[email protected]')],
                                received_date=datetime.datetime(year=2000,
                                                                day=20,
                                                                month=03),
                                subject='another subject')

    inbox = Category(namespace_id=message.namespace_id, name='inbox',
                     display_name='Inbox', type_='label')
    message.categories.add(inbox)
    thread.subject = message.subject

    message2.categories.add(inbox)
    thread2.subject = message2.subject

    db.session.commit()

    received_date = message.received_date
    t_epoch = dt_to_timestamp(datetime.datetime(year=1998, month=2, day=3))
    t_firstmsg = dt_to_timestamp(received_date)

    results = api_client.get_data('/messages?received_before={}'
                                  .format(t_epoch))
    assert len(results) == 0

    # received_before should be inclusive (i.e: match <=, not just <).
    results = api_client.get_data('/messages?received_before={}'
                                  .format(t_firstmsg))
    assert len(results) == 1

    t1 = dt_to_timestamp(received_date + datetime.timedelta(days=1))
    results = api_client.get_data('/messages?received_after={}'
                                  .format(t1))
    assert len(results) == 1

    results = api_client.get_data(
        '/messages?received_before={}&received_after={}'.format(t1,
                                                                t_firstmsg))
    assert len(results) == 0

    # bogus values
    results = api_client.get_data(
        '/messages?received_before={}&received_after={}'.format(t_epoch, t1))
    assert len(results) == 0
开发者ID:nohobby,项目名称:sync-engine,代码行数:56,代码来源:test_filtering.py

示例10: test_reject_incompatible_reply_thread_and_message

def test_reject_incompatible_reply_thread_and_message(db, api_client, message, thread, default_namespace):
    alt_thread = add_fake_thread(db.session, default_namespace.id)
    add_fake_message(db.session, default_namespace.id, alt_thread)

    thread = api_client.get_data("/threads")[0]
    alt_message_id = api_client.get_data("/threads")[1]["message_ids"][0]
    alt_message = api_client.get_data("/messages/{}".format(alt_message_id))
    assert thread["id"] != alt_message["thread_id"]
    reply_draft = {"subject": "test reply", "reply_to_message_id": alt_message["id"], "thread_id": thread["id"]}
    r = api_client.post_data("/drafts", reply_draft)
    assert r.status_code == 400
开发者ID:busseyl,项目名称:sync-engine,代码行数:11,代码来源:test_drafts.py

示例11: test_namespace_deletion

def test_namespace_deletion(db, default_account):
    from inbox.models import (Account, Thread, Message, Block,
                              Contact, Event, Transaction)
    from inbox.models.util import delete_namespace

    models = [Thread, Message]

    namespace = default_account.namespace
    namespace_id = namespace.id
    account_id = default_account.id

    account = db.session.query(Account).get(account_id)
    assert account

    thread = add_fake_thread(db.session, namespace_id)

    message = add_fake_message(db.session, namespace_id, thread)

    for m in models:
        c = db.session.query(m).filter(
            m.namespace_id == namespace_id).count()
        print "count for", m, ":", c
        assert c != 0

    fake_account = add_fake_account(db.session)
    fake_account_id = fake_account.id

    assert fake_account_id != account.id and \
        fake_account.namespace.id != namespace_id

    thread = add_fake_thread(db.session, fake_account.namespace.id)
    thread_id = thread.id

    message = add_fake_message(db.session, fake_account.namespace.id, thread)
    message_id = message.id

    # Delete namespace, verify data corresponding to this namespace /only/
    # is deleted
    delete_namespace(account_id, namespace_id)
    db.session.commit()

    account = db.session.query(Account).get(account_id)
    assert not account

    for m in models:
        assert db.session.query(m).filter(
            m.namespace_id == namespace_id).count() == 0

    fake_account = db.session.query(Account).get(fake_account_id)
    assert fake_account

    thread = db.session.query(Thread).get(thread_id)
    message = db.session.query(Message).get(message_id)
    assert thread and message
开发者ID:rskumar,项目名称:sync-engine,代码行数:54,代码来源:test_namespace.py

示例12: stub_message

def stub_message(db, new_message_from_synced, default_namespace, thread):
    message = add_fake_message(
        db.session,
        default_namespace.id,
        thread,
        subject="Golden Gate Park next Sat",
        from_addr=[("alice", "[email protected]")],
        to_addr=[("bob", "[email protected]")],
    )
    message.snippet = "Banh mi paleo pickled, sriracha"
    message.body = """
Banh mi paleo pickled, sriracha biodiesel chambray seitan
mumblecore mustache. Raw denim gastropub 8-bit, butcher
PBR sartorial photo booth Pinterest blog Portland roof party
cliche bitters aesthetic. Ugh.
"""

    message = add_fake_message(
        db.session,
        default_namespace.id,
        thread,
        subject="Re:Golden Gate Park next Sat",
        from_addr=[("bob", "[email protected]")],
        to_addr=[("alice", "[email protected]")],
        cc_addr=[("Cheryl", "[email protected]")],
    )
    message.snippet = "Bushwick meggings ethical keffiyeh"
    message.body = """
Bushwick meggings ethical keffiyeh. Chambray lumbersexual wayfarers,
irony Banksy cred bicycle rights scenester artisan tote bag YOLO gastropub.
"""

    draft = add_fake_message(
        db.session,
        default_namespace.id,
        thread,
        subject="Re:Golden Gate Park next Sat",
        from_addr=[("alice", "[email protected]")],
        to_addr=[("bob", "[email protected]")],
        cc_addr=[("Cheryl", "[email protected]")],
    )
    draft.snippet = "Hey there friend writing a draft"
    draft.body = """
DIY tousled Tumblr, VHS meditation 3 wolf moon listicle fingerstache viral
bicycle rights. Thundercats kale chips church-key American Apparel.
"""
    draft.is_draft = True
    draft.reply_to_message = message

    db.session.commit()
    return message
开发者ID:nohobby,项目名称:sync-engine,代码行数:51,代码来源:test_messages.py

示例13: test_generic_grouping

def test_generic_grouping(db, generic_account):
    thread = add_fake_thread(db.session, NAMESPACE_ID)
    message = add_fake_message(db.session, NAMESPACE_ID, thread,
                               subject="Golden Gate Park next Sat")
    imapuid = ImapUid(message=message, account_id=ACCOUNT_ID,
                      msg_uid=2222)

    thread = add_fake_thread(db.session, generic_account.namespace.id)
    message = add_fake_message(db.session, NAMESPACE_ID + 1, thread,
                               subject="Golden Gate Park next Sat")

    thread = fetch_corresponding_thread(db.session, generic_account.namespace.id, message)
    assert thread is None, ("fetch_similar_threads should "
                             "heed namespace boundaries")
开发者ID:Analect,项目名称:sync-engine,代码行数:14,代码来源:test_thread_creation.py

示例14: stub_message

def stub_message(db):
    namespace_id = default_namespace(db).id
    # new_msg = new_message_from_synced
    # fake_thread = add_fake_thread(db.session, NAMESPACE_ID)
    # new_msg.thread = fake_thread
    # db.session.add_all([new_msg, fake_thread])
    # db.session.commit()
    # return new_msg

    thread = add_fake_thread(db.session, namespace_id)
    message = add_fake_message(db.session, namespace_id, thread,
                               subject="Golden Gate Park next Sat",
                               from_addr=[('alice', '[email protected]')],
                               to_addr=[('bob', '[email protected]')])
    message.snippet = 'Banh mi paleo pickled, sriracha'
    message.body = """
Banh mi paleo pickled, sriracha biodiesel chambray seitan
mumblecore mustache. Raw denim gastropub 8-bit, butcher
PBR sartorial photo booth Pinterest blog Portland roof party
cliche bitters aesthetic. Ugh.
"""

    message = add_fake_message(db.session, namespace_id, thread,
                               subject="Re:Golden Gate Park next Sat",
                               from_addr=[('bob', '[email protected]')],
                               to_addr=[('alice', '[email protected]')],
                               cc_addr=[('Cheryl', '[email protected]')])
    message.snippet = 'Bushwick meggings ethical keffiyeh'
    message.body = """
Bushwick meggings ethical keffiyeh. Chambray lumbersexual wayfarers,
irony Banksy cred bicycle rights scenester artisan tote bag YOLO gastropub.
"""

    draft = add_fake_message(db.session, namespace_id, thread,
                               subject="Re:Golden Gate Park next Sat",
                               from_addr=[('alice', '[email protected]')],
                               to_addr=[('bob', '[email protected]')],
                               cc_addr=[('Cheryl', '[email protected]')])
    draft.snippet = 'Hey there friend writing a draft'
    draft.body = """
DIY tousled Tumblr, VHS meditation 3 wolf moon listicle fingerstache viral
bicycle rights. Thundercats kale chips church-key American Apparel.
"""
    draft.is_draft = True
    draft.reply_to_message = message

    db.session.commit()
    return message
开发者ID:PriviPK,项目名称:privipk-sync-engine,代码行数:48,代码来源:test_messages.py

示例15: test_category_delete

def test_category_delete(db, gmail_account):
    """ Ensure that all associated MessageCategories are deleted
        when a Category is deleted """

    api_client = new_api_client(db, gmail_account.namespace)
    po_data = api_client.post_data('/labels/',
                                   {"display_name": "Test_Label"})
    assert po_data.status_code == 200

    category_public_id = json.loads(po_data.data)['id']
    category = db.session.query(Category).filter(
        Category.public_id == category_public_id).one()
    category_id = category.id

    for i in xrange(10):
        generic_thread = add_fake_thread(db.session,
                                         gmail_account.namespace.id)
        gen_message = add_fake_message(db.session,
                                       gmail_account.namespace.id,
                                       generic_thread)
        data = {"label_ids": [category_public_id]}
        resp = api_client.put_data('/messages/{}'.
                                   format(gen_message.public_id), data)
        assert resp.status_code == 200

    associated_mcs = db.session.query(MessageCategory). \
            filter(MessageCategory.category_id == category_id).all()
    assert len(associated_mcs) == 10

    db.session.delete(category)
    db.session.commit()

    assert db.session.query(MessageCategory). \
            filter(MessageCategory.category_id == category_id).all() == []
开发者ID:DrMoriarty,项目名称:sync-engine,代码行数:34,代码来源:test_relationships.py


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