-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logout command to remove cached credentials
- Loading branch information
1 parent
f615bfa
commit 72c0f69
Showing
5 changed files
with
80 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
||
from mopidy import commands | ||
|
||
from mopidy_spotify import Extension | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SpotifyCommand(commands.Command): | ||
def __init__(self): | ||
super().__init__() | ||
self.add_child("logout", LogoutCommand()) | ||
|
||
|
||
class LogoutCommand(commands.Command): | ||
help = "Logout from Spotify account." | ||
|
||
def run(self, _args, config): | ||
credentials_dir = Extension().get_credentials_dir(config) | ||
try: | ||
for root, dirs, files in os.walk(credentials_dir, topdown=False): | ||
root_path = Path(root) | ||
for name in files: | ||
file_path = root_path / name | ||
file_path.unlink() | ||
logger.debug(f"Removed file {file_path}") | ||
for name in dirs: | ||
dir_path = root_path / name | ||
dir_path.rmdir() | ||
logger.debug(f"Removed directory {dir_path}") | ||
credentials_dir.rmdir() | ||
except Exception as error: | ||
logger.warning(f"Failed to logout from Spotify: {error}") | ||
else: | ||
logger.info("Logout from Spotify complete") |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from unittest.mock import sentinel | ||
|
||
from mopidy_spotify import Extension | ||
from mopidy_spotify.commands import LogoutCommand | ||
|
||
|
||
def test_logout_command(tmp_path): | ||
config = {"core": {"data_dir": tmp_path}} | ||
credentials_dir = Extension().get_credentials_dir(config) | ||
(credentials_dir / "foo").mkdir() | ||
(credentials_dir / "bar").touch() | ||
|
||
cmd = LogoutCommand() | ||
cmd.run(sentinel.args, config) | ||
|
||
assert not credentials_dir.is_dir() |
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