-
Notifications
You must be signed in to change notification settings - Fork 109
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 8a3d805
Showing
5 changed files
with
75 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,33 @@ | ||
import logging | ||
|
||
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 credentials_dir.walk(top_down=False): | ||
for name in files: | ||
(root / name).unlink() | ||
logger.debug(f"Removed file {root / name}") | ||
for name in dirs: | ||
(root / name).rmdir() | ||
logger.debug(f"Removed directory {root / name}") | ||
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