improved tests
This commit is contained in:
@@ -7,37 +7,91 @@ import argparse
|
|||||||
sys.path.append("..")
|
sys.path.append("..")
|
||||||
import waybackpy.cli as cli # noqa: E402
|
import waybackpy.cli as cli # noqa: E402
|
||||||
from waybackpy.wrapper import Url # noqa: E402
|
from waybackpy.wrapper import Url # noqa: E402
|
||||||
|
from waybackpy.__version__ import __version__
|
||||||
|
|
||||||
|
codecov_python = False
|
||||||
if sys.version_info > (3, 7):
|
if sys.version_info > (3, 7):
|
||||||
|
codecov_python = True
|
||||||
|
|
||||||
|
# Namespace(day=None, get=None, hour=None, minute=None, month=None, near=False,
|
||||||
|
# newest=False, oldest=False, save=False, total=False, url=None, user_agent=None, version=False, year=None)
|
||||||
|
|
||||||
|
if codecov_python:
|
||||||
def test_save():
|
def test_save():
|
||||||
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
|
args = argparse.Namespace(user_agent=None, url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
cli._save(obj)
|
oldest=False, save=True, newest=False, near=False, get=None)
|
||||||
else:
|
reply = cli.args_handler(args)
|
||||||
pass
|
assert "pypi.org/user/akamhy" in reply
|
||||||
|
|
||||||
def test_get():
|
|
||||||
args = argparse.Namespace(get='oldest')
|
|
||||||
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
|
|
||||||
cli._get(obj, args)
|
|
||||||
args = argparse.Namespace(get='newest')
|
|
||||||
cli._get(obj, args)
|
|
||||||
args = argparse.Namespace(get='url')
|
|
||||||
cli._get(obj, args)
|
|
||||||
if sys.version_info > (3, 7):
|
|
||||||
args = argparse.Namespace(get='save')
|
|
||||||
cli._get(obj, args)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_oldest():
|
def test_oldest():
|
||||||
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
|
args = argparse.Namespace(user_agent=None, url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
cli._oldest(obj)
|
oldest=True, save=False, newest=False, near=False, get=None)
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "pypi.org/user/akamhy" in reply
|
||||||
|
|
||||||
def test_newest():
|
def test_newest():
|
||||||
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
cli._newest(obj)
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
|
oldest=False, save=False, newest=True, near=False, get=None)
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "pypi.org/user/akamhy" in reply
|
||||||
|
|
||||||
|
def test_total_archives():
|
||||||
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=True, version=False,
|
||||||
|
oldest=False, save=False, newest=False, near=False, get=None)
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert type(reply) is int
|
||||||
|
|
||||||
def test_near():
|
def test_near():
|
||||||
args = argparse.Namespace(year=2020, month=6, day=1, hour=1, minute=1)
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
obj = Url("https://pypi.org/user/akamhy/", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 (KHTML, like Gecko) Version/8.0.8 Safari/600.8.9")
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
cli._near(obj, args)
|
oldest=False, save=False, newest=False, near=True, get=None, year=2020, month=7, day=15, hour=1, minute=1)
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "202007" in reply
|
||||||
|
|
||||||
|
|
||||||
|
def test_get():
|
||||||
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
|
oldest=False, save=False, newest=False, near=False, get="url")
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "waybackpy" in reply
|
||||||
|
|
||||||
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
|
oldest=False, save=False, newest=False, near=False, get="oldest")
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "waybackpy" in reply
|
||||||
|
|
||||||
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
|
oldest=False, save=False, newest=False, near=False, get="newest")
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "waybackpy" in reply
|
||||||
|
|
||||||
|
if codecov_python:
|
||||||
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
|
oldest=False, save=False, newest=False, near=False, get="save")
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "waybackpy" in reply
|
||||||
|
|
||||||
|
args = argparse.Namespace(user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/600.8.9 \
|
||||||
|
(KHTML, like Gecko) Version/8.0.8 Safari/600.8.9", url="https://pypi.org/user/akamhy/", total=False, version=False,
|
||||||
|
oldest=False, save=False, newest=False, near=False, get="BullShit")
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "get the source code of the" in reply
|
||||||
|
|
||||||
|
def test_args_handler():
|
||||||
|
args = argparse.Namespace(version=True)
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert __version__ == reply
|
||||||
|
|
||||||
|
args = argparse.Namespace(url=None, version=False)
|
||||||
|
reply = cli.args_handler(args)
|
||||||
|
assert "Specify an URL" in reply
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
# This also tests the parse_args method in cli.py
|
||||||
|
cli.main(['temp.py', '--version'])
|
||||||
|
Reference in New Issue
Block a user