2020-05-05 12:59:55 +02:00
|
|
|
import sys
|
|
|
|
import pytest
|
2020-07-18 13:09:35 +02:00
|
|
|
import random
|
2020-12-13 10:35:57 +01:00
|
|
|
import requests
|
2021-01-03 20:14:55 +01:00
|
|
|
from datetime import datetime
|
2020-12-13 20:48:04 +01:00
|
|
|
|
2021-01-23 16:38:21 +01:00
|
|
|
from waybackpy.wrapper import Url
|
2020-11-21 12:30:11 +01:00
|
|
|
|
2020-05-05 12:59:55 +02:00
|
|
|
|
|
|
|
user_agent = "Mozilla/5.0 (Windows NT 6.2; rv:20.0) Gecko/20121202 Firefox/20.0"
|
|
|
|
|
2020-07-22 06:39:14 +02:00
|
|
|
|
2021-01-02 14:22:46 +01:00
|
|
|
def test_url_check():
|
|
|
|
"""No API Use"""
|
|
|
|
broken_url = "http://wwwgooglecom/"
|
|
|
|
with pytest.raises(Exception):
|
2021-01-09 21:53:53 +01:00
|
|
|
Url(broken_url, user_agent)
|
2020-05-05 12:59:55 +02:00
|
|
|
|
2020-07-22 06:39:14 +02:00
|
|
|
|
2020-05-05 12:59:55 +02:00
|
|
|
def test_save():
|
2020-07-18 13:09:35 +02:00
|
|
|
|
|
|
|
url_list = [
|
|
|
|
"en.wikipedia.org",
|
2021-01-09 21:53:53 +01:00
|
|
|
"akamhy.github.io",
|
2020-07-18 13:09:35 +02:00
|
|
|
"www.wiktionary.org",
|
|
|
|
"www.w3schools.com",
|
2021-01-09 21:53:53 +01:00
|
|
|
"youtube.com",
|
2020-07-18 13:09:35 +02:00
|
|
|
]
|
2020-07-22 06:39:14 +02:00
|
|
|
x = random.randint(0, len(url_list) - 1)
|
2020-07-18 13:28:23 +02:00
|
|
|
url1 = url_list[x]
|
2021-01-09 21:53:53 +01:00
|
|
|
target = Url(
|
2020-07-22 06:39:14 +02:00
|
|
|
url1,
|
|
|
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 "
|
|
|
|
"(KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36",
|
|
|
|
)
|
2020-10-16 15:55:45 +02:00
|
|
|
archived_url1 = str(target.save())
|
2020-05-05 12:59:55 +02:00
|
|
|
assert url1 in archived_url1
|
2020-07-17 17:20:00 +02:00
|
|
|
|
2020-07-22 06:39:14 +02:00
|
|
|
|
2020-05-05 12:59:55 +02:00
|
|
|
def test_near():
|
2020-11-21 12:30:11 +01:00
|
|
|
with pytest.raises(Exception):
|
|
|
|
NeverArchivedUrl = (
|
|
|
|
"https://ee_3n.wrihkeipef4edia.org/rwti5r_ki/Nertr6w_rork_rse7c_urity"
|
2020-07-22 06:39:14 +02:00
|
|
|
)
|
2021-01-09 21:53:53 +01:00
|
|
|
target = Url(NeverArchivedUrl, user_agent)
|
2020-11-21 12:30:11 +01:00
|
|
|
target.near(year=2010)
|
2020-07-22 06:39:14 +02:00
|
|
|
|
2020-05-07 05:29:09 +02:00
|
|
|
|
2020-10-16 15:55:45 +02:00
|
|
|
def test_json():
|
|
|
|
url = "github.com/akamhy/waybackpy"
|
2021-01-09 21:53:53 +01:00
|
|
|
target = Url(url, user_agent)
|
2020-10-16 15:55:45 +02:00
|
|
|
assert "archived_snapshots" in str(target.JSON)
|