Exemplo n.º 1
0
    def test_close_stream_with_stream(self):
        stream = Stream(self.state)
        stream.id = 1

        self.state.streams[1] = stream
        self.state.close_stream(stream.id)
        self.assertEqual(self.transport.value(), 'CLOSESTREAM 1 1\r\n')
Exemplo n.º 2
0
    def test_close_stream_with_stream(self):
        stream = Stream(self.state)
        stream.id = 1

        self.state.streams[1] = stream
        self.state.close_stream(stream.id)
        self.assertEqual(self.transport.value(), 'CLOSESTREAM 1 1\r\n')
Exemplo n.º 3
0
 def test_close_stream_invalid_reason(self):
     stream = Stream(self.state)
     stream.id = 1
     self.state.streams[1] = stream
     self.assertRaises(
         ValueError,
         self.state.close_stream,
         stream,
         'FOO_INVALID_REASON'
     )
Exemplo n.º 4
0
 def test_close_stream_invalid_reason(self):
     stream = Stream(self.state)
     stream.id = 1
     self.state.streams[1] = stream
     self.assertRaises(
         ValueError,
         self.state.close_stream,
         stream,
         'FOO_INVALID_REASON'
     )
Exemplo n.º 5
0
    def test_close_stream(self):
        stream = Stream(self.state)
        stream.id = 1
        try:
            self.state.close_stream(stream)
            self.assertTrue(False)
        except KeyError:
            pass

        self.state.streams[1] = stream
        self.state.close_stream(stream)
        self.assertEqual(self.transport.value(), 'CLOSESTREAM 1 1\r\n')
Exemplo n.º 6
0
    def test_attacher_errors(self):
        class MyAttacher(object):
            implements(IStreamAttacher)

            def __init__(self, answer):
                self.streams = []
                self.answer = answer

            def attach_stream(self, stream, circuits):
                return self.answer

        self.state.circuits[1] = FakeCircuit(1)
        attacher = MyAttacher(FakeCircuit(2))
        self.state.set_attacher(attacher, FakeReactor(self))

        stream = Stream(self.state)
        stream.id = 3
        msg = ''
        try:
            self.state._maybe_attach(stream)
        except Exception, e:
            msg = str(e)
Exemplo n.º 7
0
    def test_attacher_errors(self):
        @implementer(IStreamAttacher)
        class MyAttacher(object):
            def __init__(self, answer):
                self.streams = []
                self.answer = answer

            def attach_stream(self, stream, circuits):
                return self.answer

        self.state.circuits[1] = FakeCircuit(1)
        attacher = MyAttacher(FakeCircuit(2))
        self.state.set_attacher(attacher, FakeReactor(self))

        stream = Stream(self.state)
        stream.id = 3
        msg = ''
        try:
            yield self.state._maybe_attach(stream)
        except Exception as e:
            msg = str(e)
        self.assertTrue('circuit unknown' in msg)

        attacher.answer = self.state.circuits[1]
        msg = ''
        try:
            yield self.state._maybe_attach(stream)
        except Exception as e:
            msg = str(e)
        self.assertTrue('only attach to BUILT' in msg)

        attacher.answer = 'not a Circuit instance'
        msg = ''
        try:
            yield self.state._maybe_attach(stream)
        except Exception as e:
            msg = str(e)
        self.assertTrue('Circuit instance' in msg)