Example #1
0
 def testNoUrl(self):
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache, "foo bar",
                                          lambda x: self.fail(x),
                                          self.encoding, 255)
     d = next(iter(message_handler), None)
     self.assertIs(d, None, "Should not give any deferreds")
Example #2
0
 def testMissingTypeHeader(self):
     msg = "http://foo/bar"
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache,
                                          lambda x: self.fail(x), 255)
     d = self.step(message_handler, msg, "foo", headers={})
     d.addCallback(self.ensureException)
     return d
Example #3
0
 def testForbidden(self):
     msg = "http://foo/bar"
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache,
                                          lambda x: self.fail(x), 255)
     d = self.step(message_handler, msg, "foo", code=400)
     d.addCallback(self.ensureException)
     return d
Example #4
0
 def testUnsupportedScheme(self):
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache,
                                          "gopher://foo/bar#baz",
                                          lambda x: self.fail(x),
                                          self.encoding, 255)
     d = next(iter(message_handler), None)
     self.assertIs(d, None, "Should not give any deferreds")
Example #5
0
 def testBrokenTypeHeader(self):
     msg = "http://foo/bar"
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache, msg,
                                          lambda x: self.fail(x),
                                          self.encoding, 255)
     iterator = iter(message_handler)
     d = self.step(iterator, msg, "foo", headers={"content-type": tuple()})
     d.addCallback(self.ensureException)
Example #6
0
 def testUnsupportedType(self):
     msg = "http://foo/bar"
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache,
                                          lambda x: self.fail(x), 255)
     d = self.step(message_handler,
                   msg,
                   "foo",
                   headers={"content-type": ("image/png", )})
     d.addCallback(self.ensureException)
     return d
Example #7
0
 def runSequence(self, urls):
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache, " ".join(urls),
                                          self.callback, self.encoding, 255)
     iterator = iter(message_handler)
     d = defer.succeed(None)
     for url in urls:
         _, _, title = url.partition("#")
         d.addCallback(lambda _: self.step(iterator, url, title))
     d.addCallback(
         lambda _: self.assertRaises(StopIteration, next, iterator))
Example #8
0
    def runSequence(self, urls):
        message = " ".join(urls)
        expected_urls = list(reversed(urls))
        url_map = {url: self.urlitem_from_url(url) for url in urls}

        def callback(title):
            url = expected_urls.pop()
            expected_title = url_map[url]["title"]
            self.assertEqual(title, f"title: {expected_title}")
            self.clock.advance(2)
            return defer.succeed(None)

        message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                             self.miss_cache, callback, 255)
        patch_handler(message_handler, MockTreq(url_map))
        d = defer.ensureDeferred(message_handler.find_links(message))
        d.addCallback(lambda _: self.clock.advance(2))
Example #9
0
 def testUnsupportedScheme(self):
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache,
                                          lambda x: self.fail(x), 255)
     return self.step(message_handler, "gopher://foo/bar#bar")
Example #10
0
 def testNoUrl(self):
     message_handler = app.MessageHandler(self.clock, self.hit_cache,
                                          self.miss_cache,
                                          lambda x: self.fail(x), 255)
     return self.step(message_handler, "foo bar")