2020-07-03 16:52:57 +00:00
|
|
|
# archivebox init
|
|
|
|
# archivebox add
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
import json
|
|
|
|
|
2020-07-23 15:06:43 +00:00
|
|
|
from archivebox.config import OUTPUT_PERMISSIONS
|
|
|
|
|
2020-07-07 13:36:58 +00:00
|
|
|
from .fixtures import *
|
2020-07-03 16:52:57 +00:00
|
|
|
|
|
|
|
def test_init(tmp_path, process):
|
|
|
|
assert "Initializing a new ArchiveBox collection in this folder..." in process.stdout.decode("utf-8")
|
|
|
|
|
|
|
|
def test_update(tmp_path, process):
|
|
|
|
os.chdir(tmp_path)
|
|
|
|
update_process = subprocess.run(['archivebox', 'init'], capture_output=True)
|
|
|
|
assert "Updating existing ArchiveBox collection in this folder" in update_process.stdout.decode("utf-8")
|
|
|
|
|
|
|
|
def test_add_link(tmp_path, process):
|
|
|
|
os.chdir(tmp_path)
|
2020-07-17 21:55:56 +00:00
|
|
|
add_process = subprocess.run(['archivebox', 'add', 'http://127.0.0.1:8080/static/example.com.html'], capture_output=True)
|
2020-07-03 16:52:57 +00:00
|
|
|
archived_item_path = list(tmp_path.glob('archive/**/*'))[0]
|
|
|
|
|
|
|
|
assert "index.json" in [x.name for x in archived_item_path.iterdir()]
|
|
|
|
|
|
|
|
with open(archived_item_path / "index.json", "r") as f:
|
|
|
|
output_json = json.load(f)
|
2020-07-07 16:53:02 +00:00
|
|
|
assert "Example Domain" == output_json['history']['title'][0]['output']
|
2020-07-03 16:52:57 +00:00
|
|
|
|
|
|
|
with open(tmp_path / "index.html", "r") as f:
|
|
|
|
output_html = f.read()
|
2020-07-07 16:53:02 +00:00
|
|
|
assert "Example Domain" in output_html
|
2020-07-03 16:52:57 +00:00
|
|
|
|
2020-07-07 20:46:45 +00:00
|
|
|
def test_add_link_support_stdin(tmp_path, process):
|
2020-07-07 17:39:36 +00:00
|
|
|
os.chdir(tmp_path)
|
|
|
|
stdin_process = subprocess.Popen(["archivebox", "add"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
2020-07-17 21:55:56 +00:00
|
|
|
stdin_process.communicate(input="http://127.0.0.1:8080/static/example.com.html".encode())
|
2020-07-07 20:46:45 +00:00
|
|
|
archived_item_path = list(tmp_path.glob('archive/**/*'))[0]
|
|
|
|
|
|
|
|
assert "index.json" in [x.name for x in archived_item_path.iterdir()]
|
|
|
|
|
|
|
|
with open(archived_item_path / "index.json", "r") as f:
|
|
|
|
output_json = json.load(f)
|
|
|
|
assert "Example Domain" == output_json['history']['title'][0]['output']
|
2020-07-07 17:39:36 +00:00
|
|
|
|
2020-07-23 15:06:43 +00:00
|
|
|
def test_correct_permissions_output_folder(tmp_path, process):
|
|
|
|
index_files = ['index.json', 'index.html', 'index.sqlite3', 'archive']
|
|
|
|
for file in index_files:
|
|
|
|
file_path = tmp_path / file
|
|
|
|
assert oct(file_path.stat().st_mode)[-3:] == OUTPUT_PERMISSIONS
|
|
|
|
|