Python twisted.internet.defer.gatherResults() Examples

The following are 30 code examples of twisted.internet.defer.gatherResults(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.internet.defer , or try the search function .
Example #1
Source File: test_config.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def test_bootstrap_invalid_ca_cert(self):
        home = os.path.join(self.home, 'fp')
        os.mkdir(home)
        self.addr.fingerprint = "fabadafabada"
        provider = Provider(self.addr.domain, autoconf=True, basedir=home,
                            cert_path=self.cacert)

        d = provider.callWhenMainConfigReady(lambda: "CA cert fp matched")
        yield self.assertFailure(d, NetworkError)
        self.assertFalse(os.path.isfile(provider._get_ca_cert_path()))
        provider._http.close()
        try:
            yield defer.gatherResults([
                d, provider.ongoing_bootstrap])
        except:
            pass
        Provider.providers[self.addr.domain] = None 
Example #2
Source File: server.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def _cbSelectWork(self, mbox, cmdName, tag):
        """
        Callback for selectWork

        * patched to avoid conformance errors due to incomplete UIDVALIDITY
        line.
        * patched to accept deferreds for messagecount and recent count
        """
        if mbox is None:
            self.sendNegativeResponse(tag, 'No such mailbox')
            return
        if '\\noselect' in [s.lower() for s in mbox.getFlags()]:
            self.sendNegativeResponse(tag, 'Mailbox cannot be selected')
            return

        d1 = defer.maybeDeferred(mbox.getMessageCount)
        d2 = defer.maybeDeferred(mbox.getRecentCount)
        d3 = defer.maybeDeferred(mbox.getUIDNext)
        return defer.gatherResults([d1, d2, d3]).addCallback(
            self.__cbSelectWork, mbox, cmdName, tag) 
Example #3
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testFailedStatus(self):
        """
        Test failed status command with a non-existent mailbox
        """
        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def status():
            return self.client.status(
                'root/nonexistent', 'MESSAGES', 'UIDNEXT', 'UNSEEN')

        def statused(result):
            self.statused = result

        def failed(failure):
            self.failure = failure

        self.statused = self.failure = None
        d1 = self.connected.addCallback(strip(login))
        d1.addCallbacks(strip(status), self._ebGeneral)
        d1.addCallbacks(statused, failed)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        return defer.gatherResults([d1, d2]).addCallback(
            self._cbTestFailedStatus) 
Example #4
Source File: __init__.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def delete_all_keys(self, km):
        def delete_keys(keys):
            deferreds = []
            for key in keys:
                d = km._openpgp.delete_key(key)
                deferreds.append(d)
            return gatherResults(deferreds)

        def check_deleted(_, private):
            d = km.get_all_keys(private=private)
            d.addCallback(lambda keys: self.assertEqual(keys, []))
            return d

        deferreds = []
        for private in [True, False]:
            d = km.get_all_keys(private=private)
            d.addCallback(delete_keys)
            d.addCallback(check_deleted, private)
            deferreds.append(d)
        return gatherResults(deferreds) 
Example #5
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testCapabilityWithAuth(self):
        caps = {}
        self.server.challengers[
            'CRAM-MD5'] = cred.credentials.CramMD5Credentials

        def getCaps():
            def gotCaps(c):
                caps.update(c)
                self.server.transport.loseConnection()
            return self.client.getCapabilities().addCallback(gotCaps)
        d1 = self.connected.addCallback(
            strip(getCaps)).addErrback(self._ebGeneral)

        d = defer.gatherResults([self.loopback(), d1])

        expCap = {'IMAP4rev1': None, 'NAMESPACE': None,
                  'IDLE': None, 'LITERAL+': None,
                  'AUTH': ['CRAM-MD5']}

        d.addCallback(lambda _: self.assertEqual(expCap, caps))
        return d

    #
    # authentication
    # 
Example #6
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testNamespace(self):
        """
        Test retrieving namespace
        """
        self.namespaceArgs = None

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def namespace():
            def gotNamespace(args):
                self.namespaceArgs = args
                self._cbStopClient(None)
            return self.client.namespace().addCallback(gotNamespace)

        d1 = self.connected.addCallback(strip(login))
        d1.addCallback(strip(namespace))
        d1.addErrback(self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])
        d.addCallback(lambda _: self.assertEqual(self.namespaceArgs,
                                                 [[['', '/']], [], []]))
        return d 
