Skip to content

Commit

Permalink
Merge pull request #160 from marksie1988/157-renamefiles-fix
Browse files Browse the repository at this point in the history
chore: post_command tests not working correctly & missing documentation
  • Loading branch information
marksie1988 authored Jul 26, 2023
2 parents b56bb63 + bf3688a commit 8f7b030
Show file tree
Hide file tree
Showing 13 changed files with 470 additions and 182 deletions.
1 change: 1 addition & 0 deletions pyarr/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from logging import Logger, getLogger

LOGGER: Logger = getLogger(__package__)
DEPRECATION_WARNING = "This method is deprecated and will be removed in v6.0.0."
15 changes: 13 additions & 2 deletions pyarr/lidarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,27 @@ def delete_album(self, id_: int) -> Union[Response, JsonObject, dict[Any, Any]]:
return self._delete(f"album/{id_}", self.ver_uri)

# POST /command
def post_command(self, name: LidarrCommand) -> JsonObject:
def post_command(
self, name: LidarrCommand, **kwargs: Optional[dict[str, Union[int, list[int]]]]
) -> JsonObject:
"""Send a command to Lidarr
Args:
name (LidarrCommand): Command to be run against Lidarr
**kwargs: Additional parameters for specific commands.
Note:
For available commands and required `**kwargs` see the `LidarrCommands` model
Returns:
JsonObject: dictionary of executed command information
"""
return self._post("command", self.ver_uri, data={"name": name})
data: dict[str, Any] = {
"name": name,
}
if kwargs:
data |= kwargs
return self._post("command", self.ver_uri, data=data)

