forked from platformio/platformio-core
Refactor test for packages manifest
This commit is contained in:
@ -14,29 +14,10 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
from os.path import basename
|
|
||||||
|
|
||||||
from platformio.util import get_api_result
|
from platformio.util import get_api_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def sfpkglist():
|
|
||||||
result = None
|
|
||||||
r = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
r = requests.get("http://sourceforge.net/projects"
|
|
||||||
"/platformio-storage/files/packages/list")
|
|
||||||
result = r.json()
|
|
||||||
r.raise_for_status()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
if r:
|
|
||||||
r.close()
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_generate_tests(metafunc):
|
def pytest_generate_tests(metafunc):
|
||||||
if "package_data" not in metafunc.fixturenames:
|
if "package_data" not in metafunc.fixturenames:
|
||||||
return
|
return
|
||||||
@ -52,39 +33,17 @@ def pytest_generate_tests(metafunc):
|
|||||||
def validate_response(req):
|
def validate_response(req):
|
||||||
assert req.status_code == 200
|
assert req.status_code == 200
|
||||||
assert int(req.headers['Content-Length']) > 0
|
assert int(req.headers['Content-Length']) > 0
|
||||||
|
assert req.headers['Content-Type'] in ("application/gzip",
|
||||||
|
"application/octet-stream")
|
||||||
|
|
||||||
|
|
||||||
def validate_package(url, sfpkglist):
|
def test_package(package_data):
|
||||||
r = requests.head(url, allow_redirects=True)
|
|
||||||
validate_response(r)
|
|
||||||
assert r.headers['Content-Type'] in ("application/x-gzip",
|
|
||||||
"application/octet-stream")
|
|
||||||
|
|
||||||
|
|
||||||
def test_package(package_data, sfpkglist):
|
|
||||||
assert package_data['url'].endswith("%d.tar.gz" % package_data['version'])
|
assert package_data['url'].endswith("%d.tar.gz" % package_data['version'])
|
||||||
sf_package = "sourceforge.net" in package_data['url']
|
|
||||||
|
|
||||||
# check content type and that file exists
|
|
||||||
try:
|
|
||||||
r = requests.head(package_data['url'], allow_redirects=True)
|
|
||||||
if 500 <= r.status_code <= 599:
|
|
||||||
raise requests.exceptions.ConnectionError()
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
|
||||||
if sf_package:
|
|
||||||
return pytest.skip("SF is off-line")
|
|
||||||
raise Exception(e)
|
|
||||||
|
|
||||||
|
r = requests.head(package_data['url'], allow_redirects=True)
|
||||||
validate_response(r)
|
validate_response(r)
|
||||||
assert r.headers['Content-Type'] in ("application/x-gzip",
|
|
||||||
"application/octet-stream")
|
|
||||||
|
|
||||||
if not sf_package:
|
if "X-Checksum-Sha1" not in r.headers:
|
||||||
return
|
return pytest.skip("X-Checksum-Sha1 is not provided")
|
||||||
|
|
||||||
# check sha1 sum
|
assert package_data['sha1'] == r.headers.get("X-Checksum-Sha1")
|
||||||
if sfpkglist is None:
|
|
||||||
return pytest.skip("SF is off-line")
|
|
||||||
pkgname = basename(package_data['url'])
|
|
||||||
assert pkgname in sfpkglist
|
|
||||||
assert package_data['sha1'] == sfpkglist.get(pkgname, {}).get("sha1")
|
|
||||||
|
Reference in New Issue
Block a user