-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from ltm/fix-log-level
Fix log-level option
- Loading branch information
Showing
3 changed files
with
40 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,18 @@ | |
import os | ||
import shutil | ||
from vcr import VCR | ||
import pytest | ||
from click.testing import CliRunner | ||
from icloudpd.base import main | ||
|
||
vcr = VCR(decode_compressed_response=True) | ||
|
||
|
||
class CliTestCase(TestCase): | ||
@pytest.fixture(autouse=True) | ||
def inject_fixtures(self, caplog): | ||
self._caplog = caplog | ||
|
||
def test_cli(self): | ||
runner = CliRunner() | ||
result = runner.invoke(main, ["--help"]) | ||
|
@@ -18,43 +23,38 @@ def test_cli(self): | |
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", | ||
"[email protected]", | ||
"--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", | ||
"[email protected]", | ||
"--password", | ||
"password1", | ||
"--recent", | ||
"0", | ||
"--log-level", | ||
"error", | ||
"-d", | ||
"tests/fixtures/Photos", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
parameters = [ | ||
("debug", ["DEBUG", "INFO"], []), | ||
("info", ["INFO"], ["DEBUG"]), | ||
("error", [], ["DEBUG", "INFO"]), | ||
] | ||
for log_level, expected, not_expected in parameters: | ||
self._caplog.clear() | ||
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", | ||
"[email protected]", | ||
"--password", | ||
"password1", | ||
"--recent", | ||
"0", | ||
"--log-level", | ||
log_level, | ||
"-d" | ||
"tests/fixtures/Photos", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
for text in expected: | ||
self.assertIn(text, self._caplog.text) | ||
for text in not_expected: | ||
self.assertNotIn(text, self._caplog.text) | ||
|
||
def test_tqdm(self): | ||
if not os.path.exists("tests/fixtures/Photos"): | ||
|