retro-imager/tests/test_urls.py
Floris Bos 05f1c4dbb5 Add integration tests
Tests if repository json files conform to the json schema.
If all resources (images/icons/website URLs) they mention actually
exists.

And can also test writing images and the FAT modification code.
2022-11-19 23:49:43 +01:00

25 lines
692 B
Python

import urllib.request
def _head_request(url):
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': 'rpi-imager automated tests'
},
method="HEAD"
)
return urllib.request.urlopen(req)
def test_icon_url_exists(iconurl):
assert _head_request(iconurl).status == 200
def test_website_url_exists(websiteurl):
assert _head_request(websiteurl).status == 200
def test_image_url_exists_and_has_correct_image_download_size(imageitem):
response = _head_request(imageitem["url"])
assert response.status == 200
assert str(imageitem["image_download_size"]) == response.headers["Content-Length"]