remove latest version funcs from utils, they were unused.
This commit is contained in:
parent
5954fcc646
commit
87fb5ecd58
@ -1,9 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from waybackpy import __version__
|
||||
from waybackpy.utils import (
|
||||
DEFAULT_USER_AGENT,
|
||||
latest_version_github,
|
||||
latest_version_pypi,
|
||||
)
|
||||
from waybackpy.utils import DEFAULT_USER_AGENT
|
||||
|
||||
|
||||
def test_default_user_agent() -> None:
|
||||
@ -11,8 +9,3 @@ def test_default_user_agent() -> None:
|
||||
DEFAULT_USER_AGENT
|
||||
== f"waybackpy {__version__} - https://github.com/akamhy/waybackpy"
|
||||
)
|
||||
|
||||
|
||||
def test_latest_version() -> None:
|
||||
package_name = "waybackpy"
|
||||
assert latest_version_github(package_name) == latest_version_pypi(package_name)
|
||||
|
@ -9,42 +9,3 @@ from . import __version__
|
||||
DEFAULT_USER_AGENT: str = (
|
||||
f"waybackpy {__version__} - https://github.com/akamhy/waybackpy"
|
||||
)
|
||||
|
||||
|
||||
def latest_version_pypi(package_name: str, user_agent: str = DEFAULT_USER_AGENT) -> str:
|
||||
"""Latest waybackpy version on PyPi."""
|
||||
request_url = "https://pypi.org/pypi/" + package_name + "/json"
|
||||
headers = {"User-Agent": user_agent}
|
||||
response = requests.get(request_url, headers=headers)
|
||||
data = response.json()
|
||||
if (
|
||||
data is not None
|
||||
and "info" in data
|
||||
and data["info"] is not None
|
||||
and "version" in data["info"]
|
||||
and data["info"]["version"] is not None
|
||||
):
|
||||
return str(data["info"]["version"])
|
||||
|
||||
raise ValueError("Could not get latest pypi version")
|
||||
|
||||
|
||||
def latest_version_github(
|
||||
package_name: str, user_agent: str = DEFAULT_USER_AGENT
|
||||
) -> str:
|
||||
"""Latest waybackpy version on GitHub."""
|
||||
request_url = (
|
||||
"https://api.github.com/repos/akamhy/" + package_name + "/releases?per_page=1"
|
||||
)
|
||||
headers = {"User-Agent": user_agent}
|
||||
response = requests.get(request_url, headers=headers)
|
||||
data = response.json()
|
||||
if (
|
||||
data is not None
|
||||
and len(data) > 0
|
||||
and data[0] is not None
|
||||
and "tag_name" in data[0]
|
||||
):
|
||||
return str(data[0]["tag_name"])
|
||||
|
||||
raise ValueError("Could not get latest github version")
|
||||
|
Loading…
Reference in New Issue
Block a user