def test_threading_limit(db, folder_sync_engine, monkeypatch):
 from inbox.models import Message, Thread
 MAX_THREAD_LENGTH = 10
 monkeypatch.setattr('inbox.mailsync.backends.imap.generic.MAX_THREAD_LENGTH', MAX_THREAD_LENGTH)
 namespace_id = folder_sync_engine.namespace_id
 msg = MockRawMessage([])
 for i in range((3 * MAX_THREAD_LENGTH)):
  m = Message()
  m.namespace_id = namespace_id
  m.received_date = datetime.datetime.utcnow()
  m.references = []
  m.size = 0
  m.body = ''
  m.from_addr = [('Karim Hamidou', 'karim@nilas.com')]
  m.to_addr = [('Eben Freeman', 'eben@nilas.com')]
  m.snippet = ''
  m.subject = 'unique subject'
  db.session.add(m)
  folder_sync_engine.add_message_to_thread(db.session, m, msg)
  db.session.commit()
 new_threads = db.session.query(Thread).filter((Thread.subject == 'unique subject')).all()
 assert (len(new_threads) == 3)
 assert all(((len(thread.messages) == MAX_THREAD_LENGTH) for thread in new_threads))

def test_threading_limit ( db , folder_sync_engine , monkeypatch ) : from inbox . models import Message , Thread MAX_THREAD_LENGTH = 10 monkeypatch . setattr ( 'inbox.mailsync.backends.imap.generic.MAX_THREAD_LENGTH' , MAX_THREAD_LENGTH ) namespace_id = folder_sync_engine . namespace_id msg = MockRawMessage ( [ ] ) for i in range ( ( 3 * MAX_THREAD_LENGTH ) ) : m = Message ( ) m . namespace_id = namespace_id m . received_date = datetime . datetime . utcnow ( ) m . references = [ ] m . size = 0 m . body = '' m . from_addr = [ ( 'Karim Hamidou' , 'karim@nilas.com' ) ] m . to_addr = [ ( 'Eben Freeman' , 'eben@nilas.com' ) ] m . snippet = '' m . subject = 'unique subject' db . session . add ( m ) folder_sync_engine . add_message_to_thread ( db . session , m , msg ) db . session . commit ( ) new_threads = db . session . query ( Thread ) . filter ( ( Thread . subject == 'unique subject' ) ) . all ( ) assert ( len ( new_threads ) == 3 ) assert all ( ( ( len ( thread . messages ) == MAX_THREAD_LENGTH ) for thread in new_threads ) )
test that custom threading doesnt produce arbitrarily long threads .