Example #7
Source File: test_webclient.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_downloadTimeout(self):
        """
        If the timeout indicated by the C{timeout} parameter to
        L{client.HTTPDownloader.__init__} elapses without the complete response
        being received, the L{defer.Deferred} returned by
        L{client.downloadPage} fires with a L{Failure} wrapping a
        L{defer.TimeoutError}.
        """
        self.cleanupServerConnections = 2
        # Verify the behavior if no bytes are ever written.
        first = client.downloadPage(
            self.getURL("wait"),
            self.mktemp(), timeout=0.01)

        # Verify the behavior if some bytes are written but then the request
        # never completes.
        second = client.downloadPage(
            self.getURL("write-then-wait"),
            self.mktemp(), timeout=0.01)

        return defer.gatherResults([
            self.assertFailure(first, defer.TimeoutError),
            self.assertFailure(second, defer.TimeoutError)]) 
Example #8
Source File: openpgp.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def _repair_docs(self, doclist, cmp_func, log_func):
        self.log.error("BUG -------------------------------------------------")
        self.log.error("There is more than one doc of type %s:"
                       % (doclist[0].content[KEY_TYPE_KEY],))

        doclist.sort(cmp=cmp_func, reverse=True)
        log_func(doclist[0])
        deferreds = []
        for doc in doclist[1:]:
            log_func(doc)
            d = self._soledad.delete_doc(doc)
            deferreds.append(d)

        self.log.error('Error repairing')
        self.log.error("BUG (please report above info) ----------------------")
        d = defer.gatherResults(deferreds, consumeErrors=True)
        d.addCallback(lambda _: doclist[0])
        return d 
Example #9
Source File: test_vhost.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_renderWithHost(self):
        """
        L{NameVirtualHost.render} returns the result of rendering the resource
        which is the value in the instance's C{host} dictionary corresponding
        to the key indicated by the value of the I{Host} header in the request.
        """
        virtualHostResource = NameVirtualHost()
        virtualHostResource.addHost(b'example.org', Data(b"winner", ""))

        request = DummyRequest([b''])
        request.requestHeaders.addRawHeader(b'host', b'example.org')
        d = _render(virtualHostResource, request)
        def cbRendered(ignored, request):
            self.assertEqual(b''.join(request.written), b"winner")
        d.addCallback(cbRendered, request)

        # The port portion of the Host header should not be considered.
        requestWithPort = DummyRequest([b''])
        requestWithPort.requestHeaders.addRawHeader(b'host', b'example.org:8000')
        dWithPort = _render(virtualHostResource, requestWithPort)
        def cbRendered(ignored, requestWithPort):
            self.assertEqual(b''.join(requestWithPort.written), b"winner")
        dWithPort.addCallback(cbRendered, requestWithPort)

        return gatherResults([d, dWithPort]) 
Example #10
Source File: test_template.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_roundTrip(self):
        """
        Given a series of parsable XML strings, verify that
        L{twisted.web._flatten.flatten} will flatten the L{Element} back to the
        input when sent on a round trip.
        """
        fragments = [
            b"<p>Hello, world.</p>",
            b"<p><!-- hello, world --></p>",
            b"<p><![CDATA[Hello, world.]]></p>",
            b'<test1 xmlns:test2="urn:test2">'
            b'<test2:test3></test2:test3></test1>',
            b'<test1 xmlns="urn:test2"><test3></test3></test1>',
            b'<p>\xe2\x98\x83</p>',
        ]
        deferreds = [
            self.assertFlattensTo(Element(loader=XMLString(xml)), xml)
            for xml in fragments]
        return gatherResults(deferreds) 
Example #11
Source File: github.py    From llvm-zorg with Apache License 2.0 6 votes vote down vote up
def _getGitHubRepoProperties(self, build):
        """
        Return a dictionary with GitHub related properties from `build`.
        """
        repoOwner, repoName, sha = yield defer.gatherResults([
            build.render(self._repoOwner),
            build.render(self._repoName),
            build.render(self._sha),
        ])

        if not repoOwner or not repoName:
            defer.returnValue({})

        if not sha:
            log.msg('GitHubStatus: No revision found.')
            defer.returnValue({})

        result = {
            'repoOwner': repoOwner,
            'repoName': repoName,
            'sha': sha,
            'targetURL': self._status.getURLForThing(build),
            'buildNumber': str(build.getNumber()),
        }
        defer.returnValue(result) 
Example #12
Source File: migrator.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def _buildKeyDict(self, keys, actives):
        keydict = {
            fp2id(key.content[doc.KEY_FINGERPRINT_KEY]): KeyDocs(key, [])
            for key in keys}

        deferreds = []
        for active in actives:
            if KEY_ID_KEY in active.content:
                key_id = active.content[KEY_ID_KEY]
                if key_id not in keydict:
                    d = self._soledad.delete_doc(active)
                    deferreds.append(d)
                    continue
                keydict[key_id].active.append(active)

        d = gatherResults(deferreds)
        d.addCallback(lambda _: keydict)
        return d 
