bejw 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bejw-0.2.3 → bejw-0.2.4}/PKG-INFO +1 -1
- {bejw-0.2.3 → bejw-0.2.4}/bejw/main.py +15 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw.egg-info/PKG-INFO +1 -1
- {bejw-0.2.3 → bejw-0.2.4}/bejw.egg-info/SOURCES.txt +1 -0
- {bejw-0.2.3 → bejw-0.2.4}/pyproject.toml +1 -1
- bejw-0.2.4/tests/test_cli_read.py +72 -0
- {bejw-0.2.3 → bejw-0.2.4}/LICENSE +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/README.md +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw/__init__.py +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw/models.py +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw/render.py +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw/storage.py +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw.egg-info/dependency_links.txt +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw.egg-info/entry_points.txt +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw.egg-info/requires.txt +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/bejw.egg-info/top_level.txt +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/setup.cfg +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/tests/test_cli_list_formats.py +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/tests/test_models.py +0 -0
- {bejw-0.2.3 → bejw-0.2.4}/tests/test_storage.py +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
bejw: A capped reading list for links that shimmer
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
import webbrowser
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
|
|
7
8
|
import typer
|
|
@@ -69,6 +70,20 @@ def remove(number: int, file_path: str = DEFAULT_FILE_PATH) -> None:
|
|
|
69
70
|
raise typer.Exit(code=1)
|
|
70
71
|
|
|
71
72
|
|
|
73
|
+
@app.command()
|
|
74
|
+
def read(number: int, file_path: str = DEFAULT_FILE_PATH) -> None:
|
|
75
|
+
"""Open a link from the reading list by number."""
|
|
76
|
+
reading_list = load(file_path)
|
|
77
|
+
ordered = reading_list.ordered_links()
|
|
78
|
+
if number < 1 or number > len(ordered):
|
|
79
|
+
typer.echo("No link found with that number.")
|
|
80
|
+
raise typer.Exit(code=1)
|
|
81
|
+
|
|
82
|
+
url = ordered[number - 1].url
|
|
83
|
+
webbrowser.open(url)
|
|
84
|
+
typer.echo(f"Opened #{number}: {url}")
|
|
85
|
+
|
|
86
|
+
|
|
72
87
|
@app.command()
|
|
73
88
|
def list(
|
|
74
89
|
file_path: str = DEFAULT_FILE_PATH,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import webbrowser
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from typer.testing import CliRunner
|
|
5
|
+
|
|
6
|
+
from bejw.main import app
|
|
7
|
+
from bejw.models import Link, ReadingList
|
|
8
|
+
from bejw.storage import save
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
runner = CliRunner()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _seed_reading_list(file_path: Path) -> None:
|
|
15
|
+
reading_list = ReadingList(
|
|
16
|
+
capacity=10,
|
|
17
|
+
links=[
|
|
18
|
+
Link(
|
|
19
|
+
id="id-1",
|
|
20
|
+
title="Example One",
|
|
21
|
+
url="https://example.com/1",
|
|
22
|
+
created_at="2024-01-01T00:00:00+00:00",
|
|
23
|
+
),
|
|
24
|
+
Link(
|
|
25
|
+
id="id-2",
|
|
26
|
+
title="Example Two",
|
|
27
|
+
url="https://example.com/2",
|
|
28
|
+
created_at="2024-01-02T00:00:00+00:00",
|
|
29
|
+
),
|
|
30
|
+
],
|
|
31
|
+
)
|
|
32
|
+
save(reading_list, str(file_path))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_read_opens_selected_link_and_prints_confirmation(
|
|
36
|
+
tmp_path: Path, monkeypatch
|
|
37
|
+
) -> None:
|
|
38
|
+
file_path = tmp_path / "links.json"
|
|
39
|
+
_seed_reading_list(file_path)
|
|
40
|
+
opened: list[str] = []
|
|
41
|
+
|
|
42
|
+
def _fake_open(url: str, *_args, **_kwargs) -> bool:
|
|
43
|
+
opened.append(url)
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
monkeypatch.setattr(webbrowser, "open", _fake_open)
|
|
47
|
+
|
|
48
|
+
result = runner.invoke(app, ["read", "2", "--file-path", str(file_path)])
|
|
49
|
+
|
|
50
|
+
assert result.exit_code == 0
|
|
51
|
+
assert opened == ["https://example.com/2"]
|
|
52
|
+
assert result.stdout == "Opened #2: https://example.com/2\n"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_read_returns_error_when_number_is_missing(tmp_path: Path) -> None:
|
|
56
|
+
file_path = tmp_path / "links.json"
|
|
57
|
+
_seed_reading_list(file_path)
|
|
58
|
+
|
|
59
|
+
result = runner.invoke(app, ["read", "99", "--file-path", str(file_path)])
|
|
60
|
+
|
|
61
|
+
assert result.exit_code == 1
|
|
62
|
+
assert result.stdout == "No link found with that number.\n"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_read_returns_error_for_empty_list(tmp_path: Path) -> None:
|
|
66
|
+
file_path = tmp_path / "links.json"
|
|
67
|
+
save(ReadingList(capacity=10), str(file_path))
|
|
68
|
+
|
|
69
|
+
result = runner.invoke(app, ["read", "1", "--file-path", str(file_path)])
|
|
70
|
+
|
|
71
|
+
assert result.exit_code == 1
|
|
72
|
+
assert result.stdout == "No link found with that number.\n"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|