-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_database.py
67 lines (46 loc) · 1.71 KB
/
test_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
import pytest
from podcast_archiver.database import Database, DummyDatabase, get_database
if TYPE_CHECKING:
from pathlib import Path
from podcast_archiver.models.episode import Episode
def test_dummy(tmp_path_cd: Path, episode: Episode) -> None:
db = DummyDatabase("db.db", ignore_existing=False)
assert not (tmp_path_cd / "db.db").is_file()
assert not db.exists(episode)
db.add(episode)
assert not db.exists(episode)
db.add(episode)
assert not db.exists(episode)
def test_add(tmp_path_cd: Path, episode: Episode) -> None:
db = Database("db.db", ignore_existing=False)
assert (tmp_path_cd / "db.db").is_file()
assert not db.exists(episode)
db.add(episode)
assert db.exists(episode)
db.add(episode)
assert db.exists(episode)
def test_add_ignore_existing(tmp_path_cd: Path, episode: Episode) -> None:
db = Database("db.db", ignore_existing=True)
assert not db.exists(episode)
db.add(episode)
assert not db.exists(episode)
def test_migrate_idempotency(tmp_path_cd: Path) -> None:
db = Database("db.db", ignore_existing=False)
db.migrate()
db.migrate()
assert (tmp_path_cd / "db.db").is_file()
@pytest.mark.parametrize(
"input_path,expected_result_path",
[
(None, "podcast-archiver.db"),
(":memory:", ":memory:"),
],
)
def test_get_database(
tmp_path_cd: Path, input_path: Path | Literal[":memory:"] | None, expected_result_path: str
) -> None:
db = get_database(input_path)
assert db.filename == expected_result_path
assert (tmp_path_cd / "podcast-archiver.db").is_file() == (expected_result_path != ":memory:")