# GET /wanted
def get_wanted(
Expand Down
46 changes: 45 additions & 1 deletion pyarr/models/lidarr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Literal

#: Lidarr commands.
LidarrCommand = Literal[
"AlbumSearch",
"ApplicationUpdateCheck",
Expand All @@ -10,7 +9,52 @@
"RefreshAlbum",
"RefreshArtist",
]
"""
Lidarr commands.
Note:
The parameters are supplied as `**kwargs` within the `post_command` method.
DownloadedAlbumsScan:
Scans downloaded albums for state
Args:
path (str): path to files
ArtistSearch:
searches specified artist
Args:
artistId (int): ID of artist
RefreshArtist:
Refreshes all of the artists, or specific by ID
Args:
artistId (int, Optional): ID of Album
RefreshAlbum:
Refreshes all of the albums, or specific by ID
Args:
albumId (int, Optional): ID of Album
ApplicationUpdateCheck:
Checks for Application updates
MissingAlbumSearch:
Search for any missing albums
AlbumSearch:
Search for albums
RssSync:
Synchronise RSS Feeds
Backup:
Backup the server data
"""

#: Lidarr sort keys.
LidarrSortKey = Literal[
Expand Down
19 changes: 12 additions & 7 deletions pyarr/models/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
The parameters are supplied as `**kwargs` within the `post_command` method.
DownloadedMoviesScan:
Scans for all clients for downloaded movies, or a single client by ID
Scans downloaded episodes for state
Args:
clientid (int, optional): Download client ID
path (str): path to files
MissingMoviesSearch:
Searches for any missing movies
Expand All @@ -30,29 +30,34 @@
Args:
movieIds (list[int]): ID of Movie or movies
RefreshMovies:
RefreshMovie:
Refreshes all of the movies, or specific by ID
Args:
movieid (int, Optional): ID of Movie
movieId (int, Optional): ID of Movie
RenameMovie:
Rename specific movie to correct format.
Args:
movieid (list[int]): ID of Movie or movies
movieId (int): ID of Movie or movies
movieIds (list[int]): ID of Movie or movies
RescanMovie:
Rescans specific movie
Args:
movieid (int): ID of Movie
movieId (int): ID of Movie
RenameFiles:
Rename files to correct format
Args:
movieid (int): ID of Movie
movieId (int): ID of Movie
files (int): ID of files
RssSync:
Synchronise RSS Feeds
Backup:
Backup the server data
Expand Down
2 changes: 2 additions & 0 deletions pyarr/models/readarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
Args:
authorId (int, optional): ID for Author
files (str): ID of files
RescanFolders:
Rescans folders
RssSync:
Synchronise RSS Feeds
Backup:
Backup of the Database
Expand Down
4 changes: 4 additions & 0 deletions pyarr/models/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
DownloadedEpisodesScan:
Scans downloaded episodes for state
Args:
path (str): path to files
EpisodeSearch:
Searches for all episondes, or specific ones in supplied list
Expand All @@ -49,6 +52,7 @@
Renames files to the expected naming format.
Args:
seriesId (int, optional): ID of series files relate to
files (list[int]): List of File IDs to rename.
RescanSeries:
Expand Down
9 changes: 5 additions & 4 deletions pyarr/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from requests import Response

from pyarr.const import DEPRECATION_WARNING
from pyarr.types import JsonArray, JsonObject

from .base import BaseArrAPI
Expand Down Expand Up @@ -159,7 +160,7 @@ def get_movie_by_movie_id(self, id_: int) -> JsonObject:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_movie()",
f"{DEPRECATION_WARNING} Please use get_movie()",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -226,7 +227,7 @@ def lookup_movie_by_tmdb_id(self, id_: int) -> JsonArray:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. use lookup_movie(term='tmdb:123456')",
f"{DEPRECATION_WARNING} use lookup_movie(term='tmdb:123456')",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -244,7 +245,7 @@ def lookup_movie_by_imdb_id(self, id_: str) -> JsonArray:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. use lookup_movie(term='imdb:123456')",
f"{DEPRECATION_WARNING} use lookup_movie(term='imdb:123456')",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -291,7 +292,7 @@ def del_movies(
Response: HTTP Response
"""
warn(
"This method is deprecated and will be removed in a future release. Please use del_movie().",
f"{DEPRECATION_WARNING} Please use del_movie().",
DeprecationWarning,
stacklevel=2,
)
Expand Down
15 changes: 8 additions & 7 deletions pyarr/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from requests import Response

from pyarr.const import DEPRECATION_WARNING
from pyarr.exceptions import PyarrMissingArgument
from pyarr.types import JsonArray, JsonObject

Expand Down Expand Up @@ -102,7 +103,7 @@ def get_episodes_by_series_id(self, id_: int) -> JsonArray:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_episode()",
f"{DEPRECATION_WARNING} Please use get_episode()",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -124,7 +125,7 @@ def get_episode_by_episode_id(self, id_: int) -> JsonObject:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_episode()",
f"{DEPRECATION_WARNING} Please use get_episode()",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -181,7 +182,7 @@ def get_episode_files_by_series_id(self, id_: int) -> JsonArray:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_episode_file()",
f"{DEPRECATION_WARNING} Please use get_episode_file()",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -368,7 +369,7 @@ def get_parsed_title(self, title: str) -> JsonObject:
JsonObject: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_parse_title_path()",
f"{DEPRECATION_WARNING} Please use get_parse_title_path()",
DeprecationWarning,
stacklevel=2,
)
Expand All @@ -388,7 +389,7 @@ def get_parsed_path(self, file_path: str) -> JsonObject:
JsonObject: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_parse_title_path()",
f"{DEPRECATION_WARNING} Please use get_parse_title_path()",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -581,7 +582,7 @@ def lookup_series_by_tvdb_id(self, id_: int) -> JsonArray:
JsonArray: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use lookup_series()",
f"{DEPRECATION_WARNING} Please use lookup_series()",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -649,7 +650,7 @@ def get_language_profile(
Union[JsonArray, dict[Any, Any]]: List of dictionaries with items
"""
warn(
"This method is deprecated and will be removed in a future release. Please use get_language()",
f"{DEPRECATION_WARNING} Please use get_language()",
DeprecationWarning,
stacklevel=2,
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyarr"
version = "5.1.1"
version = "5.1.2"
description = "Synchronous Sonarr, Radarr, Lidarr and Readarr API's for Python"
authors = ["Steven Marks <marksie1988@users.noreply.github.com>"]
license = "MIT"
Expand Down
75 changes: 58 additions & 17 deletions tests/test_lidarr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
from datetime import datetime
import random
import time

import pytest
import responses
Expand Down Expand Up @@ -163,23 +164,6 @@ def test_get_album(lidarr_client: LidarrAPI):
assert isinstance(data, list)


def test_post_command(lidarr_client: LidarrAPI):
data = lidarr_client.post_command(name="DownloadedAlbumsScan")
assert isinstance(data, dict)
data = lidarr_client.post_command(name="ArtistSearch")
assert isinstance(data, dict)
data = lidarr_client.post_command(name="RefreshArtist")
assert isinstance(data, dict)
data = lidarr_client.post_command(name="RefreshAlbum")
assert isinstance(data, dict)
data = lidarr_client.post_command(name="ApplicationUpdateCheck")
assert isinstance(data, dict)
data = lidarr_client.post_command(name="MissingAlbumSearch")
assert isinstance(data, dict)
data = lidarr_client.post_command(name="AlbumSearch")
assert isinstance(data, dict)


def test_get_wanted(lidarr_client: LidarrAPI):
data = lidarr_client.get_wanted()
assert isinstance(data, dict)
Expand Down Expand Up @@ -361,6 +345,63 @@ def test_get_language(lidarr_client: LidarrAPI):
assert isinstance(data, dict)


def test_post_command(lidarr_client: LidarrAPI):
data = lidarr_client.post_command(
name="DownloadedAlbumsScan", path=lidarr_client.get_root_folder()[0]["path"]
)
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"

data = lidarr_client.post_command(
name="ArtistSearch", artistId=lidarr_client.get_artist()[0]["id"]
)
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"

data = lidarr_client.post_command(name="RefreshArtist")
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"

data = lidarr_client.post_command(name="RefreshAlbum")
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"

data = lidarr_client.post_command(name="ApplicationUpdateCheck")
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "No update available"

data = lidarr_client.post_command(name="MissingAlbumSearch")
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"

data = lidarr_client.post_command(name="AlbumSearch")
assert isinstance(data, dict)

data = lidarr_client.post_command(name="RssSync")
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"

data = lidarr_client.post_command(name="Backup")
time.sleep(5)
result = lidarr_client.get_command(id_=data["id"])
assert isinstance(data, dict)
assert result["message"] == "Completed"


@pytest.mark.usefixtures
@responses.activate
def test_get_queue(lidarr_mock_client: LidarrAPI):
Expand Down
Loading

0 comments on commit 8f7b030

Please sign in to comment.