Exemplo n.º 1
0
    def test_send_message_correct_call_when_message_is_too_long(self):
        message_content = ""
        for i in range(256):
            message_content += 'm'
        assert len(message_content) == 256

        with pytest.raises(ValueError):
            Network.send_message(self.socket_mock, message_content)
Exemplo n.º 2
0
    def test_send_message_correct_call(self):
        message_content = ""
        for i in range(255):
            message_content += 'm'
        assert len(message_content) == 255

        self.socket_mock.send.side_effect = [0, 1, 0, 100, 0, 155]

        Network.send_message(self.socket_mock, message_content)

        self.socket_mock.send.assert_has_calls([call(struct.pack("B", 255)),
                                                call(struct.pack("B", 255)),
                                                call(message_content),
                                                call(message_content),
                                                call(message_content[100:]),
                                                call(message_content[100:]),
                                                ])