Example #13
Source File: test_flatten.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_serializeUnicode(self):
        """
        Test that unicode is encoded correctly in the appropriate places, and
        raises an error when it occurs in inappropriate place.
        """
        snowman = u'\N{SNOWMAN}'
        return gatherResults([
            self.assertFlattensTo(snowman, b'\xe2\x98\x83'),
            self.assertFlattensTo(tags.p(snowman), b'<p>\xe2\x98\x83</p>'),
            self.assertFlattensTo(Comment(snowman), b'<!--\xe2\x98\x83-->'),
            self.assertFlattensTo(CDATA(snowman), b'<![CDATA[\xe2\x98\x83]]>'),
            self.assertFlatteningRaises(
                Tag(snowman), UnicodeEncodeError),
            self.assertFlatteningRaises(
                Tag('p', attributes={snowman: ''}), UnicodeEncodeError),
        ]) 
Example #14
Source File: test_wsgi.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def test_serverName(self):
        """
        The C{'SERVER_NAME'} key of the C{environ} C{dict} passed to the
        application contains the best determination of the server hostname
        possible, using either the value of the I{Host} header in the request
        or the address the server is listening on if that header is not
        present (RFC 3875, section 4.1.14).
        """
        missing = self.render('GET', '1.1', [], [''])
        # 10.0.0.1 value comes from a bit far away -
        # twisted.test.test_web.DummyChannel.transport.getHost().host
        missing.addCallback(self.environKeyEqual('SERVER_NAME', '10.0.0.1'))

        present = self.render(
            'GET', '1.1', [], [''], None, [('host', 'example.org')])
        present.addCallback(self.environKeyEqual('SERVER_NAME', 'example.org'))

        return gatherResults([missing, present]) 
Example #15
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testCapability(self):
        caps = {}

        def getCaps():
            def gotCaps(c):
                caps.update(c)
                self.server.transport.loseConnection()
            return self.client.getCapabilities().addCallback(gotCaps)

        d1 = self.connected
        d1.addCallback(
            strip(getCaps)).addErrback(self._ebGeneral)

        d = defer.gatherResults([self.loopback(), d1])
        expected = {'IMAP4rev1': None, 'NAMESPACE': None, 'LITERAL+': None,
                    'IDLE': None}
        d.addCallback(lambda _: self.assertEqual(expected, caps))
        return d 
Example #16
Source File: config.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def _get_config_for_all_services(self, session):
        if session is None:
            provider_cert = self._get_ca_cert_path()
            session = Session(Anonymous(), self.api_uri, provider_cert)

        services_dict = self._load_provider_configs()
        configs_path = self._get_configs_path()
        with open(configs_path) as jsonf:
            services_dict = Record(**json.load(jsonf)).services
        pending = []
        base = self._disco.get_base_uri()
        for service in self._provider_config.services:
            if service in self.SERVICES_MAP.keys():
                for subservice in self.SERVICES_MAP[service]:
                    uri = base + str(services_dict[subservice])
                    path = self._get_service_config_path(subservice)
                    d = session.fetch_provider_configs(
                        uri, path, method='GET')
                    pending.append(d)
        return defer.gatherResults(pending) 
Example #17
Source File: client.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def closeCachedConnections(self):
        """
        Close all persistent connections and remove them from the pool.

        @return: L{defer.Deferred} that fires when all connections have been
            closed.
        """
        results = []
        for protocols in itervalues(self._connections):
            for p in protocols:
                results.append(p.abort())
        self._connections = {}
        for dc in itervalues(self._timeouts):
            dc.cancel()
        self._timeouts = {}
        return defer.gatherResults(results).addCallback(lambda ign: None) 
Example #18
Source File: test_distrib.py    From Safejumper-for-Desktop with GNU General Public License v2.0 6 votes vote down vote up
def tearDown(self):
        """
        Clean up all the event sources left behind by either directly by
        test methods or indirectly via some distrib API.
        """
        dl = [defer.Deferred(), defer.Deferred()]
        if self.f1 is not None and self.f1.proto is not None:
            self.f1.proto.notifyOnDisconnect(lambda: dl[0].callback(None))
        else:
            dl[0].callback(None)
        if self.sub is not None and self.sub.publisher is not None:
            self.sub.publisher.broker.notifyOnDisconnect(
                lambda: dl[1].callback(None))
            self.sub.publisher.broker.transport.loseConnection()
        else:
            dl[1].callback(None)
        if self.port1 is not None:
            dl.append(self.port1.stopListening())
        if self.port2 is not None:
            dl.append(self.port2.stopListening())
        return defer.gatherResults(dl) 
