Files
platformio-core/tests/misc/test_misc.py

49 lines
1.7 KiB
Python
Raw Permalink Normal View History

# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# 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.
2020-08-17 12:56:57 +03:00
# pylint: disable=unused-argument
import pytest
import requests
2017-12-14 22:01:59 +02:00
2022-05-30 20:29:35 +03:00
from platformio import __check_internet_hosts__, http, proc
2022-06-01 12:35:55 +03:00
from platformio.registry.client import RegistryClient
def test_platformio_cli():
2020-08-22 17:48:49 +03:00
result = proc.exec_command(["pio", "--help"])
assert result["returncode"] == 0
2020-08-17 12:56:57 +03:00
# pylint: disable=unsupported-membership-test
assert "Usage: pio [OPTIONS] COMMAND [ARGS]..." in result["out"]
def test_ping_internet_ips():
2020-08-23 14:29:31 +03:00
for host in __check_internet_hosts__:
requests.get("http://%s" % host, allow_redirects=False, timeout=2)
2020-06-27 12:36:57 +03:00
def test_api_internet_offline(without_internet, isolated_pio_core):
2020-08-22 17:48:49 +03:00
regclient = RegistryClient()
with pytest.raises(http.InternetConnectionError):
2023-06-05 18:15:30 +03:00
regclient.fetch_json_data("get", "/v3/search")
2018-01-13 17:02:08 +02:00
2020-06-27 12:36:57 +03:00
def test_api_cache(monkeypatch, isolated_pio_core):
2020-08-22 17:48:49 +03:00
regclient = RegistryClient()
2023-06-05 18:15:30 +03:00
api_kwargs = {"method": "get", "path": "/v3/search", "x_cache_valid": "10s"}
2020-08-22 17:48:49 +03:00
result = regclient.fetch_json_data(**api_kwargs)
2023-06-05 18:15:30 +03:00
assert result and "total" in result
2020-08-22 17:48:49 +03:00
monkeypatch.setattr(http, "_internet_on", lambda: False)
assert regclient.fetch_json_data(**api_kwargs) == result