Ejemplo n.º 1
0
    def testWaitUntil(self):
        # Wait for a deferred that doesn't fire within the timeout
        d = defer.Deferred()
        self.assertRaises(
            testreactor.TimeoutError,
            lambda: reactor.waitUntil(d, 1440)  # wait "all day" and time out
        )

        # Now fire it in 5 seconds and get what we want
        reactor.callLater(5, d.callback, "Ping!")
        self.assertEqual(reactor.waitUntil(d, 5), "Ping!")

        # Fired before loop starts -> immediate return
        d = defer.Deferred()
        d.callback("Pong")
        self.assertEqual(reactor.waitUntil(d, 0), "Pong")

        # Errors from the deferred should be communicated back to caller
        class my_error(Exception):
            pass

        d = defer.Deferred()

        def throw_me():
            try:
                raise my_error
            except:
                d.errback()

        reactor.callLater(3, throw_me)
        self.assertRaises(my_error, lambda: reactor.waitUntil(d, 5))
Ejemplo n.º 2
0
 def testCleanupAfterEarlyExit(self):
     d = defer.Deferred()
     reactor.callLater(1, reactor.crash)  # exit early
     self.assertRaises(testreactor.EarlyExit,
                       lambda: reactor.waitUntil(d, 5))
     reactor.callLater(10, d.callback, "Done")
     self.assertEqual(reactor.waitUntil(d, 10), "Done")
Ejemplo n.º 3
0
    def testWaitUntil(self):
        # Wait for a deferred that doesn't fire within the timeout
        d = defer.Deferred()
        self.assertRaises(
            testreactor.TimeoutError,
            lambda: reactor.waitUntil(d, 1440)  # wait "all day" and time out
        )

        # Now fire it in 5 seconds and get what we want
        reactor.callLater(5, d.callback, "Ping!")
        self.assertEqual( reactor.waitUntil(d, 5), "Ping!")

        # Fired before loop starts -> immediate return
        d = defer.Deferred()
        d.callback("Pong")
        self.assertEqual( reactor.waitUntil(d, 0), "Pong")

        # Errors from the deferred should be communicated back to caller
        class my_error(Exception): pass

        d = defer.Deferred()
        def throw_me():
            try:
                raise my_error
            except:
                d.errback()

        reactor.callLater(3,throw_me)
        self.assertRaises(my_error, lambda: reactor.waitUntil(d,5))
Ejemplo n.º 4
0
 def testCleanupAfterEarlyExit(self):
     d = defer.Deferred()
     reactor.callLater(1,reactor.crash)  # exit early
     self.assertRaises(
         testreactor.EarlyExit,
         lambda:reactor.waitUntil(d, 5)
     )
     reactor.callLater(10, d.callback, "Done")
     self.assertEqual(reactor.waitUntil(d, 10), "Done")
Ejemplo n.º 5
0
    def setUp(self):

        super(CosmoTest, self).setUp()

        reactor.useRealTime()

        self.useSSL = False
        #self.useSSL = True
        self.username = "******"
        self.password = "******"
        #self.host = "localhost"
        #self.username = "******"
        #self.password = "******"
        #self.username = "******"
        #self.password = "******"
        self.host = "cosmo-demo.osafoundation.org"
        self.port = 8080
        #self.port = 443
        self.path = "/home/%s" % (self.username, )
        self.url = "http://" + self.host + ":" + str(self.port) + self.path

        self.server = ServerHandle(self.host, self.port, self.username,
                                   self.password, self.useSSL)

        global ACCOUNT_CREATED
        if not ACCOUNT_CREATED:

            ACCOUNT_CREATED = True

            testHandle = ServerHandle(self.host, self.port, "root", "cosmo",
                                      False)
            xmlCreateAccount = """<?xml version="1.0" encoding="utf-8" ?> 
        <user xmlns="http://osafoundation.org/cosmo">
          <username>%s</username>
          <password>%s</password>
          <firstName>Tommy</firstName>
          <lastName>Tester</lastName>
          <email>%[email protected]</email>
        </user>
        """ % (self.username, self.password, self.username)

            body = xmlCreateAccount.encode("utf-8")

            headers = {'content-type': 'text/xml', 'connection': 'close'}

            print "Creating user account %s" % self.username

            req = Request('PUT', '/api/user/%s' % self.username, headers, body)
            req.timeout = 45.0
            response = reactor.waitUntil(testHandle.factory.addRequest(req),
                                         45.0)

            if response.status == 201:
                print "Created user account %s" % self.username
            elif response.status == 204:
                print "WARNING: Account %s already exists." % self.username
            elif response.status == 401:
                print "ERROR: Authorization error. Check username and password."
            else:
                print "ERROR %s. Unknown error" % response.status
