1
0
Fork 0

fix after and before in remove tests

This commit is contained in:
Nick Sweeting 2021-02-18 06:21:44 -05:00
parent 9c07fbdc0b
commit 33df9c1ebe
2 changed files with 20 additions and 16 deletions

View file

@ -45,7 +45,7 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
group.add_argument(
'--json', #'-j',
action='store_true',
help="Print the output in JSON format with all columns included.",
help="Print the output in JSON format with all columns included",
)
group.add_argument(
'--html',
@ -60,19 +60,19 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
parser.add_argument(
'--sort', #'-s',
type=str,
help="List the links sorted using the given key, e.g. timestamp or updated.",
help="List the links sorted using the given key, e.g. timestamp or updated",
default=None,
)
parser.add_argument(
'--before', #'-b',
type=float,
help="List only links bookmarked before the given timestamp.",
help="List only links bookmarked before (less than) the given timestamp",
default=None,
)
parser.add_argument(
'--after', #'-a',
type=float,
help="List only links bookmarked after the given timestamp.",
help="List only links bookmarked after (greater than or equal to) the given timestamp",
default=None,
)
parser.add_argument(
@ -108,14 +108,14 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
nargs='*',
type=str,
default=None,
help='List only URLs matching these filter patterns.'
help='List only URLs matching these filter patterns'
)
command = parser.parse_args(args or ())
reject_stdin(stdin)
if command.with_headers and not (command.json or command.html or command.csv):
stderr(
'[X] --with-headers can only be used with --json, --html or --csv options.\n',
'[X] --with-headers can only be used with --json, --html or --csv options\n',
color='red',
)
raise SystemExit(2)

View file

@ -100,16 +100,18 @@ def test_remove_before(tmp_path, process, disable_extractors_dict):
conn = sqlite3.connect("index.sqlite3")
c = conn.cursor()
timestamp = c.execute("SELECT timestamp FROM core_snapshot ORDER BY timestamp DESC").fetchall()
higherts, lowerts = timestamp = c.execute("SELECT timestamp FROM core_snapshot ORDER BY timestamp DESC").fetchall()
conn.commit()
conn.close()
before = list(map(lambda x: int(x[0].split(".")[0]), timestamp))
lowerts = lowerts[0].split(".")[0]
higherts = higherts[0].split(".")[0]
subprocess.run(['archivebox', 'remove', '--filter-type=regex', '.*', '--yes', '--delete', '--before', str(before[1])], capture_output=True)
# before is less than, so only the lower snapshot gets deleted
subprocess.run(['archivebox', 'remove', '--filter-type=regex', '.*', '--yes', '--delete', '--before', higherts], capture_output=True)
assert (tmp_path / "archive" / timestamp[0][0]).exists()
assert not (tmp_path / "archive" / timestamp[1][0]).exists()
assert not (tmp_path / "archive" / lowerts).exists()
assert (tmp_path / "archive" / higherts).exists()
def test_remove_after(tmp_path, process, disable_extractors_dict):
subprocess.run(['archivebox', 'add', 'http://127.0.0.1:8080/static/example.com.html'], capture_output=True, env=disable_extractors_dict)
@ -118,13 +120,15 @@ def test_remove_after(tmp_path, process, disable_extractors_dict):
conn = sqlite3.connect("index.sqlite3")
c = conn.cursor()
timestamp = c.execute("SELECT timestamp FROM core_snapshot ORDER BY timestamp DESC").fetchall()
higherts, lowerts = c.execute("SELECT timestamp FROM core_snapshot ORDER BY timestamp DESC").fetchall()
conn.commit()
conn.close()
after = list(map(lambda x: int(x[0].split(".")[0]), timestamp))
lowerts = lowerts[0].split(".")[0]
higherts = higherts[0].split(".")[0]
subprocess.run(['archivebox', 'remove', '--filter-type=regex', '.*', '--yes', '--delete', '--after', str(after[1])], capture_output=True)
# after is greater than or equal to, so both snapshots get deleted
subprocess.run(['archivebox', 'remove', '--filter-type=regex', '.*', '--yes', '--delete', '--after', lowerts], capture_output=True)
assert (tmp_path / "archive" / timestamp[1][0]).exists()
assert not (tmp_path / "archive" / timestamp[0][0]).exists()
assert not (tmp_path / "archive" / lowerts).exists()
assert not (tmp_path / "archive" / higherts).exists()