def test_send_zero_raises_error(self, monkeypatch, data):

        mocked_socket = MagicMock()
        mock_send = MagicMock(return_value=0)
        mocked_socket.send = mock_send

        conn = Connection()
        monkeypatch.setattr(conn, "socket", mocked_socket)

        with pytest.raises(FaktoryConnectionResetError):
            conn.reply("test command")
    def test_sends_until_out_of_data(self, monkeypatch, data):

        mocked_socket = MagicMock()
        mock_send = MagicMock(return_value=7)
        mocked_socket.send = mock_send

        conn = Connection()
        monkeypatch.setattr(conn, "socket", mocked_socket)

        conn.reply("test command")

        calls = [call(b"test command\r\n"), call(b"mmand\r\n")]
        mock_send.assert_has_calls(calls)
    def test_adds_return_and_newline_to_payload(self, monkeypatch, data):

        mocked_socket = MagicMock()
        mock_send = MagicMock()
        mocked_socket.send = mock_send

        conn = Connection()
        monkeypatch.setattr(conn, "socket", mocked_socket)

        conn.reply("test command")
        called_with = mock_send.call_args[0][0]
        decoded = called_with.decode()

        assert "\r\n" == decoded[-2:]
    def test_sends_bytes(self, monkeypatch, data):

        mocked_socket = MagicMock()
        mock_send = MagicMock()
        mocked_socket.send = mock_send

        conn = Connection()
        monkeypatch.setattr(conn, "socket", mocked_socket)

        conn.reply("test command")

        mock_send.assert_called_once()
        assert isinstance(mock_send.call_args[0][0], bytes)
        decoded_value = mock_send.call_args[0][0].decode()
        assert decoded_value == "test command\r\n"