Ejemplo n.º 6
0
    def setUp(self):

        super(CosmoTest, self).setUp()
        
        reactor.useRealTime()
        
        self.useSSL = False
        #self.useSSL = True
        self.username = "******"
        self.password = "******"
        #self.host = "localhost"
        #self.username = "******"
        #self.password = "******"
        #self.username = "******"
        #self.password = "******"
        self.host = "cosmo-demo.osafoundation.org"
        self.port = 8080
        #self.port = 443
        self.path = "/home/%s" % (self.username,)
        self.url = "http://" + self.host + ":" + str(self.port) + self.path
        
        self.server = ServerHandle(self.host, self.port, self.username,
                                   self.password, self.useSSL)
                                   
        global ACCOUNT_CREATED
        if not ACCOUNT_CREATED:
                
            ACCOUNT_CREATED = True

            testHandle = ServerHandle(self.host, self.port, "root", "cosmo", False)
            xmlCreateAccount = """<?xml version="1.0" encoding="utf-8" ?> 
        <user xmlns="http://osafoundation.org/cosmo">
          <username>%s</username>
          <password>%s</password>
          <firstName>Tommy</firstName>
          <lastName>Tester</lastName>
          <email>%[email protected]</email>
        </user>
        """ % (self.username, self.password, self.username)

            body = xmlCreateAccount.encode("utf-8")
            
            headers = { 'content-type': 'text/xml', 'connection': 'close' }
            
            print "Creating user account %s" % self.username

            req = Request('PUT', '/api/user/%s' % self.username, headers, body)
            req.timeout = 45.0
            response = reactor.waitUntil(testHandle.factory.addRequest(req), 45.0)

            if response.status == 201:
                print "Created user account %s" % self.username
            elif response.status == 204:
                print "WARNING: Account %s already exists." % self.username
            elif response.status == 401:
                print "ERROR: Authorization error. Check username and password."
            else:
                print "ERROR %s. Unknown error" % response.status
Ejemplo n.º 7
0
 def sendRequest(self, method, path, extraHeaders, body):
     req = Request(method, path, extraHeaders, body)
     
     if VERBOSE: print '... Sending %s %s' % (method, path)
     
     result = reactor.waitUntil(self.server.factory.addRequest(req), 60.0)
     
     if VERBOSE: print '... Received %s %s' % (result.status, result.message)
     
     return result
Ejemplo n.º 8
0
    def sendRequest(self, method, path, extraHeaders, body):
        req = Request(method, path, extraHeaders, body)

        if VERBOSE: print '... Sending %s %s' % (method, path)

        result = reactor.waitUntil(self.server.factory.addRequest(req), 60.0)

        if VERBOSE:
            print '... Received %s %s' % (result.status, result.message)

        return result
Ejemplo n.º 9
0
    def tearDown(self):
        reactor.waitUntil(defer.maybeDeferred(self.server.factory.stopFactory),
                          10)

        super(CosmoTest, self).tearDown()
Ejemplo n.º 10
0
 def tearDown(self):
     reactor.waitUntil(defer.maybeDeferred(self.server.factory.stopFactory), 10)
     
     super(CosmoTest, self).tearDown()