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:
parent
cd8a32ed1f
commit
d1a1cf2546
13
tests/test_utils.py
Normal file
13
tests/test_utils.py
Normal 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")
|
@ -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"]
|
||||||
|
Loading…
Reference in New Issue
Block a user