Example #19
Source File: __init__.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def delete_all_keys(self, km):
        def delete_keys(keys):
            deferreds = []
            for key in keys:
                d = km._openpgp.delete_key(key)
                deferreds.append(d)
            return gatherResults(deferreds)

        def check_deleted(_, private):
            d = km.get_all_keys(private=private)
            d.addCallback(lambda keys: self.assertEqual(keys, []))
            return d

        deferreds = []
        for private in [True, False]:
            d = km.get_all_keys(private=private)
            d.addCallback(delete_keys)
            d.addCallback(check_deleted, private)
            deferreds.append(d)
        return gatherResults(deferreds) 
Example #20
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testDelete(self):
        """
        Test whether we can delete mailboxes
        """
        def add_mailbox():
            return self.server.theAccount.addMailbox('test-delete/me')

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def delete():
            return self.client.delete('test-delete/me')

        acc = self.server.theAccount.account

        d1 = self.connected.addCallback(add_mailbox)
        d1.addCallback(strip(login))
        d1.addCallbacks(strip(delete), self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])
        d.addCallback(lambda _: acc.list_all_mailbox_names())
        d.addCallback(lambda mboxes: self.assertEqual(
            set(mboxes), set(DEFAULT_MBOXES)))
        return d 
Example #21
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testIllegalInboxDelete(self):
        """
        Test what happens if we try to delete the user Inbox.
        We expect that operation to fail.
        """
        self.stashed = None

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def delete():
            return self.client.delete('inbox')

        def stash(result):
            self.stashed = result

        d1 = self.connected.addCallback(strip(login))
        d1.addCallbacks(strip(delete), self._ebGeneral)
        d1.addBoth(stash)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])
        d.addCallback(lambda _: self.failUnless(isinstance(self.stashed,
                                                           failure.Failure)))
        return d 
Example #22
Source File: test_soledad_adaptor.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def test_get_all_mboxes(self):
        adaptor = self.get_adaptor()
        mboxes = ("Sent", "Trash", "Personal", "ListFoo")

        def get_or_create_mboxes(ignored):
            d = []
            for mbox in mboxes:
                d.append(adaptor.get_or_create_mbox(
                    adaptor.store, mbox))
            return defer.gatherResults(d)

        def get_all_mboxes(ignored):
            return adaptor.get_all_mboxes(adaptor.store)

        def assert_mboxes_match_expected(wrappers):
            names = [m.mbox for m in wrappers]
            self.assertEqual(set(names), set(mboxes))

        d = adaptor.initialize_store(adaptor.store)
        d.addCallback(get_or_create_mboxes)
        d.addCallback(get_all_mboxes)
        d.addCallback(assert_mboxes_match_expected)
        return d 
Example #23
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testRename(self):
        """
        Test whether we can rename a mailbox
        """
        def create_mbox():
            return self.server.theAccount.addMailbox('oldmbox')

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def rename():
            return self.client.rename('oldmbox', 'newname')

        d1 = self.connected.addCallback(strip(create_mbox))
        d1.addCallback(strip(login))
        d1.addCallbacks(strip(rename), self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])
        d.addCallback(lambda _:
                      self.server.theAccount.account.list_all_mailbox_names())
        d.addCallback(lambda mboxes:
                      self.assertItemsEqual(
                          mboxes, DEFAULT_MBOXES + ['newname']))
        return d 
Example #24
Source File: test_soledad_adaptor.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def test_create_many(self):

        store = self._soledad
        w1 = CounterWrapper()
        w2 = CounterWrapper(counter=1)
        w3 = CounterWrapper(counter=2)
        w4 = CounterWrapper(counter=3)
        w5 = CounterWrapper(counter=4)

        d1 = [w1.create(store),
              w2.create(store),
              w3.create(store),
              w4.create(store),
              w5.create(store)]

        d = defer.gatherResults(d1)
        d.addCallback(lambda _: store.get_all_docs())
        d.addCallback(partial(self.assert_num_docs, 5))
        return d 
