-
Notifications
You must be signed in to change notification settings - Fork 574
/
test_listing_libraries.py
90 lines (73 loc) · 3 KB
/
test_listing_libraries.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import inspect
import os
from unittest import TestCase
import pytest
from click.testing import CliRunner
from icloudpd.base import main
from vcr import VCR
from tests.helpers import path_from_project_root, print_result_exception, recreate_path
vcr = VCR(decode_compressed_response=True, record_mode="none")
class ListingLibraryTestCase(TestCase):
@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog: pytest.LogCaptureFixture) -> None:
self._caplog = caplog
self.root_path = path_from_project_root(__file__)
self.fixtures_path = os.path.join(self.root_path, "fixtures")
self.vcr_path = os.path.join(self.root_path, "vcr_cassettes")
def test_listing_library(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])
cookie_dir = os.path.join(base_dir, "cookie")
for dir in [base_dir, cookie_dir]:
recreate_path(dir)
with vcr.use_cassette(os.path.join(self.vcr_path, "listing_albums.yml")):
# Pass fixed client ID via environment variable
runner = CliRunner(env={"CLIENT_ID": "DE309E26-942E-11E8-92F5-14109FE0B321"})
result = runner.invoke(
main,
[
"--username",
"--password",
"password1",
"--list-libraries",
"--no-progress-bar",
"--cookie-directory",
cookie_dir,
],
)
print_result_exception(result)
albums = result.output.splitlines()
self.assertIn("PrimarySync", albums)
# self.assertIn("WhatsApp", albums)
assert result.exit_code == 0
def test_listing_library_error(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])
cookie_dir = os.path.join(base_dir, "cookie")
data_dir = os.path.join(base_dir, "data")
for dir in [base_dir, cookie_dir, data_dir]:
recreate_path(dir)
with vcr.use_cassette(os.path.join(self.vcr_path, "listing_albums.yml")):
# Pass fixed client ID via environment variable
runner = CliRunner(env={"CLIENT_ID": "DE309E26-942E-11E8-92F5-14109FE0B321"})
result = runner.invoke(
main,
[
"--username",
"--password",
"password1",
"--library",
"doesnotexist",
"--no-progress-bar",
"-d",
data_dir,
"--cookie-directory",
cookie_dir,
],
)
print_result_exception(result)
self.assertIn(
"ERROR Unknown library: doesnotexist",
self._caplog.text,
)
assert result.exit_code == 1