Exemplo n.º 1
0
    def test_when_closed_listen_raises_exception(self):
        self.serial.isOpen = Mock(return_value=False)
        self.serial.read = Mock(return_value=bytearray(b'\xb0\x12\x00\x3e'))
        channel = Channel(self.serial, MagicMock())

        channel.receive_message()

        self.assertRaises(ChannelException)
Exemplo n.º 2
0
    def test_when_receive_message_then_calls_read(self):
        self.serial.read = Mock(
            return_value=commands_from_stm.Message.SUCCESSFULL_TASK.value)
        channel = Channel(self.serial, MagicMock())

        channel.receive_message()

        self.serial.read.assert_called_with(
            commands_from_stm.Message.BYTES_TO_READ.value)
Exemplo n.º 3
0
    def test_when_receive_country_code_then_return_country_code(self):
        self.serial.read = Mock(return_value=bytearray(b'\xb0\x12\x00\x3e'))
        channel = Channel(self.serial, MagicMock())

        msg = channel.receive_message()

        self.assertEqual(0x12, msg.country)
Exemplo n.º 4
0
    def test_when_receive_country_code_then_return_country_type(self):
        self.serial.read = Mock(return_value=bytearray(b'\xb0\x12\x00\x3e'))
        channel = Channel(self.serial, MagicMock())

        msg = channel.receive_message()

        self.assertEqual(commands_from_stm.Feedback.COUNTRY, msg.type)
Exemplo n.º 5
0
    def test_when_receive_open_close_message_then_return_hey_type(self):
        self.serial.read = Mock(
            return_value=commands_from_stm.Message.OPEN_CLOSE_MSG.value)
        channel = Channel(self.serial, MagicMock())

        self.assertEqual(commands_from_stm.Feedback.HEY,
                         channel.receive_message().type)
Exemplo n.º 6
0
    def test_when_receive_nothing_message_then_return_hey_type(self):
        self.serial.read = Mock(
            return_value=commands_from_stm.Message.NOTHING.value)
        channel = Channel(self.serial, MagicMock())

        msg = channel.receive_message()

        self.assertEqual(commands_from_stm.Feedback.HEY, msg.type)