예제 #1
0
    def test_tn3270e_negotiation(self):
        # Arrange
        self.telnet = Telnet('IBM-3279-2-E')

        responses = [
            bytes.fromhex('ff fd 28'),
            bytes.fromhex('ff fa 28 08 02 ff f0'),
            bytes.fromhex(
                'ff fa 28 02 04 49 42 4d 2d 33 32 37 38 2d 32 2d 45 01 54 43 50 30 30 30 33 34 ff f0'
            ),
            bytes.fromhex('ff fa 28 03 04 ff f0')
        ]

        self.socket_mock.recv = Mock(side_effect=responses)

        self.assertFalse(self.telnet.is_tn3270_negotiated)
        self.assertFalse(self.telnet.is_tn3270e_negotiated)

        # Act
        self.telnet.open('mainframe', 23)

        # Assert
        self.assertTrue(self.telnet.is_tn3270_negotiated)
        self.assertTrue(self.telnet.is_tn3270e_negotiated)

        self.assertEqual(self.telnet.device_type, 'IBM-3278-2-E')
        self.assertEqual(self.telnet.device_name, 'TCP00034')

        self.socket_mock.sendall.assert_any_call(bytes.fromhex('ff fb 28'))
        self.socket_mock.sendall.assert_any_call(
            bytes.fromhex(
                'ff fa 28 02 07 49 42 4d 2d 33 32 37 38 2d 32 2d 45 ff f0'))
        self.socket_mock.sendall.assert_any_call(
            bytes.fromhex('ff fa 28 03 07 ff f0'))
예제 #2
0
    def test_basic_tn3270_negotiation(self):
        # Arrange
        self.telnet = Telnet('IBM-3279-2-E')

        responses = [
            bytes.fromhex('ff fd 18'),
            bytes.fromhex('ff fa 18 01 ff f0'),
            bytes.fromhex('ff fd 19'),
            bytes.fromhex('ff fb 19'),
            bytes.fromhex('ff fd 00'),
            bytes.fromhex('ff fb 00')
        ]

        self.socket_mock.recv = Mock(side_effect=responses)

        self.assertFalse(self.telnet.is_tn3270_negotiated)
        self.assertFalse(self.telnet.is_tn3270e_negotiated)

        # Act
        self.telnet.open('mainframe', 23)

        # Assert
        self.assertTrue(self.telnet.is_tn3270_negotiated)
        self.assertFalse(self.telnet.is_tn3270e_negotiated)

        self.socket_mock.sendall.assert_any_call(bytes.fromhex('ff fb 18'))
        self.socket_mock.sendall.assert_any_call(
            bytes.fromhex(
                'ff fa 18 00 49 42 4d 2d 33 32 37 39 2d 32 2d 45 ff f0'))
        self.socket_mock.sendall.assert_any_call(bytes.fromhex('ff fb 19'))
        self.socket_mock.sendall.assert_any_call(bytes.fromhex('ff fd 19'))
        self.socket_mock.sendall.assert_any_call(bytes.fromhex('ff fb 00'))
        self.socket_mock.sendall.assert_any_call(bytes.fromhex('ff fd 00'))
예제 #3
0
    def setUp(self):
        self.telnet = Telnet('IBM-3278-2')

        self.telnet.socket = Mock()

        patcher = patch('tn3270.telnet.select')

        self.select_mock = patcher.start()

        self.select_mock.return_value = [[self.telnet.socket]]

        self.addCleanup(patch.stopall)
예제 #4
0
    def test(self):
        # Arrange
        telnet = Telnet('IBM-3278-2')

        telnet.socket = Mock()

        # Act
        telnet.write(bytes.fromhex('01 02 03 ff 04 05'))

        # Assert
        telnet.socket.sendall.assert_called_with(
            bytes.fromhex('01 02 03 ff ff 04 05 ff ef'))
예제 #5
0
    def test_tn3270e(self):
        # Arrange
        telnet = Telnet('IBM-3279-2-E')

        telnet.socket = create_autospec(socket, instance=True)

        telnet.is_tn3270e_negotiated = True

        # Act
        telnet.write(bytes.fromhex('01 02 03 ff 04 05'))

        # Assert
        telnet.socket.sendall.assert_called_with(
            bytes.fromhex('00 00 00 00 00 01 02 03 ff ff 04 05 ff ef'))
예제 #6
0
    def test_unsuccessful_negotiation(self):
        # Arrange
        self.telnet = Telnet('IBM-3279-2-E')

        self.socket_mock.recv = Mock(
            return_value='hello world'.encode('ascii'))

        self.assertFalse(self.telnet.is_tn3270_negotiated)
        self.assertFalse(self.telnet.is_tn3270e_negotiated)

        # Act and assert
        with self.assertRaisesRegex(Exception,
                                    'Unable to negotiate TN3270 mode'):
            self.telnet.open('mainframe', 23)
예제 #7
0
    def test_basic_tn3270(self):
        # Arrange
        telnet = Telnet('IBM-3279-2-E')

        telnet.socket = Mock()

        telnet.is_tn3270e_negotiated = False

        # Act
        telnet.write(bytes.fromhex('01 02 03 ff 04 05'))

        # Assert
        telnet.socket.sendall.assert_called_with(
            bytes.fromhex('01 02 03 ff ff 04 05 ff ef'))
예제 #8
0
    def setUp(self):
        self.telnet = Telnet('IBM-3279-2-E')

        self.telnet.socket = create_autospec(socket, instance=True)

        self.telnet.socket_selector = create_autospec(BaseSelector,
                                                      instance=True)

        self.is_tn3270e_negotiated = False

        selector_key = Mock(fileobj=self.telnet.socket)

        self.telnet.socket_selector.select.return_value = [
            (selector_key, selectors.EVENT_READ)
        ]
예제 #9
0
    def setUp(self):
        self.telnet = Telnet('IBM-3279-2-E')

        self.telnet.socket = Mock()

        self.telnet.socket_selector = Mock()

        self.is_tn3270e_negotiated = False

        selector_key = Mock(fileobj=self.telnet.socket)

        self.telnet.socket_selector.select.return_value = [
            (selector_key, selectors.EVENT_READ)
        ]

        self.addCleanup(patch.stopall)
예제 #10
0
    def setUp(self):
        self.telnet = Telnet('IBM-3278-2')

        self.socket_mock = Mock()

        patcher = patch('socket.create_connection')

        create_connection_mock = patcher.start()

        create_connection_mock.return_value = self.socket_mock

        patcher = patch('tn3270.telnet.select')

        select_mock = patcher.start()

        select_mock.return_value = [[self.socket_mock]]

        self.addCleanup(patch.stopall)