https-checker-simple 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- https_checker_simple-0.1.0/LICENSE +21 -0
- https_checker_simple-0.1.0/PKG-INFO +31 -0
- https_checker_simple-0.1.0/README.md +12 -0
- https_checker_simple-0.1.0/pyproject.toml +78 -0
- https_checker_simple-0.1.0/setup.cfg +4 -0
- https_checker_simple-0.1.0/src/https_checker_simple.egg-info/PKG-INFO +31 -0
- https_checker_simple-0.1.0/src/https_checker_simple.egg-info/SOURCES.txt +14 -0
- https_checker_simple-0.1.0/src/https_checker_simple.egg-info/dependency_links.txt +1 -0
- https_checker_simple-0.1.0/src/https_checker_simple.egg-info/entry_points.txt +2 -0
- https_checker_simple-0.1.0/src/https_checker_simple.egg-info/requires.txt +11 -0
- https_checker_simple-0.1.0/src/https_checker_simple.egg-info/top_level.txt +1 -0
- https_checker_simple-0.1.0/src/simple_http_checker/__init__.py +0 -0
- https_checker_simple-0.1.0/src/simple_http_checker/checker.py +47 -0
- https_checker_simple-0.1.0/src/simple_http_checker/cli.py +52 -0
- https_checker_simple-0.1.0/tests/test_checker.py +146 -0
- https_checker_simple-0.1.0/tests/test_cli.py +45 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nazareno Urday
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: https-checker-simple
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple CLI tool to check the status of URLS.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: requests<3.0,>=2.28
|
|
9
|
+
Requires-Dist: click<9.0,>=8.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest; extra == "dev"
|
|
12
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
13
|
+
Requires-Dist: ruff; extra == "dev"
|
|
14
|
+
Requires-Dist: black; extra == "dev"
|
|
15
|
+
Requires-Dist: mypy; extra == "dev"
|
|
16
|
+
Requires-Dist: bandit; extra == "dev"
|
|
17
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# python for DevOps: CI/CD for Python Projects
|
|
21
|
+
This repository contains the code to learn CI/CD for future projects implementation.
|
|
22
|
+
|
|
23
|
+
## What we implement in this repository
|
|
24
|
+
|
|
25
|
+
[x] Implement the project (code files)
|
|
26
|
+
[x] Add a simple GHA workflow and make sure it runs until completion
|
|
27
|
+
[x] Add linting (ruff) and format checks (black)
|
|
28
|
+
[x] Add typing (mypy) and security checks (bandit)
|
|
29
|
+
[x] Add test automation
|
|
30
|
+
[x] Build our Python project
|
|
31
|
+
[] Publish the project to both TestPyPI and PyPI when a new released is published
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# python for DevOps: CI/CD for Python Projects
|
|
2
|
+
This repository contains the code to learn CI/CD for future projects implementation.
|
|
3
|
+
|
|
4
|
+
## What we implement in this repository
|
|
5
|
+
|
|
6
|
+
[x] Implement the project (code files)
|
|
7
|
+
[x] Add a simple GHA workflow and make sure it runs until completion
|
|
8
|
+
[x] Add linting (ruff) and format checks (black)
|
|
9
|
+
[x] Add typing (mypy) and security checks (bandit)
|
|
10
|
+
[x] Add test automation
|
|
11
|
+
[x] Build our Python project
|
|
12
|
+
[] Publish the project to both TestPyPI and PyPI when a new released is published
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "https-checker-simple"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A simple CLI tool to check the status of URLS."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"requests>=2.28,<3.0",
|
|
13
|
+
"click>=8.0,<9.0"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
dev = [
|
|
18
|
+
"pytest",
|
|
19
|
+
"pytest-mock",
|
|
20
|
+
"ruff",
|
|
21
|
+
"black",
|
|
22
|
+
"mypy",
|
|
23
|
+
"bandit",
|
|
24
|
+
"types-requests"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
check-urls = "simple_http_checker.cli:main"
|
|
29
|
+
|
|
30
|
+
[tool.ruff]
|
|
31
|
+
line-length = 65
|
|
32
|
+
|
|
33
|
+
[tool.black]
|
|
34
|
+
line-length = 65
|
|
35
|
+
|
|
36
|
+
[tool.mypy]
|
|
37
|
+
warn_return_any = true
|
|
38
|
+
warn_unused_configs = true
|
|
39
|
+
ignore_missing_imports = true
|
|
40
|
+
|
|
41
|
+
[tool.bandit]
|
|
42
|
+
exclude_dirs = [".venv", "__pycache__", "build", "dist"]
|
|
43
|
+
skips = ["B101"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
addopts = "-rA -s -v"
|
|
47
|
+
|
|
48
|
+
[tool.semantic_realease]
|
|
49
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
50
|
+
buid_command = "pip install build && python -m build"
|
|
51
|
+
dist_path = "dist/"
|
|
52
|
+
upload_to_pypi = false
|
|
53
|
+
upload_to_release = true
|
|
54
|
+
hvcs = "github"
|
|
55
|
+
commit_message = "chore(release): {version} [skip ci]"
|
|
56
|
+
|
|
57
|
+
[tool.semantic_release_branches.main]
|
|
58
|
+
match = "main"
|
|
59
|
+
prerelease = false
|
|
60
|
+
|
|
61
|
+
[tool.semantic_release.changelog.default_templates]
|
|
62
|
+
changelog_file = "CHANGELOG.md"
|
|
63
|
+
|
|
64
|
+
[tool.semantic_release.commit_parser_options]
|
|
65
|
+
allowed_tags = [
|
|
66
|
+
"build",
|
|
67
|
+
"chore",
|
|
68
|
+
"ci",
|
|
69
|
+
"docs",
|
|
70
|
+
"feat",
|
|
71
|
+
"fix",
|
|
72
|
+
"perf",
|
|
73
|
+
"style",
|
|
74
|
+
"refactor",
|
|
75
|
+
"test"
|
|
76
|
+
]
|
|
77
|
+
minor_tags = ["feat"]
|
|
78
|
+
patch_tags = ["fix", "perf"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: https-checker-simple
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A simple CLI tool to check the status of URLS.
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: requests<3.0,>=2.28
|
|
9
|
+
Requires-Dist: click<9.0,>=8.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest; extra == "dev"
|
|
12
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
13
|
+
Requires-Dist: ruff; extra == "dev"
|
|
14
|
+
Requires-Dist: black; extra == "dev"
|
|
15
|
+
Requires-Dist: mypy; extra == "dev"
|
|
16
|
+
Requires-Dist: bandit; extra == "dev"
|
|
17
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# python for DevOps: CI/CD for Python Projects
|
|
21
|
+
This repository contains the code to learn CI/CD for future projects implementation.
|
|
22
|
+
|
|
23
|
+
## What we implement in this repository
|
|
24
|
+
|
|
25
|
+
[x] Implement the project (code files)
|
|
26
|
+
[x] Add a simple GHA workflow and make sure it runs until completion
|
|
27
|
+
[x] Add linting (ruff) and format checks (black)
|
|
28
|
+
[x] Add typing (mypy) and security checks (bandit)
|
|
29
|
+
[x] Add test automation
|
|
30
|
+
[x] Build our Python project
|
|
31
|
+
[] Publish the project to both TestPyPI and PyPI when a new released is published
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/https_checker_simple.egg-info/PKG-INFO
|
|
5
|
+
src/https_checker_simple.egg-info/SOURCES.txt
|
|
6
|
+
src/https_checker_simple.egg-info/dependency_links.txt
|
|
7
|
+
src/https_checker_simple.egg-info/entry_points.txt
|
|
8
|
+
src/https_checker_simple.egg-info/requires.txt
|
|
9
|
+
src/https_checker_simple.egg-info/top_level.txt
|
|
10
|
+
src/simple_http_checker/__init__.py
|
|
11
|
+
src/simple_http_checker/checker.py
|
|
12
|
+
src/simple_http_checker/cli.py
|
|
13
|
+
tests/test_checker.py
|
|
14
|
+
tests/test_cli.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simple_http_checker
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def check_urls(
|
|
10
|
+
urls: Collection[str], timeout: int = 5
|
|
11
|
+
) -> dict[str, str]:
|
|
12
|
+
logger.info(
|
|
13
|
+
f"Starting check for {len(urls)} URLs with a timeout of {timeout} seconds"
|
|
14
|
+
)
|
|
15
|
+
results: dict[str, str] = {}
|
|
16
|
+
|
|
17
|
+
for url in urls:
|
|
18
|
+
status = "UNKNOWN"
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
logger.debug(f"Checking URL: {url}")
|
|
22
|
+
response = requests.get(url, timeout=timeout)
|
|
23
|
+
|
|
24
|
+
if response.ok:
|
|
25
|
+
status = f"{response.status_code} OK"
|
|
26
|
+
else:
|
|
27
|
+
status = f"{response.status_code}, [{response.reason}]"
|
|
28
|
+
|
|
29
|
+
except requests.exceptions.Timeout:
|
|
30
|
+
status = "TIMEOUT"
|
|
31
|
+
logger.warning(f"Request to {url} timed out")
|
|
32
|
+
|
|
33
|
+
except requests.exceptions.ConnectionError:
|
|
34
|
+
status = "CONNECTION ERROR"
|
|
35
|
+
logger.warning(f"Connection error for {url}")
|
|
36
|
+
|
|
37
|
+
except requests.exceptions.RequestException as error:
|
|
38
|
+
status = f"ERROR: {error}"
|
|
39
|
+
logger.error(
|
|
40
|
+
f"An unexpected error occurred while checking {url}"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
results[url] = status
|
|
44
|
+
logger.debug(f"Checked URL: {url:<40} -> {status}")
|
|
45
|
+
|
|
46
|
+
logger.info("URL check finished")
|
|
47
|
+
return results
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from collections.abc import Collection
|
|
3
|
+
|
|
4
|
+
import click
|
|
5
|
+
|
|
6
|
+
from .checker import check_urls
|
|
7
|
+
|
|
8
|
+
logging.basicConfig(
|
|
9
|
+
level=logging.INFO,
|
|
10
|
+
format="[%(asctime)s] %(levelname)-8s %(name)s: %(message)s",
|
|
11
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@click.command()
|
|
19
|
+
@click.argument("urls", nargs=-1)
|
|
20
|
+
@click.option("--timeout", default=5, help="Timeout in seconds")
|
|
21
|
+
@click.option(
|
|
22
|
+
"--verbose", "-v", is_flag=True, help="Enable debug logging."
|
|
23
|
+
)
|
|
24
|
+
def main(urls: Collection[str], timeout: int, verbose: bool):
|
|
25
|
+
if verbose:
|
|
26
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
27
|
+
logger.debug("Verbose logging enabled")
|
|
28
|
+
|
|
29
|
+
logger.debug(f"Received URLs: {urls}")
|
|
30
|
+
logger.debug(f"Received timeout: {timeout}")
|
|
31
|
+
logger.debug(f"Received verbose: {verbose}")
|
|
32
|
+
|
|
33
|
+
if not urls:
|
|
34
|
+
logger.warning("No URLs provided")
|
|
35
|
+
click.echo("Usage: check-urls <URL1> <URL2> ...")
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
logger.info(f"Starting check for {len(urls)} URLs.")
|
|
39
|
+
|
|
40
|
+
results = check_urls(list(urls), timeout)
|
|
41
|
+
|
|
42
|
+
click.echo("\n---Results---")
|
|
43
|
+
|
|
44
|
+
for url, status in results.items():
|
|
45
|
+
|
|
46
|
+
if "OK" in status:
|
|
47
|
+
fg_color = "green"
|
|
48
|
+
|
|
49
|
+
else:
|
|
50
|
+
fg_color = "red"
|
|
51
|
+
|
|
52
|
+
click.secho(f"{url:<40} -> {status}", fg=fg_color)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import requests
|
|
3
|
+
from pytest_mock import MockerFixture
|
|
4
|
+
|
|
5
|
+
from simple_http_checker.checker import check_urls
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_check_urls_success(mocker):
|
|
9
|
+
mock_requests_get = mocker.patch(
|
|
10
|
+
"simple_http_checker.checker.requests.get"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
mock_response = mocker.MagicMock(spec=requests.Response)
|
|
14
|
+
mock_response.status_code = 200
|
|
15
|
+
mock_response.reason = "OK"
|
|
16
|
+
mock_response.ok = True
|
|
17
|
+
mock_requests_get.return_value = mock_response
|
|
18
|
+
|
|
19
|
+
urls = ["https://www.example.com"]
|
|
20
|
+
results = check_urls(urls)
|
|
21
|
+
|
|
22
|
+
mock_requests_get.assert_called_once_with(urls[0], timeout=5)
|
|
23
|
+
assert results[urls[0]] == "200 OK"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_check_urls_client_error(mocker: MockerFixture):
|
|
27
|
+
mock_requests_get = mocker.patch(
|
|
28
|
+
"simple_http_checker.checker.requests.get"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
mock_response = mocker.MagicMock(spec=requests.Response)
|
|
32
|
+
mock_response.status_code = 404
|
|
33
|
+
mock_response.reason = "Not Found"
|
|
34
|
+
mock_response.ok = False
|
|
35
|
+
mock_requests_get.return_value = mock_response
|
|
36
|
+
|
|
37
|
+
urls = ["https://www.example.com/nonexistent"]
|
|
38
|
+
results = check_urls(urls)
|
|
39
|
+
|
|
40
|
+
mock_requests_get.assert_called_once_with(urls[0], timeout=5)
|
|
41
|
+
assert results[urls[0]] == "404, [Not Found]"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.parametrize(
|
|
45
|
+
"error_exception,expected_status",
|
|
46
|
+
[
|
|
47
|
+
(requests.exceptions.Timeout, "TIMEOUT"),
|
|
48
|
+
(
|
|
49
|
+
requests.exceptions.ConnectionError,
|
|
50
|
+
"CONNECTION ERROR",
|
|
51
|
+
),
|
|
52
|
+
(
|
|
53
|
+
requests.exceptions.RequestException,
|
|
54
|
+
"ERROR: Simulated error",
|
|
55
|
+
),
|
|
56
|
+
],
|
|
57
|
+
)
|
|
58
|
+
def test_check_urls_requests_exceptions(
|
|
59
|
+
mocker: MockerFixture,
|
|
60
|
+
error_exception: type[requests.exceptions.RequestException],
|
|
61
|
+
expected_status: str,
|
|
62
|
+
):
|
|
63
|
+
|
|
64
|
+
mock_requests_get = mocker.patch(
|
|
65
|
+
"simple_http_checker.checker.requests.get"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
mock_requests_get.side_effect = error_exception(
|
|
69
|
+
"Simulated error"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
urls = ["https://www.problem.com"]
|
|
73
|
+
results = check_urls(urls)
|
|
74
|
+
|
|
75
|
+
mock_requests_get.assert_called_once_with(urls[0], timeout=5)
|
|
76
|
+
assert results[urls[0]] == expected_status
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_check_urls_with_multiple_urls(mocker: MockerFixture):
|
|
80
|
+
mock_requests_get = mocker.patch(
|
|
81
|
+
"simple_http_checker.checker.requests.get"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# First call: OK
|
|
85
|
+
mock_response_ok = mocker.MagicMock(spec=requests.Response)
|
|
86
|
+
mock_response_ok.status_code = 200
|
|
87
|
+
mock_response_ok.reason = "OK"
|
|
88
|
+
mock_response_ok.ok = True
|
|
89
|
+
|
|
90
|
+
# Second call: Timeout
|
|
91
|
+
timeout_exception = requests.exceptions.Timeout(
|
|
92
|
+
"Simulated timeout"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Third call: 500 Server Error
|
|
96
|
+
mock_response_fail = mocker.MagicMock(spec=requests.Response)
|
|
97
|
+
mock_response_fail.status_code = 500
|
|
98
|
+
mock_response_fail.reason = "Server Error"
|
|
99
|
+
mock_response_fail.ok = False
|
|
100
|
+
|
|
101
|
+
mock_requests_get.side_effect = [
|
|
102
|
+
mock_response_ok,
|
|
103
|
+
timeout_exception,
|
|
104
|
+
mock_response_fail,
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
urls = [
|
|
108
|
+
"https://success.com",
|
|
109
|
+
"https://timeout.com",
|
|
110
|
+
"https://servererror.com",
|
|
111
|
+
]
|
|
112
|
+
results = check_urls(urls)
|
|
113
|
+
|
|
114
|
+
assert len(results) == 3
|
|
115
|
+
assert mock_requests_get.call_count == 3
|
|
116
|
+
assert results[urls[0]] == "200 OK"
|
|
117
|
+
assert results[urls[1]] == "TIMEOUT"
|
|
118
|
+
assert results[urls[2]] == "500, [Server Error]"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_check_urls_empty_list():
|
|
122
|
+
urls = []
|
|
123
|
+
results = check_urls(urls)
|
|
124
|
+
assert len(results) == 0
|
|
125
|
+
assert results == {}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_check_urls_custom_timeout(mocker):
|
|
129
|
+
mock_requests_get = mocker.patch(
|
|
130
|
+
"simple_http_checker.checker.requests.get"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
mock_response = mocker.MagicMock(spec=requests.Response)
|
|
134
|
+
mock_response.status_code = 200
|
|
135
|
+
mock_response.reason = "OK"
|
|
136
|
+
mock_response.ok = True
|
|
137
|
+
mock_requests_get.return_value = mock_response
|
|
138
|
+
|
|
139
|
+
urls = ["https://www.example.com"]
|
|
140
|
+
custom_timeout = 10
|
|
141
|
+
results = check_urls(urls, timeout=custom_timeout)
|
|
142
|
+
|
|
143
|
+
mock_requests_get.assert_called_once_with(
|
|
144
|
+
urls[0], timeout=custom_timeout
|
|
145
|
+
)
|
|
146
|
+
assert results[urls[0]] == "200 OK"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from click.testing import CliRunner
|
|
2
|
+
from pytest_mock import MockFixture
|
|
3
|
+
|
|
4
|
+
from simple_http_checker.cli import main
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_no_urls():
|
|
8
|
+
runner = CliRunner()
|
|
9
|
+
result = runner.invoke(main, [])
|
|
10
|
+
|
|
11
|
+
assert result.exit_code == 0
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_main_single_url(mocker: MockFixture):
|
|
15
|
+
url = "https://www.example.com"
|
|
16
|
+
|
|
17
|
+
mock_check = mocker.patch(
|
|
18
|
+
"simple_http_checker.cli.check_urls"
|
|
19
|
+
)
|
|
20
|
+
mock_check.return_value = {url: "200 OK"}
|
|
21
|
+
|
|
22
|
+
runner = CliRunner()
|
|
23
|
+
result = runner.invoke(main, [url])
|
|
24
|
+
|
|
25
|
+
assert result.exit_code == 0
|
|
26
|
+
mock_check.assert_called_once_with([url], 5)
|
|
27
|
+
assert url in result.output
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_main_timeout_option(mocker: MockFixture):
|
|
31
|
+
url = "https://www.timeout.com"
|
|
32
|
+
|
|
33
|
+
mock_check = mocker.patch(
|
|
34
|
+
"simple_http_checker.cli.check_urls"
|
|
35
|
+
)
|
|
36
|
+
mock_check.return_value = {url: "TIMEOUT"}
|
|
37
|
+
|
|
38
|
+
runner = CliRunner()
|
|
39
|
+
result = runner.invoke(main, [url, "--timeout", "10"])
|
|
40
|
+
|
|
41
|
+
assert result.exit_code == 0
|
|
42
|
+
mock_check.assert_called_once_with([url], 10)
|
|
43
|
+
|
|
44
|
+
assert url in result.output
|
|
45
|
+
assert "TIMEOUT" in result.output
|