def test_get_lastuid(self):
        soledad = mock()
        mbox = mock()
        mbox.content = {'lastuid': 0}
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn([mbox])
        querier = SoledadQuerier(soledad)

        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 0)
        mbox.content = {'lastuid': 1}
        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 1)
    def test_create_mail_increments_uid(self):
        soledad = mock()
        mbox = mock()
        mail = mock()
        when(mail).get_for_save(next_uid=any(), mailbox='INBOX').thenReturn([])
        mbox.content = {'lastuid': 0}
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn([mbox])
        querier = SoledadQuerier(soledad)
        when(querier).mail(any()).thenReturn([])

        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 0)
        querier.create_mail(mail, 'INBOX')
        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 1)
예제 #3
0
    def test_get_lastuid(self):
        soledad = mock()
        mbox = mock()
        indexer = mock()
        mbox.content = {'uuid': str(uuid4())}
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn(defer.succeed([mbox]))
        querier = SoledadQuerier(soledad)

        when(pixelated.adapter.soledad.soledad_facade_mixin).MailboxIndexer(soledad).thenReturn(indexer)
        when(indexer).create_table(any()).thenReturn(defer.succeed(None))
        when(indexer).get_last_uid(any()).thenReturn(defer.succeed(42))

        last_uid = (yield querier.get_lastuid('INBOX'))

        self.assertEquals(42, last_uid)