diff --git a/tests/test_cli.py b/tests/test_cli.py index 7704dc1..b971adb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,8 @@ import sys import os import pytest +import random +import string import argparse sys.path.append("..") @@ -8,9 +10,6 @@ import waybackpy.cli as cli # noqa: E402 from waybackpy.wrapper import Url # noqa: E402 from waybackpy.__version__ import __version__ -# 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) - def test_save(): args = argparse.Namespace( @@ -32,6 +31,25 @@ def test_save(): reply = cli.args_handler(args) assert "pypi.org/user/akamhy" in str(reply) + args = argparse.Namespace( + user_agent=None, + url="https://hfjfjfjfyu6r6rfjvj.fjhgjhfjgvjm", + total=False, + version=False, + oldest=False, + save=True, + json=False, + archive_url=False, + newest=False, + near=False, + alive=False, + subdomain=False, + known_urls=False, + get=None, + ) + reply = cli.args_handler(args) + assert "could happen because either your waybackpy" in str(reply) + def test_json(): args = argparse.Namespace( @@ -95,6 +113,29 @@ def test_oldest(): reply = cli.args_handler(args) assert "pypi.org/user/akamhy" in str(reply) + uid = "".join( + random.choice(string.ascii_lowercase + string.digits) for _ in range(6) + ) + url = "https://pypi.org/yfvjvycyc667r67ed67r" + uid + args = argparse.Namespace( + user_agent=None, + url=url, + total=False, + version=False, + oldest=True, + save=False, + json=False, + archive_url=False, + newest=False, + near=False, + alive=False, + subdomain=False, + known_urls=False, + get=None, + ) + reply = cli.args_handler(args) + assert "Can not find archive for" in str(reply) + def test_newest(): args = argparse.Namespace( @@ -117,6 +158,29 @@ def test_newest(): reply = cli.args_handler(args) assert "pypi.org/user/akamhy" in str(reply) + uid = "".join( + random.choice(string.ascii_lowercase + string.digits) for _ in range(6) + ) + url = "https://pypi.org/yfvjvycyc667r67ed67r" + uid + args = argparse.Namespace( + user_agent=None, + url=url, + total=False, + version=False, + oldest=False, + save=False, + json=False, + archive_url=False, + newest=True, + near=False, + alive=False, + subdomain=False, + known_urls=False, + get=None, + ) + reply = cli.args_handler(args) + assert "Can not find archive for" in str(reply) + def test_total_archives(): args = argparse.Namespace( @@ -161,6 +225,26 @@ def test_known_urls(): reply = cli.args_handler(args) assert "github" in str(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://akfyfufyjcujfufu6576r76r6amhy.gitd6r67r6u6hub.yfjyfjio", + total=False, + version=False, + oldest=False, + save=False, + json=False, + archive_url=False, + newest=False, + near=False, + alive=True, + subdomain=True, + known_urls=True, + get=None, + ) + reply = cli.args_handler(args) + assert "No known URLs found" in str(reply) + def test_near(): args = argparse.Namespace( @@ -188,6 +272,34 @@ def test_near(): reply = cli.args_handler(args) assert "202007" in str(reply) + uid = "".join( + random.choice(string.ascii_lowercase + string.digits) for _ in range(6) + ) + url = "https://pypi.org/yfvjvycyc667r67ed67r" + uid + args = argparse.Namespace( + user_agent=None, + url=url, + total=False, + version=False, + oldest=False, + save=False, + json=False, + archive_url=False, + newest=False, + near=True, + alive=False, + subdomain=False, + known_urls=False, + get=None, + year=2020, + month=7, + day=15, + hour=1, + minute=1, + ) + reply = cli.args_handler(args) + assert "Can not find archive for" in str(reply) + def test_get(): args = argparse.Namespace( diff --git a/waybackpy/cli.py b/waybackpy/cli.py index fb7c857..67206e4 100644 --- a/waybackpy/cli.py +++ b/waybackpy/cli.py @@ -305,8 +305,7 @@ def parse_args(argv): def main(argv=None): - if argv is None: - argv = sys.argv + argv = sys.argv if argv is None else argv print(args_handler(parse_args(argv))) diff --git a/waybackpy/wrapper.py b/waybackpy/wrapper.py index 3ac4042..a2087b7 100644 --- a/waybackpy/wrapper.py +++ b/waybackpy/wrapper.py @@ -57,7 +57,7 @@ def _archive_url_parser(header, url): "If '%s' can be accessed via your web browser then either " "this version of waybackpy (%s) is out of date or WayBack Machine is malfunctioning. Visit " "'https://github.com/akamhy/waybackpy' for the latest version " - "of waybackpy.\nHeader:\n%s" % (__version__, str(header)) + "of waybackpy.\nHeader:\n%s" % (url, __version__, str(header)) )