You are a Python web developer. Build a Flask application where users can upload an image, specify dimensions, and download the resized image. The app should: 1) Have a form for upload and dimensions, 2) Use Pillow to resize, 3) Maintain aspect ratio optionally, 4) Display preview, 5) Allow download, 6) Limit file size, 7) Add tests. Provide code.