Fix render_png middleware, add missing tests