CLI tool that tracks GitHub releases or tags from user-defined repositories and exposes them as a subscribable RSS 2.0 feed. Features: - Track releases or tags per repository - SQLite storage with automatic deduplication - RSS 2.0 feed with markdown-stripped release notes - Built-in HTTP server for local feed access - Rate-limit-aware GitHub API client - 64 passing tests
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
"""Tests for CLI commands."""
|
|
|
|
import sqlite3
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
from src.db import _create_tables, add_repo
|
|
|
|
|
|
class TestRepoFormatValidation:
|
|
def test_valid_format(self):
|
|
from src.cli import REPO_PATTERN
|
|
assert REPO_PATTERN.match("owner/repo")
|
|
assert REPO_PATTERN.match("my-org/my_repo")
|
|
assert REPO_PATTERN.match("a.b/c-d_e")
|
|
|
|
def test_invalid_format(self):
|
|
from src.cli import REPO_PATTERN
|
|
assert not REPO_PATTERN.match("owner")
|
|
assert not REPO_PATTERN.match("repo")
|
|
assert not REPO_PATTERN.match("owner/repo/extra")
|
|
|
|
|
|
class TestParseSince:
|
|
def test_hours(self):
|
|
from src.cli import parse_since
|
|
from datetime import timedelta
|
|
assert parse_since("24h") == timedelta(hours=24)
|
|
|
|
def test_days(self):
|
|
from src.cli import parse_since
|
|
from datetime import timedelta
|
|
assert parse_since("2d") == timedelta(days=2)
|
|
|
|
def test_minutes(self):
|
|
from src.cli import parse_since
|
|
from datetime import timedelta
|
|
assert parse_since("30m") == timedelta(minutes=30)
|
|
|
|
def test_invalid_defaults(self):
|
|
from src.cli import parse_since
|
|
from datetime import timedelta
|
|
assert parse_since("invalid") == timedelta(hours=24)
|
|
|
|
|
|
class TestCliHelp:
|
|
def test_help_flag(self):
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "src.cli", "--help"],
|
|
capture_output=True, text=True
|
|
)
|
|
assert result.returncode == 0
|
|
assert "ghrel" in result.stdout.lower() or "track" in result.stdout.lower()
|
|
|
|
def test_version_flag(self):
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "src.cli", "--version"],
|
|
capture_output=True, text=True
|
|
)
|
|
assert result.returncode == 0
|
|
assert "0.1.0" in result.stdout
|
|
|
|
|
|
class TestCliList:
|
|
def test_list_empty(self, tmp_path):
|
|
db_path = str(tmp_path / "test.db")
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "src.cli", "--db-path", db_path, "list"],
|
|
capture_output=True, text=True
|
|
)
|
|
assert result.returncode == 0
|
|
assert "No repositories" in result.stdout
|
|
|
|
|
|
class TestCliAddRemove:
|
|
def test_add_invalid_format(self, tmp_path):
|
|
db_path = str(tmp_path / "test.db")
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "src.cli", "--db-path", db_path, "add", "invalid"],
|
|
capture_output=True, text=True
|
|
)
|
|
assert result.returncode != 0
|
|
assert "Invalid repo format" in result.stderr
|