2016-01-01 20:51:48 +02:00
|
|
|
# Copyright 2014-2016 Ivan Kravets <me@ikravets.com>
|
2015-11-18 17:16:17 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2015-02-20 21:02:10 +02:00
|
|
|
|
2015-02-24 20:11:57 +02:00
|
|
|
import pytest
|
2015-02-20 21:02:10 +02:00
|
|
|
import requests
|
2015-02-24 20:11:57 +02:00
|
|
|
|
2015-02-20 21:02:10 +02:00
|
|
|
from platformio.util import get_api_result
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "package_data" not in metafunc.fixturenames:
|
|
|
|
return
|
2015-03-14 00:01:32 +02:00
|
|
|
pkgs_manifest = get_api_result("/packages/manifest")
|
2015-02-20 21:02:10 +02:00
|
|
|
assert isinstance(pkgs_manifest, dict)
|
|
|
|
packages = []
|
|
|
|
for _, variants in pkgs_manifest.iteritems():
|
|
|
|
for item in variants:
|
|
|
|
packages.append(item)
|
|
|
|
metafunc.parametrize("package_data", packages)
|
|
|
|
|
|
|
|
|
|
|
|
def validate_response(req):
|
|
|
|
assert req.status_code == 200
|
|
|
|
assert int(req.headers['Content-Length']) > 0
|
2016-02-26 21:00:51 +02:00
|
|
|
assert req.headers['Content-Type'] in ("application/gzip",
|
|
|
|
"application/octet-stream")
|
2015-02-20 21:02:10 +02:00
|
|
|
|
|
|
|
|
2016-02-26 21:00:51 +02:00
|
|
|
def test_package(package_data):
|
2015-02-21 15:15:00 +02:00
|
|
|
assert package_data['url'].endswith("%d.tar.gz" % package_data['version'])
|
2015-05-29 18:34:21 +03:00
|
|
|
|
2016-02-26 21:00:51 +02:00
|
|
|
r = requests.head(package_data['url'], allow_redirects=True)
|
2015-02-24 20:11:57 +02:00
|
|
|
validate_response(r)
|
|
|
|
|
2016-02-26 21:00:51 +02:00
|
|
|
if "X-Checksum-Sha1" not in r.headers:
|
|
|
|
return pytest.skip("X-Checksum-Sha1 is not provided")
|
2015-07-29 19:59:39 +03:00
|
|
|
|
2016-02-26 21:00:51 +02:00
|
|
|
assert package_data['sha1'] == r.headers.get("X-Checksum-Sha1")
|