Skip to content

Commit

Permalink
Merge pull request #112 from totaldebug/110-assertion_error_with_del_…
Browse files Browse the repository at this point in the history
…series

fix: issue with assertion for sonarr deletes
  • Loading branch information
marksie1988 authored Jun 27, 2022
2 parents 731f37b + 70b0c95 commit 0cdece4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 29 deletions.
36 changes: 25 additions & 11 deletions pyarr/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Optional
from typing import Any, Optional, Union

from requests import Response

Expand Down Expand Up @@ -128,7 +128,9 @@ def get_root_folder(self) -> list[dict[str, Any]]:
# DELETE /rootfolder
def del_root_folder(
self, id_: int
) -> Response: # sourcery skip: class-extract-method
) -> Union[
Response, dict[str, Any], dict[Any, Any]
]: # sourcery skip: class-extract-method
"""Delete root folder with specified id
Args:
Expand Down Expand Up @@ -256,7 +258,9 @@ def get_blocklist(
return self.assert_return("blocklist", self.ver_uri, list, params)

# DELETE /blocklist
def del_blocklist(self, id_: int) -> Response:
def del_blocklist(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Removes a specific release (the id provided) from the blocklist
Args:
Expand All @@ -269,7 +273,9 @@ def del_blocklist(self, id_: int) -> Response:
return self._delete("blocklist", self.ver_uri, params=params)

# DELETE /blocklist/bulk
def del_blocklist_bulk(self, data: dict[str, Any]) -> Response:
def del_blocklist_bulk(
self, data: dict[str, Any]
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete blocked releases in bulk
Args:
Expand Down Expand Up @@ -312,7 +318,9 @@ def upd_quality_profile(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
return self._put(f"qualityprofile/{id_}", self.ver_uri, data=data)

# DELETE /qualityprofile
def del_quality_profile(self, id_: int) -> Response:
def del_quality_profile(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Removes a specific quality profile from the blocklist
Args:
Expand Down Expand Up @@ -385,7 +393,7 @@ def upd_indexer(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
return self._put(f"indexer/{id_}", self.ver_uri, data=data)

# DELETE /indexer
def del_indexer(self, id_: int) -> Response:
def del_indexer(self, id_: int) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Removes a specific indexer from the blocklist
Args:
Expand All @@ -402,7 +410,7 @@ def del_indexer(self, id_: int) -> Response:
# DELETE /queue/{id}
def del_queue(
self, id_: int, remove_from_client: bool = True, blacklist: bool = True
) -> Response:
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Remove an item from the queue and blacklist it
Args:
Expand Down Expand Up @@ -571,7 +579,9 @@ def upd_notification(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
return self._put(f"notification/{id_}", self.ver_uri, data=data)

# DELETE /notification/{id}
def del_notification(self, id_: int) -> Response:
def del_notification(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete a notification by its database id
Args:
Expand Down Expand Up @@ -641,7 +651,7 @@ def upd_tag(self, id_: int, label: str) -> dict[str, Any]:
return self._put(f"tag/{id_}", self.ver_uri, data=data)

# DELETE /tag/{id}
def del_tag(self, id_: int) -> Response:
def del_tag(self, id_: int) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete the tag with the given ID
Args:
Expand Down Expand Up @@ -718,7 +728,9 @@ def upd_download_client(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
return self._put(f"downloadclient/{id_}", self.ver_uri, data=data)

# DELETE /downloadclient/{id}
def del_download_client(self, id_: int) -> Response:
def del_download_client(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete a download client by database id
Args:
Expand Down Expand Up @@ -767,7 +779,9 @@ def upd_import_list(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
return self._put(f"importlist/{id_}", self.ver_uri, data=data)

# DELETE /importlist/{id}
def del_import_list(self, id_: int) -> Response:
def del_import_list(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete an import list
Args:
Expand Down
10 changes: 7 additions & 3 deletions pyarr/lidarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ def upd_artist(self, data: dict[str, Any]) -> dict[str, Any]:
"""
return self._put("artist", self.ver_uri, data=data)

