tests:download: collect common code together

There was all-together too much copy-and-paste code in testdownload.py.
Collect common code together.