added tests for utils.py at tests/test_utils.py also changed a keyword argument from headers to user_agent for latest_version of utils.py with the usual default vaule.

This commit is contained in:
Akash Mahanty 2022-01-24 17:50:36 +05:30
parent cd8a32ed1f
commit d1a1cf2546
2 changed files with 15 additions and 1 deletions

13
tests/test_utils.py Normal file
View File

@ -0,0 +1,13 @@
from waybackpy.utils import latest_version, DEFAULT_USER_AGENT
from waybackpy.__version__ import __version__
def test_default_user_agent():
assert (
DEFAULT_USER_AGENT
== "waybackpy %s - https://github.com/akamhy/waybackpy" % __version__
)
def test_latest_version():
assert __version__ == latest_version(package_name="waybackpy")

View File

@ -4,8 +4,9 @@ from .__version__ import __version__
DEFAULT_USER_AGENT = "waybackpy %s - https://github.com/akamhy/waybackpy" % __version__ DEFAULT_USER_AGENT = "waybackpy %s - https://github.com/akamhy/waybackpy" % __version__
def latest_version(package_name, headers): def latest_version(package_name, user_agent=DEFAULT_USER_AGENT):
request_url = "https://pypi.org/pypi/" + package_name + "/json" request_url = "https://pypi.org/pypi/" + package_name + "/json"
headers = {"User-Agent": user_agent}
response = requests.get(request_url, headers=headers) response = requests.get(request_url, headers=headers)
data = response.json() data = response.json()
return data["info"]["version"] return data["info"]["version"]