def delete_artist(self, id_: int) -> Response:
def delete_artist(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete an artist with the provided ID
Args:
Expand Down Expand Up @@ -348,7 +350,7 @@ def upd_album(self, data: dict[str, Any]) -> dict[str, Any]:
"""
return self._put("album", self.ver_uri, data=data)

def delete_album(self, id_: int) -> Response:
def delete_album(self, id_: int) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete an album with the provided ID
Args:
Expand Down Expand Up @@ -526,7 +528,9 @@ def upd_track_file(self, data: dict[str, Any]) -> dict[str, Any]:
return self._put("trackfile", self.ver_uri, data=data)

# DEL /trackfile/{ids_}
def delete_track_file(self, ids_: Union[int, list[int]]) -> Response:
def delete_track_file(
self, ids_: Union[int, list[int]]
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete track files. Use integer for one file or list for mass deletion.
Args:
Expand Down
16 changes: 10 additions & 6 deletions pyarr/radarr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any, Optional, Union

from requests import Response

Expand Down Expand Up @@ -152,7 +152,7 @@ def get_movie_by_movie_id(self, id_: int) -> list[dict[str, Any]]:
# DELETE /movie/{id}
def del_movie(
self, id_: int, delete_files: bool = False, add_exclusion: bool = False
) -> Response:
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete a single movie by database id.
Args:
Expand Down Expand Up @@ -218,7 +218,9 @@ def upd_movies(self, data: dict[str, Any]) -> dict[str, Any]:
return self._put("movie/editor", self.ver_uri, data=data)

# DELETE /movie/editor
def del_movies(self, data: dict[str, Any]) -> Response:
def del_movies(
self, data: dict[str, Any]
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""The delete operation allows mass deletion of movies (and optionally files)
Args:
Expand Down Expand Up @@ -292,7 +294,9 @@ def get_movie_file(self, id_: int) -> list[dict[str, Any]]:
return self.assert_return(f"moviefile/{id_}", self.ver_uri, list)

# DELETE /moviefile/{id}
def del_movie_file(self, id_: int) -> Response:
def del_movie_file(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Allows for deletion of a moviefile by its database ID.
Args:
Expand Down Expand Up @@ -380,7 +384,7 @@ def del_queue_bulk(
data: dict[str, Any],
remove_from_client: bool = True,
blacklist: bool = True,
) -> Response:
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Remove multiple items from queue by their IDs
Args:
Expand Down Expand Up @@ -469,7 +473,7 @@ def upd_indexer(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
return self._put(f"indexer/{id_}", self.ver_uri, data=data)

# DELETE /indexer/{id}
def del_indexer(self, id_: int) -> Response:
def del_indexer(self, id_: int) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete indexer by database ID
Args:
Expand Down
4 changes: 2 additions & 2 deletions pyarr/readarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def upd_book(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
# DELETE /book/{id}
def del_book(
self, id_: int, delete_files: bool = False, import_list_exclusion: bool = True
) -> Response:
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete the book with the given ID
Args:
Expand Down Expand Up @@ -506,7 +506,7 @@ def upd_author(self, id_: int, data: dict[str, Any]) -> dict[str, Any]:
# DELETE /author/{id}
def del_author(
self, id_: int, delete_files: bool = False, import_list_exclusion: bool = True
) -> Response:
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete the author with the given ID
Args:
Expand Down
9 changes: 7 additions & 2 deletions pyarr/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _delete(
ver_uri: str = "",
params: Union[dict, None] = None,
data: Union[dict, None] = None,
) -> Response:
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Wrapper on any delete requests
Args:
Expand All @@ -186,7 +186,12 @@ def _delete(
raise PyarrConnectionError(
"Timeout occurred while connecting to API"
) from exception
return self._return(res, Response)
response = _process_response(res)
if isinstance(response, dict):
assert isinstance(response, dict)
else:
assert isinstance(response, Response)
return response

def _return(self, res: Response, arg1: type) -> Any:
"""Takes the response and asserts its type
Expand Down
12 changes: 8 additions & 4 deletions pyarr/sonarr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Optional
from typing import Any, Optional, Union
from warnings import warn

from requests import Response
Expand Down Expand Up @@ -214,7 +214,9 @@ def get_episode_file(self, id_: int) -> list[dict[str, Any]]:
return self.assert_return(f"episodefile/{id_}", self.ver_uri, list)

# DELETE /episodefile/{id}
def del_episode_file(self, id_: int) -> Response:
def del_episode_file(
self, id_: int
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Deletes the episode file with corresponding id
Args:
Expand Down Expand Up @@ -464,15 +466,17 @@ def upd_series(self, data: dict[str, Any]) -> dict[str, Any]:
return self._put("series", self.ver_uri, data=data)

# DELETE /series/{id}
def del_series(self, id_: int, delete_files: bool = False) -> Response:
def del_series(
self, id_: int, delete_files: bool = False
) -> Union[Response, dict[str, Any], dict[Any, Any]]:
"""Delete the series with the given ID
Args:
id_ (int): Database ID for series
delete_files (bool, optional): If true series folder and files will be deleted. Defaults to False.
Returns:
Response: HTTP Response
dict: Blank dictionary
"""
# File deletion does not work
params = {"deleteFiles": delete_files}
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 = "4.0.1"
version = "4.0.2"
description = "Synchronous Sonarr, Radarr, Lidarr and Readarr API's for Python"
authors = ["Steven Marks <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 0cdece4

Please sign in to comment.