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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bejw
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: A capped reading list for links that shimmer
5
5
  Author: menisadi
6
6
  License: MIT License
@@ -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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bejw
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: A capped reading list for links that shimmer
5
5
  Author: menisadi
6
6
  License: MIT License
@@ -13,5 +13,6 @@ bejw.egg-info/entry_points.txt
13
13
  bejw.egg-info/requires.txt
14
14
  bejw.egg-info/top_level.txt
15
15
  tests/test_cli_list_formats.py
16
+ tests/test_cli_read.py
16
17
  tests/test_models.py
17
18
  tests/test_storage.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "bejw"
7
- version = "0.2.3"
7
+ version = "0.2.4"
8
8
  description = "A capped reading list for links that shimmer"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13"
@@ -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