Пример #1
0
class TestFeeder(TestCase):

    def setUp(self):
        self.connection = Mock()
        self.feeder = Feeder(self.connection)

    def test_feeder(self):
        self.connection.recv.return_value = b''
        self.assertEqual((None, b''), self.feeder.feed(b''))

        self.connection.recv.return_value = b'\x00\x00\x00\x04\x00\x00\x00\x01'
        pck, buf = self.feeder.feed(b'')
        self.assertEqual(pck, Connect())
        self.assertEqual(b'', buf)

        self.connection.recv.return_value = b'\x00\x00\x00\x01'
        pck, buf = self.feeder.feed(b'\x00\x00\x00\x04')
        self.assertEqual(pck, Connect())
        self.assertEqual(b'', buf)

        self.connection.recv.return_value = b''
        pck, buf = self.feeder.feed(b'\x00\x00\x00\x08\x00\x00\x00\x05data')
        self.assertEqual(pck, PingD(data='data'))
        self.assertNotEqual(pck, PingD(data=''))
Пример #2
0
 def setUp(self):
     self.connection = Mock()
     self.feeder = Feeder(self.connection)