Exemple #1
0
class SettingsReloadingTestCase(TestCase):
    def setUp(self):
        self.transport = AbortableStringTransport()
        self.factory = ConnectionFactory()
        self.factory.settings = ConnectionSettings({
            'channel #foo': {'enabled': True},
            'plugin {}'.format(NoticingPlugin.name): True})
        self.connection = self.factory.buildProtocol(None)
        self.connection.reactor = Clock()
        self.connection.makeConnection(self.transport)
        self.connection.irc_RPL_WELCOME('irc.server.test', [])
        self.connection.joined('#foo')

    def test_joins_and_parts(self):
        self.connection.joined('#bar')
        self.transport.clear()
        self.factory.reload_settings({
            'channel #foo': {'enabled': False},
            'channel #bar': {'enabled': 'soft'},
            'channel #baz': {'enabled': 'soft'},
            'channel #quux': {'enabled': True}})
        self.assertItemsEqual(self.transport.value().splitlines(),
                              ['PART #foo', 'JOIN #quux'])

    def test_plugin_identity(self):
        old_plugin = self.factory.settings.active_plugins().keys()[0]
        self.factory.reload_settings({
            'channel #foo': {'enabled': True},
            'plugin {}'.format(NoticingPlugin.name): True})
        new_plugin = self.factory.settings.active_plugins().keys()[0]
        self.assertIs(old_plugin, new_plugin)
Exemple #2
0
 def test_proxy_filebodyproducer(self):
     original = FileBodyProducer(BytesIO(LOREM_IPSUM))
     proxy = RecordingBodyProducer(original)
     self.assertEqual(original.length, proxy.length)
     transport = AbortableStringTransport()
     yield proxy.startProducing(transport)
     self.assertEqual(transport.value(), LOREM_IPSUM)
     self.assertEqual(proxy.value(), LOREM_IPSUM)
Exemple #3
0
 def test_redirect_to_same_host(self):
     finished = self.fetcher.fetch_title('http://foo.test/',
                                         hostname_tag=True)
     request, result = self.protocol.requests.pop()
     redirect_headers = Headers()
     redirect_headers.addRawHeader('Location', 'http://foo.test/bar')
     response = Response._construct(('HTTP', 1, 1), 301,
                                    'Moved Permanently', redirect_headers,
                                    AbortableStringTransport(), request)
     result.callback(response)
     request, result = self.protocol.requests.pop()
     response = Response._construct(('HTTP', 1, 1), 200, 'OK', Headers(),
                                    AbortableStringTransport(), request)
     result.callback(response)
     finished.addCallback(self.assertEqual, u'[foo.test] Unknown document')
     return finished
Exemple #4
0
 def test_no_redirect(self):
     finished = self.fetcher.fetch_title('http://foo.test/',
                                         hostname_tag=True)
     request, result = self.protocol.requests.pop()
     response = Response._construct(('HTTP', 1, 1), 200, 'OK', Headers(),
                                    AbortableStringTransport(), request)
     result.callback(response)
     finished.addCallback(self.assertEqual, u'[foo.test] Unknown document')
     return finished
Exemple #5
0
 def test_tag_iri_to_uri(self):
     finished = self.fetcher.fetch_title(u'http://ドメイン名例.test/',
                                         hostname_tag=True)
     request, result = self.protocol.requests.pop()
     response = Response._construct(('HTTP', 1, 1), 200, 'OK', Headers(),
                                    AbortableStringTransport(), request)
     result.callback(response)
     finished.addCallback(
         self.assertEqual, u'[ドメイン名例.test → xn--eckwd4c7cu47r2wf.test] '
         u'Unknown document')
     return finished
Exemple #6
0
 def test_soft_redirect(self):
     self.fetcher.extractors = {
         'text/html': SoftRedirectExtractor(u'http://bar.test/')
     }
     finished = self.fetcher.fetch_title('http://foo.test/',
                                         hostname_tag=True)
     request, result = self.protocol.requests.pop()
     redirect_headers = Headers()
     redirect_headers.addRawHeader('Content-Type', 'text/html')
     response = Response._construct(('HTTP', 1, 1), 200, 'OK',
                                    redirect_headers,
                                    AbortableStringTransport(), request)
     result.callback(response)
     request, result = self.protocol.requests.pop()
     response = Response._construct(('HTTP', 1, 1), 200, 'OK', Headers(),
                                    AbortableStringTransport(), request)
     result.callback(response)
     finished.addCallback(self.assertEqual,
                          u'[foo.test → bar.test] Unknown document')
     return finished
Exemple #7
0
 def setUp(self):
     self.transport = AbortableStringTransport()
     self.factory = ConnectionFactory()
     self.factory.settings = ConnectionSettings({
         'channel #foo': {'enabled': True},
         'plugin {}'.format(NoticingPlugin.name): True})
     self.connection = self.factory.buildProtocol(None)
     self.connection.reactor = Clock()
     self.connection.makeConnection(self.transport)
     self.connection.irc_RPL_WELCOME('irc.server.test', [])
     self.connection.joined('#foo')
Exemple #8
0
 def assert_delivery(self, data, expected):
     finished = Deferred()
     finished.addCallback(self.assertEqual, expected)
     response = Response(('HTTP', 1, 1), 200, 'OK', Headers(),
                         AbortableStringTransport())
     protocol = TruncatingReadBodyProtocol(response.code,
                                           response.phrase,
                                           finished,
                                           max_bytes=8)
     response.deliverBody(protocol)
     response._bodyDataReceived(data)
     response._bodyDataFinished()
     return finished
Exemple #9
0
 def test_infinite_hard_redirection(self):
     finished = self.fetcher.fetch_title(u'http://foo.test/',
                                         hostname_tag=True,
                                         friendly_errors=True)
     while self.protocol.requests:
         request, result = self.protocol.requests.pop()
         redirect_headers = Headers()
         redirect_headers.addRawHeader('Location', 'http://foo.test/')
         response = Response._construct(
             ('HTTP', 1, 1), 301, 'Moved Permanently', redirect_headers,
             AbortableStringTransport(), request)
         result.callback(response)
     finished.addCallback(self.assertEqual,
                          u'[foo.test] Encountered too many redirects.')
     return finished
Exemple #10
0
 def test_infinite_soft_redirection(self):
     self.fetcher.extractors = {
         'text/html': SoftRedirectExtractor(u'http://foo.test/')
     }
     finished = self.fetcher.fetch_title(u'http://foo.test/',
                                         hostname_tag=True,
                                         friendly_errors=True)
     while self.protocol.requests:
         request, result = self.protocol.requests.pop()
         redirect_headers = Headers()
         redirect_headers.addRawHeader('Content-Type', 'text/html')
         response = Response._construct(('HTTP', 1, 1), 200, 'OK',
                                        redirect_headers,
                                        AbortableStringTransport(), request)
         result.callback(response)
     finished.addCallback(self.assertEqual,
                          u'[foo.test] Encountered too many redirects.')
     return finished