Example #25
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 6 votes vote down vote up
def testHierarchicalRename(self):
        """
        Try to rename hierarchical mailboxes
        """
        acc = self.server.theAccount

        def add_mailboxes():
            return defer.gatherResults([
                acc.addMailbox('oldmbox/m1'),
                acc.addMailbox('oldmbox/m2')])

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def rename():
            return self.client.rename('oldmbox', 'newname')

        d1 = self.connected.addCallback(strip(add_mailboxes))
        d1.addCallback(strip(login))
        d1.addCallbacks(strip(rename), self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])
        d.addCallback(lambda _: acc.account.list_all_mailbox_names())
        return d.addCallback(self._cbTestHierarchicalRename) 
Example #26
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 5 votes vote down vote up
def testCheck(self):
        """
        Test check command
        """
        def add_mailbox():
            return self.server.theAccount.addMailbox('root/subthing')

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def select():
            return self.client.select('root/subthing')

        def check():
            return self.client.check()

        d = self.connected.addCallbacks(
            strip(add_mailbox), self._ebGeneral)
        d.addCallbacks(lambda _: login(), self._ebGeneral)
        d.addCallbacks(strip(select), self._ebGeneral)
        d.addCallbacks(strip(check), self._ebGeneral)
        d.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        return defer.gatherResults([d, d2])

        # Okay, that was much fun indeed 
Example #27
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 5 votes vote down vote up
def _listSetup(self, f, f2=None):

        acc = self.server.theAccount

        def dc1():
            return acc.addMailbox('root_subthing', creation_ts=42)

        def dc2():
            return acc.addMailbox('root_another_thing', creation_ts=42)

        def dc3():
            return acc.addMailbox('non_root_subthing', creation_ts=42)

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def listed(answers):
            self.listed = answers

        self.listed = None
        d1 = self.connected.addCallback(strip(login))
        d1.addCallback(strip(dc1))
        d1.addCallback(strip(dc2))
        d1.addCallback(strip(dc3))

        if f2 is not None:
            d1.addCallback(f2)

        d1.addCallbacks(strip(f), self._ebGeneral)
        d1.addCallbacks(listed, self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        return defer.gatherResults([d1, d2]).addCallback(lambda _: self.listed) 
Example #28
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 5 votes vote down vote up
def testPartialAppend(self):
        """
        Test partially appending a message to the mailbox
        """
        # TODO this test sometimes will fail because of the notify_just_mdoc
        infile = os.path.join(HERE, '..', 'rfc822.message')

        acc = self.server.theAccount

        def add_mailbox():
            return acc.addMailbox('PARTIAL/SUBTHING')

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def append():
            message = file(infile)
            return self.client.sendCommand(
                imap4.Command(
                    'APPEND',
                    'PARTIAL/SUBTHING (\\SEEN) "Right now" '
                    '{%d}' % os.path.getsize(infile),
                    (), self.client._IMAP4Client__cbContinueAppend, message
                )
            )
        d1 = self.connected.addCallback(strip(add_mailbox))
        d1.addCallback(strip(login))
        d1.addCallbacks(strip(append), self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])

        d.addCallback(lambda _: acc.getMailbox("PARTIAL/SUBTHING"))
        d.addCallback(lambda mb: mb.fetch(imap4.MessageSet(start=1), True))
        return d.addCallback(
            self._cbTestPartialAppend, infile) 
Example #29
Source File: test_imap.py    From bitmask-dev with GNU General Public License v3.0 5 votes vote down vote up
def testStatus(self):
        """
        Test Status command
        """
        acc = self.server.theAccount

        def add_mailbox():
            return acc.addMailbox('root_subthings')

        # XXX FIXME ---- should populate this a little bit,
        # with unseen etc...

        def login():
            return self.client.login(TEST_USER, TEST_PASSWD)

        def status():
            return self.client.status(
                'root_subthings', 'MESSAGES', 'UIDNEXT', 'UNSEEN')

        def statused(result):
            self.statused = result

        self.statused = None

        d1 = self.connected.addCallback(strip(add_mailbox))
        d1.addCallback(strip(login))
        d1.addCallbacks(strip(status), self._ebGeneral)
        d1.addCallbacks(statused, self._ebGeneral)
        d1.addCallbacks(self._cbStopClient, self._ebGeneral)
        d2 = self.loopback()
        d = defer.gatherResults([d1, d2])
        d.addCallback(lambda _: self.assertEqual(
            self.statused,
            {'MESSAGES': 0, 'UIDNEXT': '1', 'UNSEEN': 0}
        ))
        return d 
Example #30
Source File: seahorse.py    From IRCBots with MIT License 5 votes vote down vote up
def update_room_list(self):
        print(defer.gatherResults(self.names(config["channel"])))