-
Notifications
You must be signed in to change notification settings - Fork 520
/
test_cli.py
102 lines (96 loc) · 3.26 KB
/
test_cli.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
91
92
93
94
95
96
97
98
99
100
101
102
# coding=utf-8
from unittest import TestCase
from vcr import VCR
import os
import click
from click.testing import CliRunner
from icloudpd.base import main
vcr = VCR(decode_compressed_response=True)
class CliTestCase(TestCase):
def test_cli(self):
runner = CliRunner()
result = runner.invoke(main, ["--help"])
assert result.exit_code == 0
def test_log_levels(self):
if not os.path.exists("tests/fixtures/Photos"):
os.makedirs("tests/fixtures/Photos")
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
# Pass fixed client ID via environment variable
os.environ["CLIENT_ID"] = "DE309E26-942E-11E8-92F5-14109FE0B321"
runner = CliRunner()
result = runner.invoke(
main,
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--recent",
"0",
"--log-level",
"info",
"-d"
"tests/fixtures/Photos",
],
)
assert result.exit_code == 0
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
result = runner.invoke(
main,
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--recent",
"0",
"--log-level",
"error",
"-d",
"tests/fixtures/Photos",
],
)
assert result.exit_code == 0
def test_tqdm(self):
if not os.path.exists("tests/fixtures/Photos"):
os.makedirs("tests/fixtures/Photos")
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
# Force tqdm progress bar via ENV var
os.environ["FORCE_TQDM"] = "yes"
runner = CliRunner()
result = runner.invoke(
main,
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--recent",
"0",
"-d",
"tests/fixtures/Photos",
],
)
del os.environ["FORCE_TQDM"]
assert result.exit_code == 0
def test_unicode_directory(self):
with vcr.use_cassette("tests/vcr_cassettes/listing_photos.yml"):
# Pass fixed client ID via environment variable
os.environ["CLIENT_ID"] = "DE309E26-942E-11E8-92F5-14109FE0B321"
runner = CliRunner()
result = runner.invoke(
main,
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--recent",
"0",
"--log-level",
"info",
"-d",
"tests/fixtures/相片",
],
)
assert result.exit_code == 0