Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- fix: --log-level option [#194](https://github.com/icloud-photos-downloader/icloud_photos_downloader/pull/194)
- feature: Folder structure can be set to 'none' instead of a date pattern,
so all photos will be placed directly into the download directory.
- fix: Empty directory structure being created #185
Expand Down
5 changes: 2 additions & 3 deletions icloudpd/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
import logging
from logging import DEBUG, INFO
from logging import INFO


class IPDLogger(logging.Logger):
Expand Down Expand Up @@ -32,11 +32,10 @@ def tqdm_write(self, message, loglevel=INFO):
self.tqdm.write(message)


def setup_logger(loglevel=DEBUG):
def setup_logger():
"""Set up logger and add stdout handler"""
logging.setLoggerClass(IPDLogger)
logger = logging.getLogger("icloudpd")
logger.setLevel(loglevel)
has_stdout_handler = False
for handler in logger.handlers:
if handler.name == "stdoutLogger":
Expand Down
74 changes: 37 additions & 37 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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",
"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

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",
"jdoe@gmail.com",
"--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"):
Expand Down